| Customize Help

Removing CCD artifacts from grabbed images



The quality of grabbed images can be affected by electrical bias, thermal agitation, and artifacts generated by a sensitive CCD. These variations can reduce the quality of your grabbed images and cause further errors in processing. These artifacts can appear in a variety of forms, such as: a graininess in the darker areas of your image, faint horizontal or vertical lines, blotchy gradients between darker and lighter areas in your image, or even a gradient from dark to light across the entire image. Such artifacts are especially troubling in low-contrast images. One way to clean the grabbed images of these artifacts is to use MimFlatField(). This function uses a flat-field image processing context to store processing settings.

You must set up the flat-field image processing context with information about the gain, thermal agitation, CCD sensitivity variations, and electrical bias, using MimControl(). You can specify each of these on a pixel-by-pixel basis using an image or, on a global level, using a constant.

The flat-field image processing context is applied to the source image using the following formula.

As an example of using images, this formula combines the various images of the image processing context in the following way:

If you must omit one or more operands from the above formula, set the operand to a constant of either 0 or 1, depending on the operand.

Note that you can also use MimFlatField() to remove non-uniform lighting from grabbed images. For more information, refer to the Removing uneven lighting from grabbed images section of Chapter 3: Fundamental image processing.

How to perform a flat-field correction

Before calling MimFlatField(), you must first set up the flat-field image processing context by performing the following:

  1. Allocate a flat-field image processing context, using MimAlloc() with M_FLAT_FIELD_CONTEXT.

  2. Specify the amount of electrical bias variations to remove, using MimControl() with either M_OFFSET_CONST or M_OFFSET_IMAGE.

  3. Specify the amount of thermal agitation to remove, using MimControl() with either M_DARK_CONST or M_DARK_IMAGE.

  4. Specify the amount of CCD sensitivity variations to remove, using MimControl() with either M_FLAT_CONST or M_FLAT_IMAGE.

  5. Specify the gain factor to scale the result, typically back to the full dynamic range of the destination image, using MimControl() with M_GAIN_CONST.

  6. Preprocess the context by calling MimFlatField() with M_PREPROCESS. Both the source and/or destination image buffers can be set to M_NULL. If, however, the source or destination image is provided, it should be a typical source or destination image, respectively, and it will be used in the preprocess operation, to better optimize future calls. If the preprocess operation is not done explicitly, it will be done when MimFlatField() is first called.

Electrical bias (offset image or constant)

Electrical bias is a level of electronic noise generated by the CCD and transferred into the grabbed image. The amount of electrical bias can differ greatly between cameras. An example of an image affected by electrical bias should resemble the following:

To verify whether your image suffers from electrical bias, grab an image of a uniformly dark area (such as, grabbing with the camera's lens cap firmly in place), using a very short exposure time (compared to the standard exposure time for your application). This is referred to as an offset image. To produce a more accurate offset image, multiple offset images should be taken, and then averaged (for example, using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE).

Each pixel of the offset image might be slightly different from the expected black value (by a small random value) and this will change from image to image; this is the electronic noise of the camera. The electrical bias will show a number of electronic problems in the camera, including: excessive noise and pattern noise.

To remove the electrical bias from your image, create an offset image, as described above, and set MimControl() with M_OFFSET_IMAGE to this image. Alternatively, if you do not have an offset image or prefer to use the same value for all pixels, you can use a number instead of an image using MimControl() with M_OFFSET_CONST.

Thermal agitation (dark image or constant)

Thermal agitation is a level of electronic noise generated by the CCD when the free electrons in a conductor move randomly. The electronic noise is transferred into the grabbed image. The amount of thermal agitation in a grabbed image can increase as both the exposure time is increased and the CCD grows hotter. An example of an image affected by thermal agitation should resemble the following:

To verify whether your image suffers from thermal agitation, grab an image of a uniformly dark area (such as, grabbing with the camera's lens cap firmly in place), using an exposure time that is standard for your application. This is referred to as a dark image. To produce a more accurate dark image, multiple dark images should be taken, and then averaged (for example, using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE).

Dark images are a map of pixels that have a source other than light. Normally, light falls on the CCD and interacts with the silicon to free up electrons. These electrons are then moved out of the CCD and counted by the A/D converter. Besides light, there are several ways electrons can leak into the pixel without light. The dominant source of these electrons is dark current, but issues like spurious charge and residual charge can also give the pixel extra electrons.

To remove the thermal agitation from your image, create a dark image, as described above, and set MimControl() with M_DARK_IMAGE to this image. Alternatively, if you do not have a dark image or prefer to use the same value for all pixels, you can use a number instead of an image using MimControl() with M_DARK_CONST.

CCD sensitivity (flat image or constant)

CCD sensitivity is a level of distortion exhibited by the CCD when the center of the grabbed image is more in focus (brighter, less saturated) than its outer edges, or when streaks appear from a brighter area to a nearby darker area. The distortion is transferred into the grabbed image. An example of an image affected by CCD sensitivity should resemble the following:

To verify whether your image suffers from CCD sensitivity, grab an image of a uniform light gray area (such as, grabbing an image of a blank piece of paper), using a very short exposure time (compared to the standard exposure time for your application). This is referred to as a flat image. To produce a more accurate flat image, multiple flat images should be taken, and then averaged (for example, using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE).

A flat image shows a variety of camera electronic problems, shutter problems, as well as CCD defects. Note that dust on the lens will not show up well in the flat image, but dust on the CCD or CCD defects will be very visible.

To remove CCD sensitivity from your image, create a flat image, as described above, and set MimControl() with M_FLAT_IMAGE to this image. Alternatively, if you do not have a flat image or prefer to use the same value for all pixels, you can use a number instead of an image using MimControl() with M_FLAT_CONST.

Gain

Specifying a gain allows you to normalize (or scale) the results of the flat-field calculation, typically back to the full dynamic range of the destination image. You can only specify the gain as a single value. To establish a good gain, analyze the histogram of a grabbed image with linear luminosity.

If you are uncertain as to the gain factor that would result in the best results, let MIL automatically generate the gain factor (MimControl() with M_GAIN_CONST set to M_AUTOMATIC).

The automatically generated gain factor is determined by subtracting the offset image (M_OFFSET_IMAGE) from the flat image (M_FLAT_IMAGE) and then taking the average of the resulting image's pixels. If constant values are specified instead of images (by using M_FLAT_CONST and M_OFFSET_CONST), MIL returns the result of the subtraction instead.