Code covered by the BSD License  

Highlights from
Rotate Image

4.52381

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

Rotate Image

by Ohad Gal

 

21 Oct 2003 (Updated 22 Oct 2003)

Rotate an image in X degrees.

| Watch this File

File Information
Description

% 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

Acknowledgements
This submission has inspired the following:
Automatic Image Registration
MATLAB release MATLAB 6.1 (R12.1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (24)
26 Dec 2004 Meenal Bagla

Could you possibly do this for a 3D matrix.

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!!

21 Dec 2005 K S

Very Nice!

23 Dec 2005 Francisco Lopes

Perfect. Congratulations.

17 May 2006 Alice Huang

good

12 Jul 2006 PBO .

Very useful and well documented: thanks !

20 Nov 2006 Sachin Gupta

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

23 Nov 2006 Avinash .

Extremely useful and well documented code!!!

12 Dec 2006 sulakshana borsune  
08 Mar 2007 Tim Peace  
06 Jun 2007 aa jam  
08 Aug 2007 Sudhir Gupta  
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.

23 Apr 2008 Shamem Ahmed

Very interesting

15 May 2008 Ben hardy  
15 May 2008 David Moyles  
15 May 2008 Simone Scolding

clever

01 Jul 2008 Steve Sharples

Excellent code, thank you for sharing.

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.

14 Aug 2008 vaira prakash  
04 Sep 2009 Pearl  
15 Dec 2009 Kelly

this is great, thank you for sharing!

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) = ...

08 Jun 2011 Irma

great! :)

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
geometric transformation Ohad Gal 22 Oct 2008 07:08:54
image registration Ohad Gal 22 Oct 2008 07:08:54
rotate spin revolve Ohad Gal 22 Oct 2008 07:08:54
image registration Tonyc Cao 09 Jun 2009 05:06:47
image registration Keith 12 Oct 2010 12:47:33

Contact us at files@mathworks.com