Reputation: 189
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");
Upvotes: 0
Views: 347
Reputation: 189
Figured it out error was here I had the size wrong.
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
I had the size wrong needed to be
for I=1:128 ect...
Upvotes: 1
Reputation: 13081
I can't make much sense of your code but yes, you're doing something wrong. You're not using the functions of the image package to imrotate and imresize. Don't forget to load the image package before calling those functions pkg load image
.
Upvotes: 0