This is a static copy of a profile reportHome
imrotate (1721 calls, 44.942 sec)
Generated 05-Nov-2014 07:52:59 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/imrotate.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
ml_rotate | function | 1721 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
155 | B = tformarray(A, T, R, [1 2],... | 1721 | 30.372 s | 67.6% |  |
145 | T = maketform('composite',[fli... | 1721 | 3.154 s | 7.0% |  |
150 | R = makeresampler('linear','fi... | 1721 | 2.874 s | 6.4% |  |
129 | rotate = maketform('affine',[ ... | 1721 | 1.662 s | 3.7% |  |
144 | boxB = maketform('box',outputS... | 1721 | 1.572 s | 3.5% |  |
All other lines | | | 5.307 s | 11.8% |  |
Totals | | | 44.942 s | 100% | |
Children (called functions)
Code Analyzer results
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 172 |
Non-code lines (comments, blank lines) | 105 |
Code lines (lines that can run) | 67 |
Code lines that did run | 23 |
Code lines that did not run | 44 |
Coverage (did run/can run) | 34.33 % |
Function listing
time calls line
1 function varargout = imrotate(varargin)
2 %IMROTATE Rotate image.
3 % B = IMROTATE(A,ANGLE) rotates image A by ANGLE degrees in a
4 % counterclockwise direction around its center point. To rotate the image
5 % clockwise, specify a negative value for ANGLE. IMROTATE makes the output
6 % image B large enough to contain the entire rotated image. IMROTATE uses
7 % nearest neighbor interpolation, setting the values of pixels in B that
8 % are outside the rotated image to 0 (zero).
9 %
10 % B = IMROTATE(A,ANGLE,METHOD) rotates image A, using the interpolation
11 % method specified by METHOD. METHOD is a string that can have one of the
12 % following values. The default value is enclosed in braces ({}).
13 %
14 % {'nearest'} Nearest neighbor interpolation
15 %
16 % 'bilinear' Bilinear interpolation
17 %
18 % 'bicubic' Bicubic interpolation. Note: This interpolation
19 % method can produce pixel values outside the original
20 % range.
21 %
22 % B = IMROTATE(A,ANGLE,METHOD,BBOX) rotates image A, where BBOX specifies
23 % the size of the output image B. BBOX is a text string that can have
24 % either of the following values. The default value is enclosed in braces
25 % ({}).
26 %
27 % {'loose'} Make output image B large enough to contain the
28 % entire rotated image. B is generally larger than A.
29 %
30 % 'crop' Make output image B the same size as the input image
31 % A, cropping the rotated image to fit.
32 %
33 % Class Support
34 % -------------
35 % The input image can be numeric or logical. The output image is of the
36 % same class as the input image.
37 %
38 % Performance Note
39 % ----------------
40 % This function may take advantage of hardware optimization for datatypes
41 % uint8, uint16, and single to run faster.
42 %
43 % Example
44 % -------
45 % % This example brings image I into horizontal alignment by
46 % % rotating the image by -1 degree.
47 %
48 % I = fitsread('solarspectra.fts');
49 % I = mat2gray(I);
50 % J = imrotate(I,-1,'bilinear','crop');
51 % figure, imshow(I), figure, imshow(J)
52 %
53 % See also IMCROP, IMRESIZE, IMTRANSFORM, TFORMARRAY.
54
55 % Copyright 1992-2011 The MathWorks, Inc.
56 % $Revision: 5.25.4.13.2.1 $ $Date: 2011/07/18 00:34:23 $
57
58 % Grandfathered:
59 % Without output arguments, IMROTATE(...) displays the rotated
60 % image in the current axis.
61
1.37 1721 62 [A,ang,method,bbox] = parse_inputs(varargin{:});
63
1721 64 so = size(A);
0.01 1721 65 twod_size = so(1:2);
66
0.03 1721 67 if rem(ang,90) == 0
68 % Catch and speed up 90 degree rotations
69
70 % determine if angle is +- 90 degrees or 0,180 degrees.
71 multiple_of_ninety = mod(floor(ang/90), 4);
72
73 % initialize array of subscripts
74 v = repmat({':'},[1 ndims(A)]);
75
76 switch multiple_of_ninety
77
78 case 0
79 % 0 rotation;
80 B = A;
81
82 case {1,3}
83 % +- 90 deg rotation
84
85 thirdD = prod(so(3:end));
86 A = reshape(A,[twod_size thirdD]);
87
88 not_square = twod_size(1) ~= twod_size(2);
89 if strcmpi(bbox, 'crop') && not_square
90 % center rotated image and preserve size
91
92 imbegin = (max(twod_size) == so)*abs(diff(floor(twod_size/2)));
93 vec = 1:min(twod_size);
94 v(1) = {imbegin(1)+vec};
95 v(2) = {imbegin(2)+vec};
96
97 new_size = [twod_size thirdD];
98
99 else
100 % don't preserve original size
101 new_size = [fliplr(twod_size) thirdD];
102 end
103
104 % pre-allocate array
105 if islogical(A)
106 B = false(new_size);
107 else
108 B = zeros(new_size,class(A));
109 end
110
111 for k = 1:thirdD
112 B(v{1},v{2},k) = rot90(A(v{1},v{2},k),multiple_of_ninety);
113 end
114
115 B = reshape(B,[new_size(1) new_size(2) so(3:end)]);
116
117 case 2
118 % 180 rotation
119
120 v(1) = {twod_size(1):-1:1};
121 v(2) = {twod_size(2):-1:1};
122 B = A(v{:});
123 end
124
0.01 1721 125 else % Perform general rotation
126
1721 127 phi = ang*pi/180; % Convert to radians
128
1.66 1721 129 rotate = maketform('affine',[ cos(phi) sin(phi) 0; ...
130 -sin(phi) cos(phi) 0; ...
131 0 0 1 ]);
132
1.29 1721 133 [loA,hiA,loB,hiB,outputSize] = getOutputBound(rotate,twod_size,bbox);
134
0.81 1721 135 if useIPP(A,method)
136 % The Intel routines have different edge behavior than our code.
137 % This difference can be worked around with zero padding.
138 A = padarray(A,[2 2],0,'both');
139 B = imrotatemex(A,ang,outputSize,method);
140
0.01 1721 141 else % rotate using tformarray
142
1.57 1721 143 boxA = maketform('box',twod_size,loA,hiA);
1.57 1721 144 boxB = maketform('box',outputSize,loB,hiB);
3.15 1721 145 T = maketform('composite',[fliptform(boxB),rotate,boxA]);
146
0.03 1721 147 if strcmp(method,'bicubic')
148 R = makeresampler('cubic','fill');
0.03 1721 149 elseif strcmp(method,'bilinear')
2.87 1721 150 R = makeresampler('linear','fill');
151 else
152 R = makeresampler('nearest','fill');
153 end
154
30.37 1721 155 B = tformarray(A, T, R, [1 2], [1 2], outputSize, [], 0);
156
1721 157 end
1721 158 end
159
160
161 % Output
0.01 1721 162 switch nargout,
0.01 1721 163 case 0,
164 % Need to set varargout{1} so ans gets populated even if user doesn't ask for output
165 varargout{1} = B;
0.02 1721 166 case 1,
0.04 1721 167 varargout{1} = B;
168 case 3,
169 error(message('images:removed:syntax','[R,G,B] = IMROTATE(RGB)','RGB2 = IMROTATE(RGB1)'))
170 otherwise,
171 error(message('images:imrotate:tooManyOutputs'))
172 end
Other subfunctions in this file are not included in this listing.