View License

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video

Highlights from
Rotate Image

4.5 | 21 ratings Rate this file 22 Downloads (last 30 days) File Size: 3.67 KB File ID: #4071 Version: 1.0

Rotate Image


Ohad Gal (view profile)


21 Oct 2003 (Updated )

Rotate an image in X degrees.

| Watch this File

File Information

% rotate_image - rotates an image given inside a matrix by the amount of "degree" counter-clockwise
% using linear interpolation of the output grid points from the back-rotated input points
% in this way, the output image will never have a "blank" point
% Format: [out_image_m,out_ref_points_m] = rotate_image( degree, in_image_m, in_ref_points_m )
% Input: degree - rotation degree in dergees, counter-clockwise
% in_image_m - input image, given inside a matrix (gray level image only)
% in_ref_points_m - points on the image wich their output coordinates will be given
% after the rotation. given format of this matrix is:
% [ x1,x2,...,xn;y1,y2,...,yn]
% Output: out_image_m - the output image
% out_ref_points_m - the position of the input handle points after the rotation.
% this element is given in "in_ref_points_m" exists
% format of the matrix is the same as of "in_ref_points_m"
% NOTE: By definition of rotation, in order to perserve all the image inside the
% rotated image space, the output image will be a matrix with a bigger size.

Call the function with no parameters, to activate the demo


This file inspired Automatic Image Registration.

MATLAB release MATLAB 6.1 (R12.1)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (25)
08 Oct 2012 Maja

Maja (view profile)

Does this code still exist?
If yes, please send it to me.


Comment only
08 Jun 2011 Irma

Irma (view profile)

great! :)

Comment only
06 Jul 2010 Gregory Bohuslav

I think that this is probably a great function, but I keep getting the error:
[rotatedSlice(:,:,imageNumber),out_ref_points_m] = rotate_image( degree, in_image_m, in_ref_points_m )
??? Error using ==> times
Integers can only be combined with integers of the same class, or scalar doubles.

Error in ==> rotate_image at 112
out_image_m(out_points_span) = ...

15 Dec 2009 Kelly

Kelly (view profile)

this is great, thank you for sharing!

Comment only
04 Sep 2009 Pearl

Pearl (view profile)

14 Aug 2008 vaira prakash

10 Jul 2008 Amanda Lin

There is only 1 small suggestion. The images I have are in uint8. Your code at line 112 will give error message. So what I did was convert my image matrix to double and after rotation, convert the output matrix to uint8. So if you can check the input image's data first, do the conversion within your code when necessary, that'll be good.

01 Jul 2008 Steve Sharples

Excellent code, thank you for sharing.

15 May 2008 Simone Scolding


Comment only
15 May 2008 David Moyles

15 May 2008 Ben hardy

23 Apr 2008 Shamem Ahmed

Very interesting

05 Sep 2007 Simon Robinson

It's a bit of a strange feature that it gives an error for 90, 180, and 270 degree rotations if you don't specify a out_ref_points_m (if you aren't interested in this) but not for other angles, otherwise excellent.

08 Aug 2007 Sudhir Gupta

06 Jun 2007 aa jam

08 Mar 2007 Tim Peace

12 Dec 2006 sulakshana borsune

23 Nov 2006 Avinash .

Extremely useful and well documented code!!!

20 Nov 2006 Sachin Gupta

Excellent!! can u plz give the format of input test cases..

12 Jul 2006 PBO .

Very useful and well documented: thanks !

17 May 2006 Alice Huang


23 Dec 2005 Francisco Lopes

Perfect. Congratulations.

21 Dec 2005 K S

Very Nice!

11 Feb 2005 amit mishra

nice tool; the only problem is that the image expands after rotation, which shd not be the case;and the areas where there is no image in rest of the area; where as there shd be pixels all aroud using extrapolation!!

26 Dec 2004 Meenal Bagla

Could you possibly do this for a 3D matrix.

Contact us