Creative Commons License Copyright © Michael Richmond. This work is licensed under a Creative Commons License.

Aligning and stacking images

Suppose you have a number of images of the same field. Can you combine them to create a deeper, more detailed image? The answer is "yes," of course, but how can you do it? Just how well can you align one image with another?

Moreover, if you combine N images with the same exposure time, how much do you gain over a single image? Should you expect to see stars which are N times fainter?


The images for today's exercise

You can find the images for today's exercise in the directory $dd/align. Please copy all these images into your own directory. There will be a lot of them: 101 images. One hundred of them have names like this:


   mrdeli-001.fit   mrdeli-002.fit   mrdeli-003.fit  ...   mrdeli-100.fit

There is one special image:


   template.fit

All the images were taken on August 25, 2009, as part of a study of the eclipsing binary star MR Del. Here's the template frame, template.fit

In order to share the work of measuring many images, each student today will be assigned to a set of 5 images. One student will get the images


 mrdeli-001.fit  
 mrdeli-002.fit  
 mrdeli-003.fit  
 mrdeli-004.fit  
 mrdeli-005.fit

another student


 mrdeli-006.fit  
 mrdeli-007.fit  
 mrdeli-008.fit  
 mrdeli-009.fit  
 mrdeli-010.fit

and so on. Please make sure you know which images you will be measuring today.


Measure positions of the bright stars A, B, MR

The first step in aligning and stacking is to figure out just how large an offset exists between two images. We'll use the positions of the bright stars to find this offset. You'll need to measure the position, both row and column, for each of the three bright stars, in

In order to find the position of a single star, you can display the image with the tv command and then move the cursor over the star. Press the 'a' key, and a line like this should appear in your terminal window.


( 414.62  199.20) flux  76482.2 npix 314.5 mag 12.791  sky   98.0  [10.0 10 30]

The two numbers inside the parantheses are the star's row and column position, respectively.

Make a table which shows the positions of each of the three stars in the template image, and in each of your five images.



                     MR                   A                  B
                  row   col          row   col           row   col
-------------------------------------------------------------------------

template


first image


second image


third image


fourth image


fifth image

-------------------------------------------------------------------------------


How precise are these positions?

You'll see numbers which have two decimal places after the decimal point, like 414.62. Does that mean that the precision of the measurement is 0.01 pixels? Not necessarily. We can determine the precision of these measurements by making one simple assumption: the stars aren't moving relative to each other during the entire night.

Suppose we measure the offset between two stars in one image, both in rows and columns. We _should_ find exactly the same offset between those two stars in every other image; however, due to the presence of noise, we may _actually_ find that the offsets aren't exactly the same. Your job today is to figure out just how precise and repeatable these measurements of position are.

Use your table of positions to make a new table, in which you list the offset between star MR and each of the other stars.



                     MR - A                      MR - B
                  delta_row  delta_col       delta_row   delta_col
-------------------------------------------------------------------------

template


first image


second image


third image


fourth image


fifth image

-------------------------------------------------------------------------------

After you've filled this table, you can compute the mean and standard deviation of the offsets in each case. A quick way to compute these statistical quantities is to use the stats command, like this:

  1. What is the standard deviation in the row difference between MR and A?
  2. What is the standard deviation in the row difference between MR and B?
  3. What is the standard deviation in the col difference between MR and A?
  4. What is the standard deviation in the col difference between MR and B?
  5. How well do you think one can measure the position of a star in these images? Express your answer in pixels, and in arcseconds. Each pixel in these images is about 1.06 arcseconds on a side.


Aligning images

Okay, the next step is to align your images so that each one has stars in the same position as the template image. First, make a copy of each of your five images. Give each copy a name like this:


     mrdeli-005.fit      --->    shift-005.fit

Next, use the first table you created to determine the difference between the position of each star in the template image and the position of that star in each other image.



               Difference in position (template - other)

                    MR           A            B              average of 
                                                           all three stars
----------------------------------------------------------------------------

           row
first 
           col


           row
second 
           col


           row
third 
           col


           row
fourth 
           col


           row
fifth 
           col

------------------------------------------------------------------------------

You should end up with an average value for the difference in rows, and an average value for the difference in columns, for each image. Let's say that your first image is called mrdeli-021.fit and looks like this:

Let's say that for this image, you find


     (template - mrdeli-021.fit)         delta_row  =   46.41
                                         delta_col  =  -23.28

In order to shift the contents of an image by a certain distance, you can use the imshift command. For example, before


      imshift  shift-021.fit  dr=46.41  dc=-23.28

If you display the shifted image, you'll see that the stars have moved:

  1. Shift each of your five images by the amount required to make it match the template.
  2. Verify that the shifting was correct by displaying each image next to the template.
  3. Place a copy of each of your shifted images into a single directory like this: (the ~ is the "tilde" character)
    
               cp shift-021.fit ~/shift
               cp shift-022.fit ~/shift
               cp shift-023.fit ~/shift
                 (etc.) 
           


Combine the aligned images

So, now you have a set of aligned images. What can you do with them?

One way to combine them is to add them. You can try that, like so:


     add shift-021.fit shift-022.fit shift-023.fit outfile=shift_sum.fit

Another way to combine them is to use the median command. Be sure to include the nomean keyword, since we don't want to scale the various input files this time.


     median shift-021.fit shift-022.fit shift-023.fit nomean outfile=shift_median.fit

  1. Create both a "sum" and "median" from your aligned images.
  2. Look at your "sum" and "median" images. Do they show stars which are invisible in the original template image?
  3. Use Aladin to show the sky around the star "MR Del". Use the "Survey" called "USNO B1.0" to make an overlay on the Aladin image window. You can click on the stars shown on the overlay to find their I-band magnitudes.
  4. What is the magnitude of the faintest star you can see in the original template image?
  5. What is the magnitude of the faintest star you can see in each of your combined images?

I combined all the images taken on this night. There were 915 images, each 5 seconds long. Here's the template image:

Here's the result of ADDING all 915 images.

Here's the result of taking the MEDIAN all 915 images.

You can copy my images like so:


   cp $dd/align/shift_all_sum.fit .
   cp $dd/align/shift_all_median.fit .

and then you can examine the images shift_all_sum.fit and shift_all_median.fit at your leisure.

  1. What is the magnitude of the faintest star you can see in the shift_all_median image?
  2. How many magnitudes did we gain by adding 915 individual images?
  3. Does that correspond to a star 915 times fainter?


For more information

Creative Commons License Copyright © Michael Richmond. This work is licensed under a Creative Commons License.