There are three script-tasks which allow "quick" image registration and
PSF-matching, and they are run in the following order:
	1. qcoords
	2. qregister
	3. qpsf

Finally, to perform intensity matching, you need to run a fourth task, `itran'.
Parameter inputs and use for each are described below.



QCOORDS:
        input = ""              input image
    coordlist = ""              output coordinate list
       dispim =                 Display image?

This task sets up the initial grid of reference stars on the reference image.
If you display the reference image before running the task, then you can set
"disp-"; otherwise the task displays the image for you.  Mark the reference
stars with the image cursor (hitting "space" marks the star).  NB: NOTE THE
FIRST TWO STARS YOU MARK -- you must identify these same two stars (in the
correct order) on the input images below. The task uses FITPSF to center
on the stars, and write the output list to the file "coordlist".  The last
part of the task puts you into the editor -- remove any unwanted stars.

USE:
al>  qcoord REF_IMAGE POS_OUT [disp-]

If you have more than one image to align with the reference image, you only
need to run QCOORDS once.



QREGISTER:
        input = ""              input image
       output = ""              output image
    reference = ""              reference image
      coordin = ""              coord.list in reference stars
    inversion =                 Is input inverted wrt. reference?
       dispim =                 Display image?

This task performs the image registration. You must specifiy the input image
(ie image to be aligned with the reference image), output image and
reference image. "coordin" is the grid of reference stars created by QCOORDS.
NB: YOU MUST SPECIFY IF THE INPUT IMAGE IS INVERTED WITH RESPECT TO THE
REFERENCE IMAGE -- generally it's not, so I've chosen identifying two 
(rather than 3) reference stars and allowing the user to specify inversion
explicitly.

USE:
al> qreg INPUT OUTPUT REF_IM COORDIN inv-[+] [disp-]

In use, after the image is displayed you identify the first two reference
stars with the image cursor (hit "space" key).  Then, these positions are
used to predict where the other stars will be found; all stars centers are 
found with FITPSF as in QCOORDS.  Next, the task GEOSCALE is called to
work out the geometrical transformation (this produces the proper input
for GEOTRAN, which then produces the actual transformed (output) image).
During GEOSCALE, you will be presented with a map of the reference stars with
vectors representing the residuals. Use `c' to change the weights of
any (deviant) points, `f' to refit, `?' for other options.


QPSF:
        input = ""              input image
       output = ""              output image
    reference = ""              reference image
            x =                 x of reference star
            y =                 x of reference star
            z =                 amplitude of reference star
      subrast =                 conv. kernel subraster

This task performs the PSF-matching by degrading the input image to the PSF
of the reference image. This can be somewhat tricky at times -- read the
file `tnotes' for more information. It may not be possible to match the
PSFs by degrading only one image, so this task may have to be run twice
on both the input image and the initial reference image.

Use the output from QREGISTER to select a suitable reference star. The ideal
star is near the center of the field, has excellent signal-to-noise, no
close neighbors, and is well-centered on a pixel (eg -- center at 356.0, not
356.5).  NB: SATURATED STARS ARE USELESS FOR THIS PURPOSE.  Stars whose
centers differ in the two aligned images (reference and output from QREGISTER)
are suspect. Also, note the SIGMA and the AMPLITUDE of the chosen reference
star.  The image with the smaller sigma (ie best seeing) is the INPUT image
here, because the PSF must be degraded.  The amplitude of the reference star
in the INPUT image should be used for the parameter `z' in this task.

USE:
al> qpsf INPUT OUTPUT REF_IM Xstar Ystar Z

During the operation of this task, you are presented first with a contour
map of the power-spectrum of the convolution kernel.  Note whether the
contours "max-out" along any axis (if so, you may have to run the task again
to degrade the reference image to match the output image here). If the
entire map is "maxed-out", then you're using the wrong image as the reference
image. If the map is centrally peaked, but extremely noisy, you may need
to raise `z' or find a brighter reference star.  If the map shows good-looking
contours out to about halfway to the edge, and then the ideal gaussian contours
of the model in the outer half, then things are looking about right. (Hit any
key to exit the plot.)

Next, you'll see a contour plot of the convolution kernel. Look for spurious
off-center features -- you'll want to exclude these when selecting the kernel
subraster. Also, note oscillations along one or both axes -- these are due
to a sinc component, which means the alignment is poor (at least for this
reference star). (Hit any key to quit)

The task ANKERN is called next, and it shows the normalized flux contained in
kernel subrasters of difference sizes, as well as the rms, min and max values
in square "annuli" about the center of the subraster.  Ideally, there should
be a subraster size where the rms, min and max all go to zero, and 100% of
the flux is contained. In practice, this never happens. Choose the smallest
subraster tah contains roughly 98-102% of the flux, and just before the rms,
min and max start to level off (ie the subraster should contain the pixels
which are significantly above "background" values). Typical subraster sizes
seem to be around [12:22,12:22] and [13:21,13:21].  Enter the chosen subraster
(in the format [x1:x2,y1:y2]) as input. The input image is convolved with
the chosen kernel subraster. If you intend to use ITRAN (below) note the
"noise reduction factor" which is printed -- this represents the effective
reduction in the noise caused by "smoothing" the image during the convolution.



ITRAN:
       image1 = ""              first image (section)
       image2 = ""              second image (section)
         xcen =                 box x-center (image1)
         ycen =                 box y-center (image1)
      delrad1 = 0.              [inner deletion radius]
      delrad2 = 1.1             [outer deletion radius]
          (nx = 32)             # col in box
          (ny = 32)             # lines in box
      (xshift = 0)              x offset to image 2
      (yshift = 0)              y offset to image 2
   (xelec_adu = 1.)             elec/adu for image 1
   (xread_out = 0.)             readou(elec) for image 1
   (yelec_adu = 1.)             elec/adu for image 2
   (yread_out = 0.)             readou(elec) for image 2
       (niter = 5)              no. of iterations to fit
       (apply = no)             apply the linear transformation?
         (out = "")             output image (image 1 scaled to image 2)

This task solves for and optionally applies a linear transformation in
intensity. It is most useful if the two images are taken through the same
passband, although it can be used (with care) for images in different filters.
Input images should be aligned and PSF-matched; the transformation is such
that "image1" is scaled and offset in intensity to match "image2".

Pick a region, preferably with high signal-to-noise features AND containing
pure sky.  If you want to see how well the PSF-matching worked, you
can use the reference star from QPSF. The box is specified by "xcen", "ycen"
and by "nx", "ny". For correct treatment of errors, specify the gain and
readout noise for image1 ("xe", "xr") and image2 ("ye", "yr"). Note that
smoothing in QPSF will reduce the noise in the degraded image; to account
for this, divide the appropriate elec_adu by the "noise reduction factor"
printed out by QPSF.

USE:
al> itran IMAGE1 IMAGE2 XCEN YCEN xe=XE xr=XR ye=YE yr=YR app+ out=IMAGE_OUT
	
ITRAN can often be run without deleting any points -- simply do an "r" to see
the residuals, then "q" if it looks OK. If you have specified an output image,
the scaling will be applied at this point. For other cursor options, type `?'.


..........................................................................

For more sophisticated use, you can run the various tasks individually.
See the script tasks for how it's all put together, and the individual
parameter files for specific parameter input to each task.

==========================================================================

DISCLAIMER: This is unsupported, use-at-your-own risk software. I'd like to
keep making improvements, however.  Please report problems or questions to
	phillips@ucolick.org
Thanks!

Andrew C. Phillips
Lick Observatory
Univ. of California at Santa Cruz
Santa Cruz, CA 95064

(408) 459-3841
