geomap(input,
ref,
bbox=None,
fit_geometry='general',
function='polynomial',
xxorder=2,
xyorder=2,
yxorder=2,
yyorder=2,
xxterms='half',
yxterms='half',
maxiter=0,
reject=0.0)
| source code
|
`geomap` computes the transformation required to map the reference
coordinate system to the input coordinate system.
The coordinates of points in common to the two systems are listed
in the same location in the *input* and *ref* arrays.
The computed transformation has the form shown below::
xin = f (xref, yref)
yin = g (xref, yref)
If, on the other hand, the user wishes to transform coordinates
from the input image coordinate system to the reference coordinate
system then he or she must reverse the roles of the reference and
input coordinates as defined above, and compute the inverse
transformation.
The functions *f* and *g* are either a power series polynomial or
a Legendre or Chebyshev polynomial surface of order *xxorder* and
*xyorder* in *x* and *yxorder* and *yyorder* in *y*.
Several polynomial cross terms options are available. Options
"none", "half", and "full" are illustrated below for a quadratic
polynomial in *x* and *y*::
xxterms = "none", xyterms = "none"
xxorder = 3, xyorder = 3, yxorder = 3, yyorder = 3
xin = a11 + a21 * xref + a12 * yref +
a31 * xref ** 2 + a13 * yref ** 2
yin = a11' + a21' * xref + a12' * yref +
a31' * xref ** 2 + a13' * yref ** 2
xxterms = "half", xyterms = "half"
xxorder = 3, xyorder = 3, yxorder = 3, yyorder = 3
xin = a11 + a21 * xref + a12 * yref +
a31 * xref ** 2 + a22 * xref * yref + a13 * yref ** 2
yin = a11' + a21' * xref + a12' * yref +
a31' * xref ** 2 + a22' * xref * yref + a13' * yref ** 2
xxterms = "full", xyterms = "full"
xxorder = 3, xyorder = 3, yxorder = 3, yyorder = 3
xin = a11 + a21 * xref + a31 * xref ** 2 +
a12 * yref + a22 * xref * yref + a32 * xref ** 2 * yref +
a13 * yref ** 2 + a23 * xref * yref ** 2 +
a33 * xref ** 2 * yref ** 2
yin = a11' + a21' * xref + a31' * xref ** 2 +
a12' * yref + a22' * xref * yref + a32' * xref ** 2 * yref +
a13' * yref ** 2 + a23' * xref * yref ** 2 +
a33' * xref ** 2 * yref ** 2
If the *fit_geometry* parameter is anything other than "general",
the order parameters assume the value 2 and the cross terms
switches assume the value "none", regardless of the values set by
the user.
Automatic pixel rejection may be enabled by setting *maxiter* > 0
and *reject* to some number greater than 0.
*bbox* defines the region of validity of the fit in the reference
coordinate system and may be set by the user. These parameters
can be used to reject out-of-range data before the actual fitting
is done.
The transformation computed by the "general" fitting geometry is
arbitrary and does not correspond to a physically meaningful
model. However, the computed coefficients for the linear term can
be given a simple geometrical geometric interpretation for all the
fitting geometries as shown below::
fitting geometry = general (linear term)
xin = a + b * xref + c * yref
yin = d + e * xref + f * yref
fitting geometry = shift
xin = a + xref
yin = d + yref
fitting geometry = xyscale
xin = a + b * xref
yin = d + f * yref
fitting geometry = rotate
xin = a + b * xref + c * yref
yin = d + e * xref + f * yref
b * f - c * e = +/-1
b = f, c = -e or b = -f, c = e
fitting geometry = rscale
xin = a + b * xref + c * yref
yin = d + e * xref + f * yref
b * f - c * e = +/- const
b = f, c = -e or b = -f, c = e
fitting geometry = rxyscale
xin = a + b * xref + c * yref
yin = d + e * xref + f * yref
b * f - c * e = +/- const
The coefficients can be interpreted as follows. `xref0`, `yref0`,
`xin0`, `yin0` are the origins in the reference and input frames
respectively. Orientation and skew are the rotation of the *x* and
*y* axes and their deviation from perpendicularity
respectively. `xmag` and `ymag` are the scaling factors in *x* and
*y* and are assumed to be positive::
general (linear term)
xrotation = rotation - skew / 2
yrotation = rotation + skew / 2
b = xmag * cos (xrotation)
c = ymag * sin (yrotation)
e = -xmag * sin (xrotation)
f = ymag * cos (yrotation)
a = xin0 - b * xref0 - c * yref0 = xshift
d = yin0 - e * xref0 - f * yref0 = yshift
shift
xrotation = 0.0, yrotation = 0.0
xmag = ymag = 1.0
b = 1.0
c = 0.0
e = 0.0
f = 1.0
a = xin0 - xref0 = xshift
d = yin0 - yref0 = yshift
xyscale
xrotation 0.0 / 180.0 yrotation = 0.0
b = + /- xmag
c = 0.0
e = 0.0
f = ymag
a = xin0 - b * xref0 = xshift
d = yin0 - f * yref0 = yshift
rscale
xrotation = rotation + 0 / 180, yrotation = rotation
mag = xmag = ymag
const = mag * mag
b = mag * cos (xrotation)
c = mag * sin (yrotation)
e = -mag * sin (xrotation)
f = mag * cos (yrotation)
a = xin0 - b * xref0 - c * yref0 = xshift
d = yin0 - e * xref0 - f * yref0 = yshift
rxyscale
xrotation = rotation + 0 / 180, yrotation = rotation
const = xmag * ymag
b = xmag * cos (xrotation)
c = ymag * sin (yrotation)
e = -xmag * sin (xrotation)
f = ymag * cos (yrotation)
a = xin0 - b * xref0 - c * yref0 = xshift
d = yin0 - e * xref0 - f * yref0 = yshift
**Parameters:**
- *input*: Array of input coordinates. (Must be an Nx2 array).
- *ref*: Array of reference coordinates. (Must be an Nx2 array).
- *bbox*: The range of reference coordinates over which the
computed coordinate transformation is valid. Must be
convertible to a 4-length or 2x2 array of the form::
[xmin, ymin, xmax, ymax]
or::
[[xmin, ymin], [xmax, ymax]]
If the user is working in pixel units, these limits should
normally be set to the values of the column and row limits of
the reference image, e.g ``[1.0, 1.0, 512.0, 512.0]`` for a 512
x 512 image. The minimum and maximum values in *ref* input are
used if *bbox* is `None` or any of its members are NaN.
- *fit_geometry*: The fitting geometry to be used. The options
are the following:
- "shift": *x* and *y* shifts are only fit.
- "xyscale": *x* and *y* shifts and *x* and *y* magnification
factors are fit. Axis flips are allowed for.
- "rotate": *x* and *y* shifts and a rotation angle are fit.
Axis flips are allowed for.
- "rscale": *x* and *x* shifts, a magnification factor assumed
to be the same in *x* and *y*, and a rotation angle are
fit. Axis flips are allowed for.
- "rxyscale": *x* and *y* shifts, *x* and *y* magnifications
factors, and a rotation angle are fit. Axis flips are allowed
for.
- "general" (default): A polynomial of arbitrary order in *x*
and *y* is fit. A linear term and a distortion term are
computed separately. The linear term includes an *x* and *y*
shift, an *x* and *y* scale factor, a rotation and a
skew. Axis flips are also allowed for in the linear portion of
the fit. The distortion term consists of a polynomial fit to
the residuals of the linear term. By default the distortion
term is set to zero.
For all the fitting geometries except "general", no distortion
term is fit, i.e. the *x* and *y* polynomial orders are assumed
to be 2 and the cross term switches (*xyterms* and *yxterms*)
are assumed to be "none", regardless of the values of the
*xxorder*, *xyorder*, *xxterms*, *yxorder*, *yyorder* and
*yxterms* parameters set by the user.
- *function*: The type of analytic surface to be fit. The options
are the following.
- "legendre": Legendre polynomials in *x* and *y*.
- "chebyshev": Chebyshev polynomials in *x* and *y*.
- "polynomial" (default): Power series in *x* and *y*.
- *xxorder*, *xyorder*, *yxorder*, *yyorder*: The order of the
polynomials in *x* and *y* for the *x* and *y* fits
respectively. The default order and cross term settings define
the linear term in *x* and *y*, where the 6 coefficients can be
interpreted in terms of an *x* and *y* shift, an *x* and *y*
scale change, and rotations of the *x* and *y* axes. The
"shift", "xyscale", "rotation", "rscale", and "rxyscale",
fitting geometries assume that the polynomial order parameters
are 2 regardless of the values set by the user. If any of the
order parameters are higher than 2 and *fit_geometry* is
"general", then a distortion surface is fit to the residuals
from the linear portion of the fit.
- *xxterms*, *yxterms*: The options are:
- "none": The individual polynomial terms contain powers of *x*
or powers of *y* but not powers of both.
- "half" (default): The individual polynomial terms contain
powers of *x* and powers of *y*, whose maximum combined power
is ``max(xxorder - 1, xyorder - 1)`` for the *x* fit and
``max(yxorder - 1, yyorder - 1)`` for the *y* fit.
- "full": The individual polynomial terms contain powers of *x*
and powers of *y*, whose maximum combined power is
``max(xxorder - 1 + xyorder - 1)`` for the *x* fit and
``max(yxorder - 1 + yyorder - 1)`` for the *y* fit.
The "shift", "xyscale", "rotation", "rscale", and "rxyscale"
fitting geometries, assume that the cross term switches are set
to "none" regardless of the values set by the user. If either of
the cross terms parameters are set to "half" or "full" and
*fit_geometry* is "general" then a distortion surface is fit to
the residuals from the linear portion of the fit.
- *maxiter* = 0: The maximum number of rejection iterations. The
default is no rejection.
- *reject* = 3.0: The rejection limit in units of sigma.
**Returns:** A 2-tuple with the following parts:
- `GeomapResults` object, with the following attributes:
- *fit_geometry* str: The same value as *fit_geometry* passed to
`geomap`.
- *function* str: The same value as *function* passed to `geomap`.
- *rms* (x, y) tuple: The root-mean-square of the residuals.
- *mean_ref* (x, y) tuple: The mean value of the reference
coordinates.
- *mean_input* (x, y) tuple: The mean value of the input
coordinates.
- *shift* (x, y) tuple: The translation of the fit.
- *mag* (x, y) tuple: The scale of the fit.
- *rotation* (x, y) tuple: The rotation of the fit.
- *xcoeff* double array: The first-order *x* coefficients of the
fit.
- *ycoeff* double array: The first-order *y* coefficients of the
fit.
- *x2coeff* double array: The second-order *x* coefficients of
the fit.
- *y2coeff* double array: The second-order *y* coefficients of
the fit.
- A Numpy structured array with the following columns:
- *input_x*
- *input_y*
- *ref_x*
- *ref_y*
- *fit_x*
- *fit_y*
- *resid_x*
- *resid_y*
|