Making Flats to Calibrate Images
One of the first things I discovered in digital imaging is that CCDs or CMOS chips are susceptible to dust in the optical train, particularly near the sensor. In addition, the optical train itself may cause uneven illumination of the sensor resulting in ‘vignetting’ around the frame or ‘hot spots’ in the center. All of these imperfections can be easily removed from digital images by careful application of flat frames. Here’s an example of what I mean by a flat, and I will describe this image in more detail.

Flat Example
This type of flat image is made by placing an evenly illuminated diffuser over the aperture of the telescope. The diffuser can be a light box or as simple as a white T-shirt stretched over the telescope. Flats can also be made by pointing the telescope at an evenly illuminated surface such as a large piece of foam core board. The illumination does not need to be bright but should allow the flat image to be made easily.This allows multiple flats to be taken and averaged to produce a ‘Master Flat’. I adjust the exposure of my CCD camera so that the detector is about half saturated within a few seconds. I use a histogram display to make this adjustment. For a 16-bit, unbinned image the ADU count should be around 32000 (approximately half of 65535). Here is the histogram for the example flat; you can see that most of the pixels are centered in the middle of the display (from about 33000 to 39000 ADU):

If you look at the Flat Example image you will see small donut-shape dark objects; these are dust motes that sit in the optical train. These ‘dust donuts’ (as they are called) are quite small, indicating that they are close to the CCD chip. Dust particles farther from the chip produce larger and fainter donuts. Dust particles far from the detector (on the objective or primary mirror) do not come into focus and do not require correction. However, you should notice from the example that the right edge of the frame is significantly darker than the left edge. This probably represents some misalignment in the optics-camera interface so that the illumination of the chip is uneven. If this uneven illumination is not corrected it will show up in each CCD image that is made.
So how does a flat frame magically correct these ‘defects’ that show up in raw images? Here’s an example of a simple detector:

This diagram represents a detector (CCD chip) that consists of just four pixels. Light striking the pixels creates a signal indicated by the number. The top row shows a ‘light’ frame read from the chip; the second pixel records the light from a bright star while the other pixels record the background sky. Notice that the far right pixel reads a much lower value than the other pixels recording the sky; this is caused by vignetting in the optics. It could just as easily be caused by a dust mote sitting above that pixel in the optics. The next row shows a flat frame made by exposing the chip to an evenly illuminated source through the same optical train used for the light frame. Again the pixel on the far right records less light because of vignetting. The mathematical mean of the light reaching all of the pixels is 14. In order to flat field the light frame each pixel in the light frame is DIVIDED by the corresponding pixel value in the flat field frame. Then the result of this division is multiplied by the mean value from the flat. This simple math is illustrated at the bottom. A new frame is then created in which the four pixels contain the values at the bottom. Notice that the background sky values are now all identical and the proportional difference between the pixel recording the star and the sky background is preserved (8:1). In practice the values recorded for flats are typically much larger than the light frame, and the mean value is usually very close the largest value, so that very little attenuation of the original signal occurs during flat fielding. Flats are usually applied after dark subtraction (more on that later).
Gregg Ruppel