Currently not logged in. main | wiki | tasks | examples | forums | privacy | login

A composite image of the M74 galaxy

In this example we demonstrate how the tasks in the FITSH package can be exploited to create a color composite astronomical image from individual scientific frames. In principle, a nice colorful image requires low noise, so either we need long exposure frames or multiple images should be combined in order to obtain this sufficiently low noise level. Since both the guiding errors of the telescope mounts and the presence of the athmospheric refraction impede us from longer exposure times, we focus on now methods based on multiple image combination. Additionally, this method also has the advantage that small but explicit dithering in the telescope position allows us to reject bad pixels or flat errors from the final image by taking a median average of the individual frames.

This actual example uses 3 × 10 individual images, in B, V and R filters from the galaxy M74. These images were taken on the night of 2010 November 15/16, between 18:48 and 20:00 UT using the 60/90/180 cm Schmidt telescope located on the Piszkés-tető Mountain Station of the Konkoly Observatory, Hungary. Each frames were exposed for 2 minutes. This example assumes that all of these 30 frames have already been calibrated using some standard calibration processing (see other examples related to calibration here). The calibrated frames are supposed to be named as Rm74-0001-B.fits, Rm74-0001-V.fits, Rm74-0001-R.fits, and so on (the sequence number in the file names are between 0001 and 0010). The basic steps of the image processig are going to be the following:

If you intend to try this set of data reduction scripts in your system, the full archive of related data can be downloaded by downloading the individual files listed here: m74-galaxy.list. This archive includes the 30 calibrated frames and the base.list file containing the ``basenames'' of these frames. This archive linked above is relatively large: the individual calibrated images have a size of 4096 × 4096 pixels, thus each image is approximately 64 megabytes (using 32-bit floating point representation), therefore the whole archive is around 2 gigabytes.

Registration

The step of image registration has the same three sub-steps like in the case of, for instance, photometry of Varuna. Namely, first, we detect some stars on the images; second, using these lists of stars we derive relative astrometric transformations and third, apply these transformations on the individual images. All of these steps can simultaneously handle the images taken with the three different filters. Thus, in all of these three sub-stebs we follow the similar methods (like here). The list of file basenames (filenames without the extensions) are listed and should be set up before these procedures in the file base.list.

So, first stars are searched and listed to individual files, using the fistar task. If the images are de-focused and stars are somehow blurred, it is easier to detect stars on a shrinked image. The shrink factor $SHF can be set to any arbitrary positive integer. If it is larger than unity, then both the task fitrans is called in --shrink mode and the program awk is used to multiply the resulted X and Y centroid coordinates by this factor.

#!/bin/bash

FITS=./fits
ASTR=./astrom
 
SHF=2

cat base.list | \
while read base dummy ; do

        if test 1 -lt $SHF ; then
                fitrans $FITS/$base.fits --shrink $SHF 
        else
                cat     $FITS/$base.fits 
        fi | \
        fistar  --input - \
                --flux-threshold 20000 --model elliptic \
                --format id,x,y,s,d,k,flux,mag \
                --output - | \
        awk -v s=$SHF \
         '{     print $1,$2*s,$3*s,$4,$5,$6,$7,$8;
         }' > $ASTR/$base.stars

        l=`cat $ASTR/$base.stars | wc -l`

        echo "$base: done [$l]." >> /dev/stderr

done

If we have the list of stars on each image, we use the task grmatch to obtain the relative astrometric transformations between the individual images and a previously selected reference image. Here, this reference image is Rm74-0005-R.

#!/bin/bash

ASTR=./astrom

ref=Rm74-0005-R

cat base.list | \
while read base dummy ; do

        grmatch --reference $ASTR/$ref.stars --col-ref 2,3 --col-ref-ordering -8 \
                --input $ASTR/$base.stars --col-inp 2,3 --col-inp-ordering -8 \
                --max-distance 1 \
                --order 3 --triangulation auto,unitarity=0.01,maxref=1000,maxinp=1000 \
                --weight reference,column=8,magnitude,power=2 \
                --comment --output-transformation $ASTR/$base.dtrans

        echo "$base: done." >> /dev/stderr

done

Once these relative transformations are known, we have to simply apply the task fitrans to shift the individual frames to the reference system.

#!/bin/bash

FITS=./fits
ASTR=./astrom
REG=./reg

cat base.list | \
while read base dummy ; do

        fiign   $FITS/$base.fits --output - | \
        fitrans --input-transformation $ASTR/$base.dtrans \
                -c --reverse --output $REG/$base.fits

        echo "$base: done." >> /dev/stderr

done

Flux level scaling

