This is a static copy of a profile reportHome
tformarray (1721 calls, 30.352 sec)
Generated 05-Nov-2014 07:53:14 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/tformarray.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
imrotate | function | 1721 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
225 | B = resample(A, M, tdims_A, td... | 1721 | 15.692 s | 51.7% |  |
218 | M = tforminv(G,T); | 1721 | 8.231 s | 27.1% |  |
212 | G = ConstructGrid(lo,hi); | 1721 | 2.333 s | 7.7% |  |
189 | CheckResampler( R, tdims_A ); | 1721 | 1.342 s | 4.4% |  |
182 | tsize_B = CheckDimsAndSizes( t... | 1721 | 1.252 s | 4.1% |  |
All other lines | | | 1.502 s | 4.9% |  |
Totals | | | 30.352 s | 100% | |
Children (called functions)
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 247 |
Non-code lines (comments, blank lines) | 204 |
Code lines (lines that can run) | 43 |
Code lines that did run | 22 |
Code lines that did not run | 21 |
Coverage (did run/can run) | 51.16 % |
Function listing
time calls line
1 function B = tformarray( A, T, R, tdims_A, tdims_B, tsize_B, tmap_B, F )
2 %TFORMARRAY Apply spatial transformation to N-D array.
3 % B = TFORMARRAY(A,T,R,TDIMS_A,TDIMS_B,TSIZE_B,TMAP_B,F) applies
4 % a geometric transformation to array A to produce array B.
5 %
6 % TFORMARRAY is like IMTRANSFORM, but is intended for problems
7 % involving higher-dimensioned arrays or mixed input/output
8 % dimensionality, or requiring greater user control or customization.
9 % (Anything -- and more -- that can be accomplished with IMTRANSFORM
10 % can be accomplished with a combination of MAKETFORM, MAKERESAMPLER,
11 % FINDBOUNDS, and TFORMARRAY, but for many tasks involving 2-D images,
12 % IMTRANSFORM is simpler.)
13 %
14 % Brief description of inputs
15 % ---------------------------
16 % A Input array or image
17 % T Geometric transformation, typically created with
18 % MAKETFORM
19 % R Resampler, typically created with MAKERESAMPLER
20 % TDIMS_A Row vector listing the input transform dimensions
21 % TDIMS_B Row vector listing the output transform dimensions
22 % TSIZE_B Output array size in the transform dimensions
23 % TMAP_B Array of point locations in output space; can be used as an
24 % alternative way to specify a geometric transformation
25 % F Array of fill values
26 %
27 % Detailed description of inputs
28 % ------------------------------
29 % A A can be any nonsparse numeric array, and can be real or
30 % complex. It can also be logical.
31 %
32 % T T is a structure that defines a particular geometric
33 % transformation. For each location in the output transform
34 % subscript space (as defined by TDIMS_B and TSIZE_B),
35 % TFORMARRAY uses T and the function TFORMINV to compute the
36 % corresponding location in the input transform subscript
37 % space (as defined by TDIMS_A and SIZE(A)).
38 %
39 % If T is empty, then TFORMARRAY operates as a direct resampling
40 % function, applying the resampler defined in R to compute
41 % values at each transform space location defined in TMAP_B
42 % (if TMAP_B is non-empty) or at each location in the output
43 % transform subscript grid.
44 %
45 % R R is a structure that defines how to interpolate values of
46 % the input array at specified locations. R is usually
47 % created with MAKERESAMPLER, which allows fine control
48 % over how to interpolate along each dimension, as well as
49 % what input array values to use when interpolating close the
50 % edge of the array.
51 %
52 % TDIMS_A TDIMS_A and TDIMS_B indicate which dimensions of the input
53 % TDIMS_B and output arrays are involved in the geometric
54 % transformation. Each element must be unique, and must be a
55 % positive integer. The entries need not be listed in
56 % increasing order, but the order matters. It specifies the
57 % precise correspondence between dimensions of arrays A and B
58 % and the input and output spaces of the transformer, T.
59 % LENGTH(TDIMS_A) must equal T.ndims_in, and LENGTH(TDIMS_B)
60 % must equal T.ndims_out.
61 %
62 % Suppose, for example, that T is a 2-D transformation,
63 % TDIMS_A = [2 1], and TDIMS_B = [1 2]. Then the column
64 % dimension and row dimension of A correspond to the first
65 % and second transformation input-space dimensions,
66 % respectively. The row and column dimensions of B
67 % correspond to the first and second output-space
68 % dimensions, respectively.
69 %
70 % TSIZE_B TSIZE_B specifies the size of the array B along the
71 % output-space transform dimensions. Note that the size of B
72 % along nontransform dimensions is taken directly from the
73 % size of A along those dimensions. If, for example, T is a
74 % 2-D transformation, size(A) = [480 640 3 10], TDIMS_B is
75 % [2 1], and TSIZE_B is [300 200], then size(B) is [200 300 3].
76 %
77 % TMAP_B TMAP_B is an optional array that provides an alternative
78 % way of specifying the correspondence between the position
79 % of elements of B and the location in output transform
80 % space. TMAP_B can be used, for example, to compute the
81 % result of an image warp at a set of arbitrary locations in
82 % output space. If TMAP_B is not empty, then the size of
83 % TMAP_B takes the form:
84 %
85 % [D1 D2 D3 ... DN L]
86 %
87 % where N equals length(TDIMS_B). The vector [D1 D2 ... DN]
88 % is used in place of TSIZE_B. If TMAP_B is not empty, then
89 % TSIZE_B should be [].
90 %
91 % The value of L depends on whether or not T is empty. If T
92 % is not empty, then L is T.ndims_out, and each L-dimension
93 % point in TMAP_B is transformed to an input-space location
94 % using T. If T is empty, then L is LENGTH(TDIMS_A), and
95 % each L-dimensional point in TMAP_B is used directly as a
96 % location in input space.
97 %
98 % F F is a double-precision array containing fill values.
99 % The fill values in F may be used in three situations:
100 %
101 % (1) When a separable resampler is created with MAKERESAMPLER
102 % and its PADMETHOD is set to either 'fill' or 'bound',
103 %
104 % (2) When a custom resampler is used that supports the 'fill'
105 % or 'bound' pad methods (with behavior that is specific
106 % to the customization), or
107 %
108 % (3) When the map from the transform dimensions of B
109 % to the transform dimensions of A is deliberately
110 % undefined for some points. Such points are encoded in
111 % the input transform space by NaNs in either TMAP_B or
112 % in the output of TFORMINV.
113 %
114 % In the first two cases, fill values are used to compute values
115 % for output locations that map outside or near edges of the input
116 % array. Fill values are copied into B when output locations map
117 % well outside the input array. Type 'help makeresampler' for
118 % further details on 'fill' and 'bound'.
119 %
120 % F can be a scalar (including NaN), in which case its value
121 % is replicated across all the nontransform dimensions. Or F
122 % can be a nonscalar whose size depends on size(A) in the
123 % nontransform dimensions. Specifically, if K is the J-th
124 % nontransform dimension of A, then SIZE(F,J) must be either
125 % SIZE(A,K) or 1. As a convenience to the user, TFORMARRAY
126 % replicates F across any dimensions with unit size such that
127 % after the replication SIZE(F,J) equals size(A,K).
128 %
129 % For example, suppose A represents 10 RGB images and has
130 % size 200-by-200-by-3-by-10, T is a 2-D transformation, and
131 % TDIMS_A and TDIMS_B are both [1 2]. In other words,
132 % TFORMARRAY will apply the same 2-D transform to each color
133 % plane of each of the 10 RGB images. In this situation you
134 % have several options for F:
135 %
136 % - F can be a scalar, in which case the same fill value
137 % is used for each color plane of all 10 images.
138 %
139 % - F can be a 3-by-1 vector, [R G B]'. Then R, G, and B
140 % will be used as the fill values for the corresponding
141 % color planes of each of the 10 images. This can be
142 % interpreted as specifying an RGB "fill color," with
143 % the same color used for all 10 images.
144 %
145 % - F can be a 1-by-10 vector. This can be interpreted as
146 % specifying a different fill value for each of 10
147 % images, with that fill value being used for all three
148 % color planes. (Each image gets a distinct grayscale
149 % fill-color.)
150 %
151 % - F can be a 3-by-10 matrix, which can be interpreted as
152 % supplying a different RGB fill-color for each of the
153 % 10 images.
154 %
155 % Example
156 % -------
157 % Create a 2-by-2 checkerboard image where each square is 20 pixels
158 % wide, then transform it with a projective transformation. Use a
159 % pad method of 'circular' when creating a resampler, so that the
160 % output appears to be a perspective view of an infinite checkerboard.
161 % Swap the output dimensions. Specify a 100-by-100 output image.
162 % Leave TMAP_B empty, since TSIZE_B is specified. Leave the fill
163 % value empty, since it won't be needed.
164 %
165 % I = checkerboard(20,1,1);
166 % figure, imshow(I)
167 % T = maketform('projective',[1 1; 41 1; 41 41; 1 41],...
168 % [5 5; 40 5; 35 30; -10 30]);
169 % R = makeresampler('cubic','circular');
170 % J = tformarray(I,T,R,[1 2],[2 1],[100 100],[],[]);
171 % figure, imshow(J)
172 %
173 % See also IMTRANSFORM, MAKERESAMPLER, MAKETFORM, FINDBOUNDS.
174
175 % Copyright 1993-2011 The MathWorks, Inc.
176 % $Revision: 1.9.4.11.2.1 $ $Date: 2011/07/18 00:35:08 $
177
178 % Start checking the inputs.
0.05 1721 179 error(nargchk(8,8,nargin, 'struct'));
180
181 % Construct a new tsize_B if tmap_B is non-empty.
1.25 1721 182 tsize_B = CheckDimsAndSizes( tdims_A, tdims_B, tsize_B, tmap_B, T );
183
184 % Get the 'full sizes' of A and B and their non-transform sizes (osize).
0.88 1721 185 [fsize_A, fsize_B, osize] = fullsizes(size(A), tsize_B, tdims_A, tdims_B);
186
187 % Finish checking the inputs.
0.08 1721 188 CheckInputArray( A );
1.34 1721 189 CheckResampler( R, tdims_A );
0.22 1721 190 F = CheckFillArray( F, osize );
191
192 % Determine blocking, if any.
0.02 1721 193 if ~isempty(tmap_B)
194 nBlocks = 1; % Must process in a single block if tmap_B is supplied.
1721 195 else
0.13 1721 196 blockingfactors = GetBlocking(tsize_B,max(length(tdims_A),length(tdims_B)));
1721 197 nBlocks = prod(blockingfactors);
1721 198 end
199
200 % If there is no tmap_B, process large arrays in multiple blocks to conserve
201 % the memory required by the output grid G and its mapping to the input
202 % space M. Otherwise, do the resampling in one large block.
0.01 1721 203 if nBlocks == 1
204 % If not already supplied in tmap_B, construct a grid G mapping B's
205 % transform subscripts to T's output space or (if T = []) directly to
206 % A's transform subscripts.
1721 207 if ~isempty(tmap_B)
208 G = tmap_B;
1721 209 else
1721 210 hi = tsize_B;
1721 211 lo = ones(1,length(hi));
2.33 1721 212 G = ConstructGrid(lo,hi);
0.01 1721 213 end
214
215 % If there is a tform, use it to extend the map in G to A's
216 % transform subscripts.
0.02 1721 217 if ~isempty(T)
8.23 1721 218 M = tforminv(G,T);
219 else
220 M = G;
221 end
0.04 1721 222 clear('G'); % Free memory used by G (which is no longer needed).
223
224 % Resample A using the map M and resampler R.
15.69 1721 225 B = resample(A, M, tdims_A, tdims_B, fsize_A, fsize_B, F, R);
226 else
227 % Pre-allocate B with size fsize_B and class(B) = class(A).
228 B(prod(fsize_B)) = A(1);
229 B = reshape(B,fsize_B);
230
231 % Loop over blocks in output transform space...
232 [lo, hi] = GetBlockLimits(tsize_B, blockingfactors);
233 for i = 1:nBlocks
234 % Construct the geometric map for the current block.
235 G = ConstructGrid(lo(i,:),hi(i,:));
236 if ~isempty(T)
237 M = tforminv(G,T);
238 else
239 M = G;
240 end
241 clear('G'); % Free memory used by G (which is no longer needed).
242
243 % Construct size and subscript arrays for the block, then resample.
244 [bsize_B, S] = ConstructSubscripts(fsize_B, tdims_B, lo(i,:), hi(i,:));
245 B(S{:}) = resample(A, M, tdims_A, tdims_B, fsize_A, bsize_B, F, R);
246 end
247 end
Other subfunctions in this file are not included in this listing.