In order to use different images as color channels, it is important that the images be properly aligned and on the same pixel grid. When your inputs are high-level products of the same survey, this is usually the case. However, in many other situations the images you plan to use as different color channels lie on different sky positions, even if they may have the same number of pixels. In this section we will show how to solve this problem.
For an example dataset, let’s use the same SDSS field that we used in Detecting large extended targets: the field covering the outer parts of the M51 group. With the commands below, we’ll make an inputs directory and download and prepare the three g, r and i band images of SDSS over the same field there:
$ mkdir inputs $ sdssurl=https://dr12.sdss.org/sas/dr12/boss/photoObj/frames $ for f in g r i; do \ wget $sdssurl/301/3716/6/frame-$f-003716-6-0117.fits.bz2 \ -O$f.fits.bz2; \ bunzip2 $f.fits.bz2; \ astfits $f.fits --copy=0 -oinputs/$f.fits; \ rm $f.fits; \ done
With the commands below, first we’ll check the size of all three images to confirm that they have exactly the same number of pixels. Then we’ll use them as three color channels to construct a PDF image:
## Check the number of pixels along each axis of all images. $ astfits inputs/*.fits --keyvalue=NAXIS1,NAXIS2 ## Create a color image from the non-yet-aligned inputs. $ astconvertt inputs/i.fits inputs/r.fits inputs/g.fits -g1 \ --fluxhigh=1 -om51-not-aligned.pdf
Open m51-not-aligned.pdf with your PDF viewer, and zoom-in to some part of the image with fewer sources. You will clearly see that for each object, there are three copies, one in red (from the reddest filter; i), one in green (from the middle filter; r), and one in blue (the bluest filter; g). Did you see the Warning message that was printed after your latest command? We have implemented a check in Warp to inform you when the images are not aligned and can produce bad (in most cases!) outputs like this.
To solve this problem, you need to align the three color channels into the same pixel grid. To do that, we will use the Warp program and in particular, its Align pixels with WCS considering distortions.
Let’s take the middle (r band) filter as the reference to define our grid. With the first command below, let’s align the r band filter to the celestial coordinates (so the M51 group’s position angle doesn’t depend on the orientation of the telescope when it took this image). With the next two commands, let’s use the --gridfile to ensure that the pixel grid and WCS comes from the r band image, but the pixel values come from the other two filters. Finally, in the last command, we’ll produce the color PDF from the three aligned images (that aren’t in the inputs/ directory any more):
## Put all three channels in the same pixel grid. $ astwarp inputs/r.fits --output=r.fits $ astwarp inputs/g.fits --gridfile=r.fits --output=g.fits $ astwarp inputs/i.fits --gridfile=r.fits --output=i.fits ## Create a color image from the aligned inputs. $ astconvertt i.fits r.fits g.fits -g1 --fluxhigh=1 -om51.pdf
Open the new m51.pdf and compare it with the old m51-not-aligned.pdf. The difference is obvious! When you zoom-in, the stars are very clear and the different color channels of the same object in the sky don’t fall on different pixels. If you look closely on the two longer edges of the image, you will see that one edge has a thin green shadow and the other has a thin red shadow. This shows how green and red channels have been slightly shifted to put your astronomical sources on the same grid.
If you don’t want to have those, or if you want the outer parts of the final image (where there was no data) to be white, some more complex commands are necessary. We’ll leave those as an exercise for you to try your self using Warp and/or Crop to pre-process the inputs before converting it to a color image.