Find output bounds for spatial transformation
outbounds = findbounds(TFORM,inbounds)
outbounds = findbounds(TFORM,inbounds) estimates the output bounds corresponding to a given spatial transformation and a set of input bounds. TFORM, as returned by maketform, is a spatial transformation structure. inbounds is a 2-by-num_dims matrix. The first row of inbounds specifies the lower bounds for each dimension, and the second row specifies the upper bounds. num_dims has to be consistent with the ndims_in field of TFORM.
outbounds has the same form as inbounds. It is an estimate of the smallest rectangular region completely containing the transformed rectangle represented by the input bounds. Since outbounds is only an estimate, it might not completely contain the transformed input rectangle.
findbounds gets called by imtransform if 'XData' and 'YData', the parameters that control the output-space bounding box in imtransform, are not specified. findbounds computes the output-space bounding box.
findbounds first creates a grid of input-space points. These points are located at the center, corners, and middle of each edge in the image.
I = imread('rice.png'); h = imshow(I); set(h,'AlphaData',0.3); axis on, grid on in_points = [ ... 0.5000 0.5000 0.5000 256.5000 256.5000 0.5000 256.5000 256.5000 0.5000 128.5000 128.5000 0.5000 128.5000 128.5000 128.5000 256.5000 256.5000 128.5000]; hold on plot(in_points(:,1),in_points(:,2),'.','MarkerSize',18) hold off
Grid of Input-Space Points
Next, findbounds transforms the grid of input-space points to output space. If tform contains a forward transformation (a nonempty forward_fcn field), then findbounds transforms the input-space points using tformfwd. For example:
tform = maketform('affine', ... [1.1067 -0.2341 0; 0.5872 1.1769 0; 1000 -300 1]); out_points = tformfwd(tform, in_points)
The output appears below:
out_points = 1.0e+003 * 1.0008 -0.2995 1.1512 0.0018 1.2842 -0.3595 1.4345 -0.0582 1.0760 -0.1489 1.1425 -0.3295 1.2177 -0.1789 1.2928 -0.0282 1.3593 -0.2088
If TFORM does not contain a forward transformation, then findbounds estimates the output bounds using the Nelder-Mead optimization function fminsearch.
Finally, findbounds computes the bounding box of the transformed grid of points.
cp2tform, imtransform, maketform, tformarray, tformfwd, tforminv
© 1984-2010 The MathWorks, Inc. Terms of Use Patents Trademarks Acknowledgments