| Customize Help

Removing uneven lighting from grabbed images



The quality of processing results can be degraded if the source images have been taken under non-uniform lighting. Non-uniform lighting can be caused by many different scenarios. It is detectable by taking a line profile (for example, along the diagonal) in an image of a uniform gray object in the imaging setup. To remove uneven lighting, you can use MimFlatField().

To use MimFlatField(), you must set up a flat-field image processing context, using MimControl(). The flat-field image processing context must contain a flat image, a gain constant, and optionally two dark images. MimFlatField() applies the flat-field image processing context to the source image using the following modified formula.

The flat image provides an example of the uneven lighting without any objects in the foreground, while the gain constant is required to normalize (or scale) the result, typically back to the full dynamic range of the destination image. Note that the gain factor can be automatically generated using M_GAIN_CONST set to M_AUTOMATIC. In this case, the gain factor is calculated based on the average of the denominator (that is, Avg(AvgFlatImg - AvgDarkImg02)).

The two dark images can be replaced by constants (for example, to remove these two images, replace them with a zero in the calculation).

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

Note that you can also use MimFlatField() to remove CCD artifacts from grabbed images. For more information, refer to the Removing CCD artifacts from grabbed images section of Chapter 5: Specialized image processing.

How to remove non-uniform lighting from grabbed images

Perform the following steps to remove non-uniform lighting from your grabbed images:

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

  2. If necessary, using the same exposure time as was used for the source image, grab multiple images taken with the lens cap placed on the lens. Average the grabbed images by performing a mean operation (using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE). Add this image to the flat-field image processing context, using MimControl() with M_DARK_IMAGE. This averaged image will be used as AvgDarkImg01 for the calculation.

    Note that, in most cases, if you provide an offset image (AvgDarkImg02), you should provide a dark image (AvgDarkImg01).

    If a dark image is not necessary, set MimControl() with M_DARK_CONST to 0.

  3. Using an exposure time set so that no pixel is saturated, grab multiple images of the same area as in your source image, except place a uniform gray object in the field of view (such as, grabbing an image of a blank gray piece of paper). Average the grabbed images by performing a mean operation (using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE). Add this image to the flat-field image processing context, using MimControl() with M_FLAT_IMAGE. This averaged image will be used as AvgFlatImg for the calculation.

  4. If necessary, using the same exposure time as for the flat image, grab multiple images taken with the lens cap placed on the lens. Average the grabbed images by performing a mean operation (using MimStatCalculate() when MimControl() with M_STAT_MEAN is set to M_ENABLE). Add this image to the flat-field image processing context, using MimControl() with M_OFFSET_IMAGE. This averaged image will be used as AvgDarkImg02 for the calculation.

    Note that, in most cases, if you provide a dark image (AvgDarkImg01), you should provide an offset image (AvgDarkImg02).

    If a dark image is not necessary, set MimControl() with M_OFFSET_CONST to 0.

  5. Specify the gain factor to apply, using MimControl() with M_GAIN_CONST. To automatically calculate an appropriate gain factor to scale the results, typically back to the full dynamic range of the destination image, use M_GAIN_CONST set to M_AUTOMATIC. Alternatively, you can set M_GAIN_CONST to any value greater than 0.

    The automatically calculated gain factor might not always result in the best gain factor to use for your image; this is typically because the range of pixel values in the AvgFlatImg image is too great. In this case, inquire the automatically calculated gain factor, using MimInquire() with M_EFFECTIVE_GAIN_CONST. If darkening light pixels (removing saturation) from the image, set M_GAIN_CONST to a value lower than the automatically calculated gain factor. Whereas, if lightening dark pixels, set M_GAIN_CONST to a value higher than the automatically calculated gain factor.

  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.

  7. Call MimFlatField() with the configured flat-field image processing context and your source image. The non-uniform lighting in the image should be improved. Note that you might have to perform the operation several times before determining the best value for the gain.