This is a static copy of a profile reportHome
imresize (82820 calls, 204.763 sec)
Generated 05-Nov-2014 07:53:39 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/imresize.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
141 | params = parseInputs(varargin{... | 82820 | 99.538 s | 48.6% |  |
154 | [weights{k}, indices{k}] = con... | 165640 | 48.177 s | 23.5% |  |
169 | B = resizeAlongDim(B, dim, wei... | 165640 | 22.331 s | 10.9% |  |
173 | [B, map] = postprocessImage(B,... | 82820 | 7.340 s | 3.6% |  |
159 | if isPureNearestNeighborComput... | 82820 | 6.389 s | 3.1% |  |
All other lines | | | 20.989 s | 10.3% |  |
Totals | | | 204.763 s | 100% | |
Children (called functions)
Code Analyzer results
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 173 |
Non-code lines (comments, blank lines) | 154 |
Code lines (lines that can run) | 19 |
Code lines that did run | 18 |
Code lines that did not run | 1 |
Coverage (did run/can run) | 94.74 % |
Function listing
time calls line
1 function [B,map] = imresize(varargin)
2 %IMRESIZE Resize image.
3 % B = IMRESIZE(A, SCALE) returns an image that is SCALE times the
4 % size of A, which is a grayscale, RGB, or binary image.
5 %
6 % B = IMRESIZE(A, [NUMROWS NUMCOLS]) resizes the image so that it has
7 % the specified number of rows and columns. Either NUMROWS or NUMCOLS
8 % may be NaN, in which case IMRESIZE computes the number of rows or
9 % columns automatically in order to preserve the image aspect ratio.
10 %
11 % [Y, NEWMAP] = IMRESIZE(X, MAP, SCALE) resizes an indexed image.
12 %
13 % [Y, NEWMAP] = IMRESIZE(X, MAP, [NUMROWS NUMCOLS]) resizes an indexed
14 % image.
15 %
16 % To control the interpolation method used by IMRESIZE, add a METHOD
17 % argument to any of the syntaxes above, like this:
18 %
19 % IMRESIZE(A, SCALE, METHOD)
20 % IMRESIZE(A, [NUMROWS NUMCOLS], METHOD),
21 % IMRESIZE(X, MAP, M, METHOD)
22 % IMRESIZE(X, MAP, [NUMROWS NUMCOLS], METHOD)
23 %
24 % METHOD can be a string naming a general interpolation method:
25 %
26 % 'nearest' - nearest-neighbor interpolation
27 %
28 % 'bilinear' - bilinear interpolation
29 %
30 % 'bicubic' - cubic interpolation; the default method
31 %
32 % METHOD can also be a string naming an interpolation kernel:
33 %
34 % 'box' - interpolation with a box-shaped kernel
35 %
36 % 'triangle' - interpolation with a triangular kernel
37 % (equivalent to 'bilinear')
38 %
39 % 'cubic' - interpolation with a cubic kernel
40 % (equivalent to 'bicubic')
41 %
42 % 'lanczos2' - interpolation with a Lanczos-2 kernel
43 %
44 % 'lanczos3' - interpolation with a Lanczos-3 kernel
45 %
46 % Finally, METHOD can be a two-element cell array of the form {f,w},
47 % where f is the function handle for a custom interpolation kernel, and
48 % w is the custom kernel's width. f(x) must be zero outside the
49 % interval -w/2 <= x < w/2. Your function handle f may be called with a
50 % scalar or a vector input.
51 %
52 % You can achieve additional control over IMRESIZE by using
53 % parameter/value pairs following any of the syntaxes above. For
54 % example:
55 %
56 % B = IMRESIZE(A, SCALE, PARAM1, VALUE1, PARAM2, VALUE2, ...)
57 %
58 % Parameters include:
59 %
60 % 'Antialiasing' - true or false; specifies whether to perform
61 % antialiasing when shrinking an image. The
62 % default value depends on the interpolation
63 % method you choose. For the 'nearest' method,
64 % the default is false; for all other methods,
65 % the default is true.
66 %
67 % 'Colormap' - (only relevant for indexed images) 'original'
68 % or 'optimized'; if 'original', then the
69 % output newmap is the same as the input map.
70 % If it is 'optimized', then a new optimized
71 % colormap is created. The default value is
72 % 'optimized'.
73 %
74 % 'Dither' - (only for indexed images) true or false;
75 % specifies whether to perform color
76 % dithering. The default value is true.
77 %
78 % 'Method' - As described above
79 %
80 % 'OutputSize' - A two-element vector, [MROWS NCOLS],
81 % specifying the output size. One element may
82 % be NaN, in which case the other value is
83 % computed automatically to preserve the aspect
84 % ratio of the image.
85 %
86 % 'Scale' - A scalar or two-element vector specifying the
87 % resize scale factors. If it is a scalar, the
88 % same scale factor is applied to each
89 % dimension. If it is a vector, it contains
90 % the scale factors for the row and column
91 % dimensions, respectively.
92 %
93 % Examples
94 % --------
95 % Shrink by factor of two using the defaults of bicubic interpolation
96 % and antialiasing.
97 %
98 % I = imread('rice.png');
99 % J = imresize(I, 0.5);
100 % figure, imshow(I), figure, imshow(J)
101 %
102 % Shrink by factor of two using nearest-neighbor interpolation.
103 % (This is the fastest method, but it has the lowest quality.)
104 %
105 % J2 = imresize(I, 0.5, 'nearest');
106 %
107 % Resize an indexed image.
108 %
109 % [X, map] = imread('trees.tif');
110 % [Y, newmap] = imresize(X, map, 0.5);
111 % imshow(Y, newmap)
112 %
113 % Resize an RGB image to have 64 rows. The number of columns is
114 % computed automatically.
115 %
116 % RGB = imread('peppers.png');
117 % RGB2 = imresize(RGB, [64 NaN]);
118 %
119 % Note
120 % ----
121 % The function IMRESIZE changed in version 5.4 (R2007a). Previous
122 % versions of the Image Processing Toolbox used a somewhat
123 % different algorithm by default. If you need the same results
124 % produced by the previous implementation, use the function
125 % IMRESIZE_OLD.
126 %
127 % For bicubic interpolation, the output image may have some values
128 % slightly outside the range of pixel values in the input image. This
129 % may also occur for user-specified interpolation kernels.
130 %
131 % Class Support
132 % -------------
133 % The input image A can be numeric or logical and it must be nonsparse.
134 % The output image is of the same class as the input image. The input
135 % indexed image X can be uint8, uint16, or double.
136 %
137 % See also IMRESIZE_OLD, IMROTATE, IMTRANSFORM, TFORMARRAY.
138
139 % Copyright 1992-2009 The MathWorks, Inc.
140
99.54 82820 141 params = parseInputs(varargin{:});
142
4.46 82820 143 checkForMissingOutputArgument(params, nargout);
144
5.84 82820 145 A = preprocessImage(params);
146
147 % Determine which dimension to resize first.
3.03 82820 148 order = dimensionOrder(params.scale);
149
150 % Calculate interpolation weights and indices for each dimension.
0.72 82820 151 weights = cell(1,2);
0.40 82820 152 indices = cell(1,2);
0.88 82820 153 for k = 1:2
48.18 165640 154 [weights{k}, indices{k}] = contributions(size(A, k), ...
155 params.output_size(k), params.scale(k), params.kernel, ...
156 params.kernel_width, params.antialiasing);
0.76 165640 157 end
158
6.39 82820 159 if isPureNearestNeighborComputation(weights{1}) && ...
160 isPureNearestNeighborComputation(weights{2})
161
162 B = resizeTwoDimUsingNearestNeighbor(A, indices);
163
0.24 82820 164 else
0.47 82820 165 B = A;
1.29 82820 166 for k = 1:numel(order)
0.61 165640 167 dim = order(k);
168
22.33 165640 169 B = resizeAlongDim(B, dim, weights{dim}, indices{dim});
0.67 165640 170 end
0.30 82820 171 end
172
7.34 82820 173 [B, map] = postprocessImage(B, params);
Other subfunctions in this file are not included in this listing.