findbounds
Find output bounds for spatial transformation
Description
estimates
the output bounds corresponding to a given spatial transformation
and a set of input bounds. outbounds
= findbounds(tform
,inbounds
)tform
is a spatial transformation
structure. inbounds
is a 2-by-num_dims
matrix
that specifies the lower and upper bounds of the output image. outbounds
is
an estimate of the smallest rectangular region completely containing
the transformed rectangle represented by the input bounds, and has
the same form as inbounds
. Since outbounds
is
only an estimate, it might not completely contain the transformed
input rectangle.
Examples
Input Arguments
Output Arguments
Algorithms
findbounds
first creates a grid of input-space points. These points are 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. Iftform
contains a forward transformation (a nonemptyforward_fcn
field), thenfindbounds
transforms the input-space points usingtformfwd
. For example:tform = maketform('affine', ... [1.1067 -0.2341 0; 0.5872 1.1769 0; 1000 -300 1]); out_points = tformfwd(tform, in_points)
out_points = 1.0e+03 * 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
If
tform
does not contain a forward transformation, thenfindbounds
estimates the output bounds using the Nelder-Mead optimization functionfminsearch
.Finally,
findbounds
computes the bounding box of the transformed grid of points.