Improve an Image

NI Vision for LabVIEW Basics

Improve an Image

Using the information you gathered from analyzing your image, you may want to improve the quality of your image for inspection. You can improve your image with lookup tables, filters, grayscale morphology, and Fast Fourier transforms.

Lookup Tables

Apply lookup table (LUT) transformations to highlight image details in areas containing significant information at the expense of other areas. A LUT transformation converts input grayscale values in the source image into other grayscale values in the transformed image. NI Vision provides four VIs that directly or indirectly apply lookup tables to images:

  • IMAQ MathLookup—Converts the pixel values of an image by replacing them with values from a predefined lookup table. NI Vision has seven predefined lookup tables based on mathematical transformations. Refer to Chapter 5, Image Processing, of the NI Vision Concepts Manual for more information about these lookup tables.
  • IMAQ UserLookup—Converts the pixel values of an image by replacing them with values from a user-defined lookup table.
  • IMAQ Equalize—Distributes the grayscale values evenly within a given grayscale range. Use IMAQ Equalize to increase the contrast in images containing few grayscale values.
  • IMAQ Inverse—Inverts the pixel intensities of an image to compute the negative of the image. For example, use IMAQ Inverse before applying an automatic threshold to your image if the background pixels are brighter than the object pixels.

Filters

Filter your image when you need to improve the sharpness of transitions in the image or increase the overall signal-to-noise ratio of the image. You can choose either a lowpass or highpass filter depending on your needs.

Lowpass filters remove insignificant details by smoothing the image, removing sharp details, and smoothing the edges between the objects and the background. You can use the IMAQ LowPass VI or define your own lowpass filter using the IMAQ Convolute or IMAQ NthOrder VI.

Highpass filters emphasize details, such as edges, object boundaries, or cracks. These details represent sharp transitions in intensity value. You can define your own highpass filter using the IMAQ Convolute or IMAQ NthOrder VI or use the IMAQ EdgeDetection or IMAQ CannyEdgeDetection VI. IMAQ EdgeDetection allows you to find edges in an image using predefined edge detection kernels, such as the Sobel, Prewitt, and Roberts kernels.

Convolution Filter

The IMAQ Convolute VI allows you to use a predefined set of lowpass and highpass filters. Each filter is defined by a kernel of coefficients. Use the IMAQ GetKernel VI to retrieve predefined kernels. If the predefined kernels do not meet your needs, define your own custom filter using a LabVIEW 2D array of floating point numbers.

Nth Order Filter

IMAQ NthOrder allows you to define a lowpass or highpass filter depending on the value of N that you choose. One specific Nth order filter, the median filter, removes speckle noise, which appears as small black and white dots. Refer to Chapter 5, Image Processing, of the NI Vision Concepts Manual for more information about Nth order filters.

Grayscale Morphology

Perform grayscale morphology when you want to filter grayscale features of an image. Grayscale morphology helps you remove or enhance isolated features, such as bright pixels on a dark background. Use these transformations on a grayscale image to enhance non-distinct features before thresholding the image in preparation for particle analysis.

Grayscale morphological transformations compare a pixel to those pixels surrounding it. The transformation keeps the smallest pixel values when performing an erosion or keeps the largest pixel values when performing a dilation.

Refer to Chapter 5, Image Processing, of the NI Vision Concepts Manual for more information about grayscale morphology transformations.

Use the IMAQ GrayMorphology VI to perform one of the following seven transformations:

  • Erosion—Reduces the brightness of pixels that are surrounded by neighbors with a lower intensity. Define the neighborhood with a structuring element. Refer to Chapter 9, Binary Morphology, of the NI Vision Concepts Manual for more information about structuring elements.
  • Dilation—Increases the brightness of pixels surrounded by neighbors with a higher intensity. A dilation has the opposite effect of an erosion.
  • Opening—Removes bright pixels isolated in dark regions and smooths boundaries.
  • Closing—Removes dark spots isolated in bright regions and smooths boundaries.
  • Proper-opening—Removes bright pixels isolated in dark regions and smooths the boundaries of regions.
  • Proper-closing—Removes dark pixels isolated in bright regions and smooths the boundaries of regions.
  • Auto-median—Generates simpler particles that have fewer details.

Fast Fourier Transforms

Use Fast Fourier Transforms (FFT) to convert an image into its frequency domain. In an image, details and sharp edges are associated with mid to high spatial frequencies because they introduce significant gray-level variations over short distances. Gradually varying patterns are associated with low spatial frequencies.

An image can have extraneous noise, such as periodic stripes, introduced during the digitization process. In the frequency domain, the periodic pattern is reduced to a limited set of high spatial frequencies. Also, the imaging setup may produce non-uniform lighting of the field of view, which produces an image with a light drift superimposed on the information you want to analyze. In the frequency domain, the light drift appears as a limited set of low frequencies around the average intensity of the image, called the DC component.

You can use algorithms working in the frequency domain to isolate and remove these unwanted frequencies from your image. Complete the following steps to obtain an image in which the unwanted pattern has disappeared but the overall features remain.

  1. Use the IMAQ FFT VI to convert an image from the spatial domain to the frequency domain. This VI computes the FFT of the image and results in a complex image representing the frequency information of your image.
  2. Improve your image in the frequency domain with a lowpass or highpass frequency filter. Specify which type of filter to use with the IMAQ ComplexAttenuate VI or the IMAQ ComplexTruncate VI. Lowpass filters smooth noise, details, textures, and sharp edges in an image. Highpass filters emphasize details, textures, and sharp edges in images, but they also emphasize noise.
    • Lowpass attenuation—The amount of attenuation is directly proportional to the frequency information. At low frequencies, there is little attenuation. As the frequencies increase, the attenuation increases. This operation preserves all of the zero frequency information. Zero frequency information corresponds to the DC component of the image or the average intensity of the image in the spatial domain.
    • Highpass attenuation—The amount of attenuation is inversely proportional to the frequency information. At high frequencies, there is little attenuation. As the frequencies decrease, the attenuation increases. The zero frequency component is removed entirely.
    • Lowpass truncation—Frequency components above the ideal cutoff frequency are removed, and the frequencies below it remain unaltered.
    • Highpass truncation—Frequency components above the ideal cutoff frequency remain unaltered, and the frequencies below it are removed.
  3. To transform your image back to the spatial domain, use the IMAQ InverseFFT VI.

Advanced Operations

The IMAQ ImageToComplexPlane and IMAQ ComplexPlaneToImage VIs allow you to access, process, and update independently the magnitude, phase, real, and imaginary planes of a complex image. You also can convert a complex image to an array and back using the IMAQ ComplexImageToArray and IMAQ ArrayToComplexImage VIs.