0

I am trying to resize and rotate an image using octave. However when I try get the following error: Index exceeds matrix dimension... Anyone see what I am doing wrong?

I=imread('c:/cg/img/Lena.jpg'); % 128 x 128 uint
I2=rgb2gray(I);


alfa=.5;

for i=1:round(256*alfa)
  for j=1:round(256*alfa)

    is=round(i/alfa);
    js=round(j/alfa);

    if (is<1) is=1;  endif;    
    if (js<1) js=1;  endif;


 I3(i,j)=I2(is,js); 

   end
end

imwrite(I3,"c:/cg/lenax0.5.jpg","jpg");



for i=1:256
   for j=1:256
     I4(i,j)=I3(257-j,i);         %90
     I5(i,j)=I3(257-i,257-j);     %180
     I6(i,j)=I3(j,257-i);         %270
    end
end

I7=[I3 I4; I5 I6];
imshow(I7);
imwrite(I7,"c:/cg/lena_rotate_90_180_270.jpg","jpg");
4

2 回答 2

1

发现错误在这里我的尺寸错误。

for i=1:256
   for j=1:256
     I4(i,j)=I3(257-j,i);         %90
     I5(i,j)=I3(257-i,257-j);     %180
     I6(i,j)=I3(j,257-i);         %270
  end
end

我的尺寸错误需要

for I=1:128 ect... 
于 2013-11-04T20:59:09.453 回答
0

我无法理解您的代码,但是是的,您做错了什么。您没有使用image 包的功能来进行imrotateimresize。在调用这些函数之前不要忘记加载图像包pkg load image

于 2013-11-04T19:24:28.517 回答