Saturday, November 26, 2011
Basic astrophotography image processing in GIMP - Part 1: image calibration
It has been some time since I added anything useful to this blog, so here is a tutorial for beginners on astronomical image processing using GIMP. GIMP is open source and free. Photoshop is proprietary software and performs similar functions.
This tutorial is intended to provide a method for photographers of any skill level to try their hand at astrophotography, without the need for specialist equipment. Anyone with a digital camera and a tripod can easily take images of the night sky and produce satisfying results with basic, and in this case free software.
A very basic introduction
This tutorial uses jpeg images, because all digital cameras produce jpeg images. Serious astrophotographers, using DLSR cameras, shoot RAW. Forget about this for now. If you cant shoot RAW, jpeg is just fine.
There are several reasons for calibrating astronomical images. Primarily, to make our images look better, we want to reduce noise and retain detail in the final image, that is, we want to increase the Signal to Noise ratio (SNR). If we expose too long, finer detail is obliterated, too short and the image is dominated by noise. In any case, because we are taking images in low light (at night), noise is a problem. So what is the best exposure time to use?
If you have a tracking device that follows the stars (see the Tracker page, you may wish to build one) and the sky at your location is polluted by suburban lighting, and depending on the ISO setting, 1 - 5 minutes is usual. At a dark site (no suburban lights), exposures will be much longer - counter intuitive, perhaps, and a separate discussion altogether. Astrophotography can be complex. Here we wish to deal with the basics.
If you have a fixed tripod, you will most likely use a high ISO (1600 - 3200, perhaps higher), a short focal length lens, wide aperture and short exposures. At 24mm stars start to show trailing after about 10 seconds. This tutorial is based on the calibration of a single 10 second exposure - 24mm, f/4.0, iso1600. Don’t be put off by all of this. If you have any sort of camera with a manual setting, particularly the ability to take longer exposures, that will do for now - this tutorial is designed for you.
You will need to know where to find certain functions in GIMP. Referring to the File menu - I use the convention, File > Open as Layers, to indicate that you need to select File and Open as Layers. Another, Image > Flatten. And, Windows > Dockable Dialogs > Layers. Another, View > Zoom > 4:1 (400%). You will use all of these in this tutorial. Photoshop has something similar.
Why calibrate?
Digital images taken under low light conditions are noisy - produced by the electronic, thermal and optical properties of the camera, lens and ambient noise. Ambient noise changes from image to image (basically, a consequence of light conditions at the time). Because ambient noise is random, combining several images averages it out remarkably well, and we can pretty much forget about it for now.
Sources of noise…
Electronic (Bias) - when the camera takes a photo the sensor is activated electronically and this leaves a characteristic pattern (cross hatch - canon 1000D) of noise, easily seen in a low light image. We take a bias frame and subtract it from our image or images.
Thermal (Dark) - as the camera sensor acquires an image over a long duration it gets hot. Heat produces a characteristic thermal noise signature. We take a dark frame and subtract it from our image or images.
Optical (Flat) - the combined camera sensor and lens (optical train) has a characteristic appearance that shows up as dust spots, vignetting and variations in individual sensor pixels (not all pixels are equal in operation or light gathering capability). We take a flat frame and divide it into our image or images.
Ambient (Random) - reduced by combining images.
In-fact, it’s a little more complicated in that we take several bias, dark and flat frames and average each set to create a master bias, master dark and master flat, thereby obtaining a better average of each type of noise. And to complicate things further, bias, dark and flat noise is different for each exposure we take.
Let’s leave it at that. There is a good deal more to effective astro imaging. For now, we want to calibrate our newly acquired image and impress our friends and family - if indeed, they can be impressed.
The light image
We will use a single image in this example. The constellation Orion rising in the East. The Great Orion Nebula (M42) can be seen in the handle of Orions’ sword. A front yard perspective - tree, shrubs and power lines. The camera was mounted on a fixed tripod, lens focal length 24mm, iso1600, focal ratio, f/4.0, 10 seconds exposure time. Note the brown characteristic hue of light pollution. Because it’s a single exposure noise is quite evident.

