Reputation: 65
I want to :
my problem is when i apply rotation with 45 degrees and -45 degrees, the size of the image changes and i want it to be the same.
Upvotes: 3
Views: 1414
Reputation: 684
The usual procedure to rotate images is to scale the image up, rotate the image and scale it down. This way, you can avoid the dark margins that will appear when you rotate.
Matlab does this process automatically. So if you want a particular dimension for the image, you have to choose the appropriate region of the image after you have rotated it.
Suppose we wanted to rotate the image and want to retain the same dimensions as the original image, we can do this:
img = imread('image.png');
r = numel(img(:,1));
c = numel(img(:,2));
nimg = imrotate(img, 45);
nimg = imrotate(nimg, 45);
n_R = numel(nimg(:,1));
n_C = numel(nimg(:,2));
n_R = n_R+mod(n_R, 2); %to avoid dimensions being in double datatype
n_C = n_C+mod(n_C, 2);
oimg = nimg(((n_R/2)-(r/2)):((n_R/2)+(r/2)), ((n_C/2)-(c/2)):((n_C/2)+(c/2)),:);
imwrite(oimg, 'rot_image.png');
Upvotes: 2
Reputation: 13091
You can't do it. It doesn't make sense. Simple experiment:
Upvotes: 1