Registering and Co-Adding Images


   If you have two or more short, sky-subtracted exposures that you want to combine into a single image, you will undoubtedly find that the positioning of the field on the CCD is not exactly the same on different exposures. You will therefore need to shift the images to bring them into registration.

   If you are combining images taken on the same night, then probably all that will be needed is a simple linear shift. If you are trying to combine images from different nights, then the camera will probably have been mounted differently and a rotation will also be needed. This page deals only with the former case.

1. Registration

   Examine the images you want to combine, and choose one to be the reference image. The other images will be shifted to match the reference, so it makes sense to choose the reference image to be "in the middle" of the group.

   In the reference image, choose 4 to 8 stars that are also clearly visible in all of the other images. The brighter the better, as long as the stars are not overexposed. Try to choose stars that are dispersed evenly about the image, and avoid stars that are close to diffuse objects (e.g. galaxies). Determine their (x,y) pixel coordinates, to the nearest pixel or two, by zooming in on them in the image display.

   Use an editor to write a regions file that lists 30 by 30 pixel boxes about each of the chosen stars in the reference image. For example,

[631:660,163:192]
[191:220,696:725]
[289:318,295:324]
[1235:1264,415:444]
[1391:1420,588:617]
[1311:1340,852:881]
   Write another file that contains the names of the images to be shifted. For example,
zn2005.fits
zn2008.fits
zn2009.fits
zn2013.fits
zn2016.fits
zn2017.fits
Note that the reference image should not be included in this list. Make a copy of this file and edit it to make a list of output image names. (Some people like to add an "r" at the beginning.) Be careful not to overwrite your input images.

   Finally, you need to make an initial coordinate shifts file. Get the (x,y) coordinates in the reference image of the center of the first star in the regions file (to the nearest pixel or so). Put these coordinates in the first line of the file, separated by a space (no comma, no parentheses). In the following lines, type the coordinates of the same star in each image in the input list. The order of coordinates must match the order of images. The coordinate file may look something like this:

646 179
704 157
597 171
649 122
706 125
691 186
613 181
As a check, notice that the coordinate file should be one line longer than the input file list or the output file list.

   Now you can edit the parameters for the 'xregister' task. Set the "input" to the name of your input list file, preceded by a @. The "reference" is the name of your reference image and "regions" the name of your regions file. Set "shifts" to some unused filename such as xreg.shifts; this is where the task writes a record of the computed shifts. Set "output" to the name of your output list file preceded by a @, and "coords" to the name of your initial coordinate shifts file. It is also recommended that "boundary_typ" be set to "constant", and "constant" (on the next line) to 0, although this doesn't really matter in the long run. "Interactive" can be set to no and "verbose" to yes. All other parameters can be left at their default values.

   When you run the task, watch carefully for error messages, because it is easy to make small mistakes in the region and coordinate files. If necessary, imdelete the output files and try again.

   After the task has successfully run, write down the overlap region, which xregister should have printed on the screen. Then, check the shifted images by blinking them against the reference. Verify thoroughly that the images are aligned exactly. They may appear registered at first glance, but when you zoom in closer you may find that they are not.

Co-Adding the Registered Images

   Depending on your science goal, it may not be a good idea to co-add images with very different point-spread functions (PSFs). You should examine your images, and if you haven't already, discard those with badly enongated star images or other serious problems. You may need to match the PSFs, by degrading the best images to match the quality of the worst, before adding. This procedure is beyond the scope of this document, but only needs to be considered if the width of the PSF varies by more than a few tens of percent between the images. Quick inspection of the PSF can be done using the 'a', 'r', and 'e' commands in 'imexamine'.

   The 'imexpr' task is easiest for coadding images. Simply type the command and let IRAF prompt you for the parameters. The expression for adding two images would be "a+b"; for adding three, "a+b+c", and so on. The task will prompt you for the name of the output image before the names of the input images, so be careful!

   Finally, use 'imcopy' to trim the non-overlapping region from the edge of the co-added image, using the overlap region returned by 'xregister'; e.g.,

imcopy coadd.fits[105:1499,88:995] coaddtrimmed.fits


Last updated 2008 May 29. Written and maintained by Tom Statler. This page is adapted from a document originally written by Megan Krejny.