The calibration frames
We begin by taking bias, dark and flat frames. Please note: the images shown have been processed to show the detail. Out of the camera, bias and dark frames appear as black frames. The flat will be a uniform light colour. I used Color > Auto > Equalize, to reveal the noise.
Bias - cover the lens (put the lens cap on, or cover with something that wont let light into the lens) and set the cameras’ fastest shutter speed - no need to change any other settings. Press the shutter release - 1 bias frame.
Dark - cover the lens as before and set the exposure time to that of the light frame. In this case 10 seconds. Press the shutter release - 1 dark frame.
Note the bias noise in the dark frame below. Because the dark is a 10 second exposure, there is not a lot of thermal noise and it looks very similar to the bias. Look closely and you will see the differences.
Flat - a bit more complicated, but well worth the effort, as you will see. This can be done in various ways, and each astrophotographer has their own true and tried method. For our purposes, we want to take an image of the camera sensor and lens, the inside the optics stuff. Focus must be the same as for the light frame. Here is an easy method, adequate for the purposes of this tutorial;
On your computer desktop open GIMP (Photoshop) and create a New frame. Maximize to fill the screen - the default is a white frame. If you wish, place a sheet of A4 paper over the computer display. Hold the camera lens (objective), so that it just touches the paper (as close as possible). Now, set the shutter speed to give an exposure (refering to the image preview histogram) of approximately 70 - 75% (make sure auto focus is off). Press the shutter - 1 flat frame.
Usually, and until familiar with your camera, taking flats may require some experimentation, till you get it right. This flat was taken at iso1600 and is quite noisy. But it’s OK to take flats at the lowest ISO provided by the camera. Note the vignetting at the corners (dark areas) and the dust spots on the face of the low pass filter, which is exposed to the air.
Calibrating the calibration frames
That’s right! First we must calibrate the calibration frames! You may have guessed it, but we need to subtract the bias from the dark, flat and light frames. This is easily done in GIMP (or Photoshop). With GIMP open on your desktop, File > Open as Layers, the dark and bias frames. You may need to go to the Windows > Dockable Dialogs > Layers, and open the Layers dialog, if it’s not already displayed.
It is inconvenient, but the first image opened as layers is automatically set as ‘Background’ - so we are left to deduce which is the bias and which is the other frame - there are only two, fortunately, but still use proper naming conventions; that is, bias, dark, light should be the names of our frames for this tutorial (it’s easy to mix them up otherwise). Set the dark frame as the background image (that is, at the bottom of the layer). The bias will be the image above. Highlight the bias and set Mode to Subtract. Now, flatten the image (Image > Flatten) and save as masterdark.jpg.
Do the same with the flat and light images, saving as masterflat.jpg and biassubtractedlight.jpg - we have our master dark and master flat frames and a bias subtracted light frame. The bias is of course the master bias and the only frame that does not require calibration in this instance.
Now, I have used different names for each image, because that’s what I was using when I created the screen shots for this tutorial. Still adhering to a naming convention that I understand, however, the names suggested above more accurately represent the state of calibration of the dark, flat and light frames.
For an imaging run of several hours, we might take 40 or 50 bias frames, 30 or 40 dark frames and 20 or 30 flat frames and combine the bias frames to create a master bias, and subtract it from the dark, flat and light frames, as we have done here. We may even shoot the flat frames at a lower ISO and require a separate set of bias frames with which to calibrate - naming conventions and ordering our folder structure is very important for smooth execution of the calibration and processing task.
Applying the calibration frames
Let’s keep in mind that the way in which we are approaching this task is slightly different to a sophisticated program such as Pixinsight. But not too different. The principles are essentially the same - we are working with what we have.
With GIMP on the desktop, File > Open as Layers’ the biassubtractedlight.jpg, the masterdark.jpg and the masterflat.jpeg. The biassubtracted light is set as the bottom image, next is the masterdark with Mode set to Subtract. The top image is the masterflat with Mode set to Divide. The result is shown below.
What have we done? Indeed, what have we done? Well, we have calibrated all the images by subtracting the master bias from each dark, flat and light frame and then subtracted the dark from the light frame, dividing the result by the flat frame.
Now! If we had a stack of light images, we would do the same for each and combine them to reduce the ambient noise. Effectively, we have increased the SNR. Take a look at the frame below. There are two very ugly blue (cold/dead pixels). My camera sensor has several of these, as well as bright red hot pixels (always on).
Voila! No blue pixel - it was definitely noise. After applying the master dark the image is looking better. The thermal, reddish appearance is diminished too.
One additional step will improve the result and get rid of that brown sky. If we normalize the masterflat we set the pixel values to upper and lower limits providing ourselves with some colour calibration (This can be done in situ by deselecting the ‘eye’ for the light and dark frames, leaving the flat as the active image. Then select Color > Auto > Normalize. The master flat can be normalized beforehand if desired. Don’t forget to re select the eyes for the light and dark frames.
The result
While originally a single frame, of only 10 seconds, the appearance is greatly improved. Contrast, brightness, smoothness and colour balance, particularly the sky, is a better representation of that captured by the camera sensor, which is much more sensitive than the human eye. Compare the 3 light images at each stage of processing and notice the steady improvement. Now it needs to be cropped… as you please.
A word on combining (stacking) images in GIMP
The composition of the example image does not lend itself to automatic alignment, even though there is a GIMP astrophtography package that has a stacking tool, among other things. Still, it is possible to stack images manually in GIMP. For calibration frames it’s very easy.
For example, if we did take several bias, dark and flat frames, File > Open as Layers, all the bias images and apply the Average script downloadable from the GIMP repository. Flatten and save as masterbias. Do the same with the darks and flats (now we’re getting into the jargon).
It’s a little different with light images because, the stars will have moved between exposures (this is actually a good thing for noise reduction - and similar to dithering). Part 2 covers stacking and alignment, noise reduction and basic image enhancement.