rotate image in matlab

To rotate an image in Matlab, you can use the imrotate function to rotate an image by a specified angle. The syntax of the function is:

main.m
B = imrotate(A, angle)
23 chars
2 lines

Where A is the input image and angle is the angle of rotation in degrees.

For example, let us rotate the following image lena.png by 45 degrees:

main.m
% Read the input image
I = imread('lena.png');

% Rotate the image by 45 degrees
J = imrotate(I, 45);

% Display the original and rotated image side by side
figure;
subplot(1, 2, 1); imshow(I); title('Original Image');
subplot(1, 2, 2); imshow(J); title('Rotated Image');
272 chars
11 lines

This will produce an output image that is 45 degrees rotated clockwise:

Rotated Image

Note that you can also specify other options, such as the interpolation method used to resample the image or the output size of the rotated image, using additional input arguments to the imrotate function.

gistlibby LogSnag