matlab 索引超出数组范围(不能超过 512)。
functionpic=FT(a)fprintf('平移变换:')mx=input('请输入水平位移:');my=input('请输入竖直位移:');fprintf('缩...
function pic=FT(a)
fprintf('平移变换:')
mx=input('请输入水平位移:');
my=input('请输入竖直位移:');
fprintf('缩放:')
k=input('请输入倍数:');
fprintf('镜像:')
g1=input('是否水平镜像(需要输入1否则0):');
g2=input('是否垂直镜像(需要输入1否则0):');
fprintf('旋转:')
ang=input('输入旋转角度');
[A1,B1] = size (a);
b1=zeros (A1,B1);
for r=1:A1
for c=1:B1
rp=r+my;
cp=c+mx;
if rp>=1&rp<=A1&cp>=1&cp<=B1
b1(rp,cp)=a(r,c);
end
end
end
logical(g1);
logical(g2);
b2=imresize(b1,k);
[A3,B3] = size (b2);
b3=zeros (A3,B3);
if g1==1
for r=1:A3
for c=1:B3
rp=r;
cp=B3-c+1;
if rp>=1&rp<=A3&cp>=1&cp<=B3
b3(rp,cp)=b2(r,c);
end
end
end
else
for r=1:A3
for c=1:B3
rp=r;
cp=c;
if rp>=1&rp<=A3&cp>=1&cp<=B3
b3(rp,cp)=b2(r,c);
end
end
end
end
[A4,B4] = size (b3);
b4=zeros(A4,B4);
if g2==1
for r=1:A4
for c=1:B4
rp=A4-r+1;
cp=c;
if rp>=1&rp<=A4&cp>=1&cp<=B4
b4(rp,cp)=b3(r,c);
end
end
end
else
for r=1:A4
for c=1:B4
rp=r;
cp=c;
if rp>=1&rp<=A4&cp>=1&cp<=B4
b4(rp,cp)=b3(r,c);
end
end
end
end
[A5,B5]=size(b4);
b5=zeros(A5,B5);
radian=ang/180*pi;
cos_val=cos(radian);
sin_val=sin(radian);
w2=round(abs(cos_val)*B5+A5*abs(sin_val));
h2=round(abs(cos_val)*A5+B5*abs(sin_val));
for r=1:w2
for c=1:h2
rp=r*cos_val+c*sin_val-0.5*w2*cos_val-0.5*h2*sin_val+0.5*B5;
cp=c*cos_val-r*sin_val+0.5*w2*sin_val-0.5*h2*cos_val+0.5*A5;
rp=round(rp);
cp=round(cp);
if rp>=1&cp>=1&B5>=rp&A5>=cp
b5(rp,cp) = b4(r,c);
end
end
end
pic=uint8(b5);
imshow(pic);
位置 1 的索引无效。数组索引必须为正整数或逻辑值。
出错 FT (line 83)
b5(rp,cp) = b4(r,c); 展开
fprintf('平移变换:')
mx=input('请输入水平位移:');
my=input('请输入竖直位移:');
fprintf('缩放:')
k=input('请输入倍数:');
fprintf('镜像:')
g1=input('是否水平镜像(需要输入1否则0):');
g2=input('是否垂直镜像(需要输入1否则0):');
fprintf('旋转:')
ang=input('输入旋转角度');
[A1,B1] = size (a);
b1=zeros (A1,B1);
for r=1:A1
for c=1:B1
rp=r+my;
cp=c+mx;
if rp>=1&rp<=A1&cp>=1&cp<=B1
b1(rp,cp)=a(r,c);
end
end
end
logical(g1);
logical(g2);
b2=imresize(b1,k);
[A3,B3] = size (b2);
b3=zeros (A3,B3);
if g1==1
for r=1:A3
for c=1:B3
rp=r;
cp=B3-c+1;
if rp>=1&rp<=A3&cp>=1&cp<=B3
b3(rp,cp)=b2(r,c);
end
end
end
else
for r=1:A3
for c=1:B3
rp=r;
cp=c;
if rp>=1&rp<=A3&cp>=1&cp<=B3
b3(rp,cp)=b2(r,c);
end
end
end
end
[A4,B4] = size (b3);
b4=zeros(A4,B4);
if g2==1
for r=1:A4
for c=1:B4
rp=A4-r+1;
cp=c;
if rp>=1&rp<=A4&cp>=1&cp<=B4
b4(rp,cp)=b3(r,c);
end
end
end
else
for r=1:A4
for c=1:B4
rp=r;
cp=c;
if rp>=1&rp<=A4&cp>=1&cp<=B4
b4(rp,cp)=b3(r,c);
end
end
end
end
[A5,B5]=size(b4);
b5=zeros(A5,B5);
radian=ang/180*pi;
cos_val=cos(radian);
sin_val=sin(radian);
w2=round(abs(cos_val)*B5+A5*abs(sin_val));
h2=round(abs(cos_val)*A5+B5*abs(sin_val));
for r=1:w2
for c=1:h2
rp=r*cos_val+c*sin_val-0.5*w2*cos_val-0.5*h2*sin_val+0.5*B5;
cp=c*cos_val-r*sin_val+0.5*w2*sin_val-0.5*h2*cos_val+0.5*A5;
rp=round(rp);
cp=round(cp);
if rp>=1&cp>=1&B5>=rp&A5>=cp
b5(rp,cp) = b4(r,c);
end
end
end
pic=uint8(b5);
imshow(pic);
位置 1 的索引无效。数组索引必须为正整数或逻辑值。
出错 FT (line 83)
b5(rp,cp) = b4(r,c); 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询