Rotating an Image in MATLAB
Method
imrotate(I,angle,method,bbox)
I
: Image to be rotated.angle
: The angle of rotation in degrees.method
: The interpolation method. Options are ’nearest’, ‘bilinear’, ‘bicubic’. If nothing is specified, ’nearet’ is applied.
X = phantom('Modified Shepp-Logan',64);
figure()
imagesc(X)
title('X')
Y1=imrotate(X,30,'nearest','crop');
Y2=imrotate(X,30,'bilinear','crop');
Y3=imrotate(X,30,'bicubic','crop');
figure()
subplot(1,3,1)
imagesc(Y1)
title('Y1 - nearest')
subplot(1,3,2)
imagesc(Y2)
title('Y2 - bilinear')
subplot(1,3,3)
imagesc(Y3)
title('Y3 - bicubic')
bbox
: Specifies the size of the output image. ’loose’ enlarges the size of the output image to include parts that exceed the original size due to rotation. ‘crop’ cuts the rotated image to fit the size of the original image. If nothing is specified, ’loose’ is applied.
X = phantom('Modified Shepp-Logan',64);
figure()
imagesc(X)
title('X - 64*64')
Y1=imrotate(X,30,'nearest','loose');
Y2=imrotate(X,30,'nearest','crop');
figure()
subplot(1,2,1)
imagesc(Y1)
title('Y1 - loose 88*88')
subplot(1,2,2)
imagesc(Y2)
title('Y2 - crop 64*64')