The flux level scaling is done in two distinct steps. First, aperture photometry is performed on a list of stars (that have been detected on the astrometric reference image, Rm74-0005-R). The results of this aperture photometry are stored in the directory ./phot. These photometric results are used in the second step, where the background infromation is used to subtract the background of the image to a nearly zero level.

Since the FOV of these images is relatively large (1.167 × 1.167 degrees), the background removal is done in a linear (first) order. To fit a certain background level or a flux scale level, the task lfit is used to obtain the coefficients. In order to subtract the background, the task fiarith is used to evaluate the coefficients obtained by lfit.

#!/bin/bash

ASTR=./astrom
REG=./reg
PHOT=./phot

ref=Rm74-0005-R

cat base.list | \
while read base dummy ; do

        fiphot  --input $REG/$base.fits \
                --input-list $ASTR/$ref.stars --col-xy 2,3 --col-id 1 \
                --aperture 8:15:25 --sky-fit mode --format IXY,FfBbs \
                --output - | \
        grep "G" > $PHOT/$base.phot

        echo "$base: done." >> /dev/stderr

done

Since the galaxy itself is relatively small (less than 10') compared to the FOV of the Schmidt telescope (that is 70' × 70'), we focus on the center of the image, i.e. we include only the central 2048 × 2048 region of the images for fitting the background information. Moreover, after subtracting the background level, the images are also trimmed to this smaller size.

#!/bin/bash

PHOT=./phot
SCALED=./scaled

ref=Rm74-0005-R

cat base.list | \
while read base dummy ; do

        A=($(   grmatch -r $PHOT/$ref.phot -i $PHOT/$base.phot \
                        --match-id --col-ref-id 1 --col-inp-id 1 \
                        --output-matched - | \
                awk \
                '{      x=$2;y=$3; 
                        if ( 1024 <= x && x < 3072 && 1024 <= y && y < 3072 )
                                print; 
                 }' | \
                lfit    \
                        -c x:2,y:3,bgr:6,bgi:14 -v a=0,b=0,c \
                        -f "a*(x-2048)/2048+b*(y-2040)/2048+c" -y bgi  ))

        fiarith "['reg/$base.fits'](a-((${A[0]})*x+(${A[1]})*y+(${A[2]})))" \
                --output - | \
        fitrans --offset 1024,1024 --size 2048,2048 -o $SCALED/$base.fits

        echo "$base: done." >> /dev/stderr

done

Image combination

Once the individual images are registered and scaled, it is safe to do a median average on them. Since the basenames of thte individual files ends with the appropriate filter name, we can use a simple shell wildcard pattern to select between the three bands. For the combination, we use the ficombine task.

#!/bin/bash

base=m74

DIR=./scaled

ficombine $DIR/*B.fits --mode median -o $base-b.fits
ficombine $DIR/*V.fits --mode median -o $base-v.fits
ficombine $DIR/*R.fits --mode median -o $base-r.fits

Scaling to a visual level

In order to have a smooth and nicely visualized image, we do some initial processing on the combined images as well, before feeding them to the task fiinfo. This task will then convert and ``visualize'' data from FITS to PGM format. The initial processing do a moving median box averaging with a box size of 3 × 3 pixels (done by fitrans, see --smooth median,hsize=1) and the resulted images are shrinked by a factor of 2.

To display the images, here fiinfo uses a simple linear scaling with a histogram percentage limitations of 99.7%. It means that the lower and higher intensity limits are derived as the boundaries of the central 99.7% of the pixel intensity distributions.

#!/bin/bash

base=m74

fitrans ${base}-b.fits --smooth median,hsize=1 --output - | \
fitrans --input - --shrink 2 --output - | \
fiinfo  --input - --pgm linear,percentage=99.7,contrast=1.0 --output-pgm $base-b.pgm
fitrans ${base}-v.fits --smooth median,hsize=1 --output - | \
fitrans --input - --shrink 2 --output - | \
fiinfo  --input - --pgm linear,percentage=99.7,contrast=1.0 --output-pgm $base-g.pgm
fitrans ${base}-r.fits --smooth median,hsize=1 --output - | \
fitrans --input - --shrink 2 --output - | \
fiinfo  --input - --pgm linear,percentage=99.7,contrast=1.0 --output-pgm $base-r.pgm

Create the composite image

The utilities found in the NetPBM package can be used to create the composite RGB image from the individual PGM images as well as to do some post-processing (trimming and conversion) on the resulted color (PPM) image. And at last, the utility pnmtopng is used to get the final image in the conventional PNG format.

#!/bin/bash

base=m74

rgb3toppm $base-r.pgm $base-g.pgm $base-b.pgm > $base.ppm
cat $base.ppm | pnmcut 192 160 512 512 | pnmtopng > $base-trim.png

The output of this script, i.e. the color composite image of the M74 galaxy is then:


Back to the examples or the main page.