rotating images matlab

rot90

Rotate matrix 90°

Syntax

    B = rot90(A)
    B = rot90(A,k)

Description :

B = rot90(A) rotates matrix A counterclockwise by 90 degrees.
B = rot90(A,k) rotates matrix A counterclockwise by k*90 degrees, where k is an integer.

Example

>> a = imread('DesertSmall.jpg'); % reading an rgb image
>> b = rgb2gray(a); % converting image to grayscale
>> c = rot90(b,1); % rotating image counterclockwise 90 deg. (1x90 = 90 deg).
>> d = rot90(b,3); % rotating image counterclockwise 270 deg.(3x90 = 270 deg).

>> subplot(2,2,1),imshow(a); title('Original Image');
>> subplot(2,2,2),imshow(b); title('Grayscale');
>> subplot(2,2,3),imshow(c); title('rotated 90');
>> subplot(2,2,4),imshow(d); title('rotated 270');

Output :