4.55

4.5 | 20 ratings Rate this file 436 downloads (last 30 days) File Size: 3.67 KB File ID: #4071

Rotate Image

by Ohad Gal

 

21 Oct 2003 (Updated 22 Oct 2003)

Code covered by BSD License  

Rotate an image in X degrees.

Download Now | 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 (21)
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  
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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com