**Brief Description**

The code computes the relative rotation and orthogonal translations
between a reference image and an input image. The algorithm employed
is based on a nonlinear
least squares fitting technique, which solves for ,
, and in
the transformation

,

where () are input-image coordinates,
() are reference-image coordinates,
is the relative rotation angle between the two images,
() are input-image coordinates of the
rotational center, and () are relative orthogonal
translations
between the reference image and the __co-rotated__ input image
(that is, the image-origin offets after rotating the input image so
that it is
unrotated with respect to the reference image).
The constraint that is imposed by the fitting
technique. The code
also includes
logic to identify and reject outlier sources, using a two-stage
method.

**Required Inputs**

Measurements of (*x*, *y*) positions of *N* sources
in the input image, corresponding measurements of (*x*, *y*) source
positions in the reference image, and relative weights for each
of the *N* sources (larger weight more
accurate measurement). A minimum of two sources is required.
The input values are read line-by-line from standard input after
the code is executed (not from the command line), where each line
contains *x*, *y*, *x'*, *y'*, and the weight for a given
source.

**Optional Command-Line Inputs (Default Values Otherwise Taken)**

theta0 = Initial estimate of the rotation angle, in units
of degrees (default value is 0.0).
Currently used only as an output diagnostic,
and not fedback into the fitting (a
potential code upgrade).

xp = *x*-coordinate of rotational center in the input-image
coordinate system, in units of pixels (default value is 0.0).

yp = *y*-coordinate of the rotational center in the
input-image coordinate system, in
units of pixels (default value is 0.0).

siginp = Estimated weighted-average standard deviation of
*x* and *y* measurements, in units of pixels
(default value is 0.05 pixels = 0.8 arcseconds for WIRE pixels).

chi2tol = Threshold for relative change in reduced chi2 after
rejection of candidate outliers (default value is 0.8). The quantity
, where is
the value of reduced chi2 prior to outlier
rejection ( is the associated
number of degrees of freedom), and
is the value of reduced chi2 after
outlier rejection (
is also the associated number of degrees of freedom),
must be greater than chi2tol, in order for
the candidate outliers to be
rejected.

npostol = Number of sigmas of the *x* or *y* position error
for determining a candidate outlier, where sigma is computed
with the candidate outlier excluded (default value is 5).

radtol = Radial position error threshold for determining
a candidate outlier, in units of pixels (default value is
0.25 pixels = 3.9 arcseconds for WIRE pixels).

nfirst = Maximum number of sources allowed by the first stage
of outlier-rejection processing (default value is 8). If *N*
> nfirst, then this first stage is bypassed.

v = Verbose switch: set to true for additional output diagnostics
(default value is false).

test = Test switch: set to true to execute the code using
input test data in the code (default value is false). See below for outputs
from the test=true case.

**List of Outputs**

1. , in units of pixels.

2. , in units of pixels.

3. , in units of degrees.

4. Number of sources left-over after outlier-rejection processing.

5. Number of sources rejected as outliers.

6. measure of goodness of fit (dimensionless, not reduced).

7. Number of degrees of freedom associated with .

8. Average fit error in the dimension, in units of pixels.

9. Standard deviation of the fit error in the dimension, in units of pixels.

10. Average fit error in the dimension, in units of pixels.

11. Standard deviation of the fit error in the dimension, in units of pixels.

12. Difference between and theta0, in units of degrees.

**Outputs For test=true Case**

delx = -11.7010 dely = 103.9679 theta = 71.1958 # kept = 5 # rejected = 0 chi2 = 3.0832614566898 # degs frdm = 7 x residual = -8.71931E-06 x std. dev. = 2.27405E-02 y residual = -1.45322E-06 y std. dev. = 2.67614E-02 Angle diff. = 71.1958

** Last revised:** October 20, 1997

** Software developer:** Russ Laher
(laher@ipac.caltech.edu)

** URL:** http://spider.ipac.caltech.edu/staff/laher/rotlsqdr.html