Improve the Binary Image

NI Vision for LabVIEW Basics

Improve the Binary Image

After you threshold your image, you may want to improve the resulting binary image with binary morphological functions. You can use primary binary morphology or advanced binary morphology to remove unwanted particles, separate connected particles, or improve the shape of particles. Primary morphology functions work on the image as a whole by processing pixels individually. Advanced morphology operations are built upon the primary morphological operators and work on particles as a whole as opposed to individual pixels. Refer to Chapter 9, Binary Morphology, of the NI Vision Concepts Manual for lists of which morphology functions are primary and which are advanced.

The advanced morphology functions require that you specify the type of connectivity to use. Connectivity specifies how NI Vision determines if two adjacent pixels belong to the same particle. Use connectivity-4 when you want NI Vision to consider pixels to be part of the same particle only when the pixels touch along an adjacent edge. Use connectivity-8 when you want NI Vision to consider pixels to be part of the same particle even if the pixels touch only at a corner. Refer to Chapter 9, Binary Morphology, of the NI Vision Concepts Manual for more information about connectivity.

Note  Use the same type of connectivity throughout your application.

Removing Unwanted Particles

Use the IMAQ RejectBorder VI to remove particles that touch the border of the image. Reject particles on the border of the image when you suspect that the information about those particles is incomplete.

Use the IMAQ RemoveParticle VI to remove large or small particles that do not interest you. You also can use the Erode, Open, and POpen functions in the IMAQ Morphology VI to remove small particles. Unlike the IMAQ RemoveParticle VI, these three functions alter the size and shape of the remaining particles.

Use the hit-miss function of the IMAQ Morphology VI to locate particular configurations of pixels, which you define with a structuring element. Depending on the configuration of the structuring element, the hit-miss function can locate single isolated pixels, cross-shape or longitudinal patterns, right angles along the edges of particles, and other user-specified shapes. Refer to Chapter 9, Binary Morphology, of the NI Vision Concepts Manual for more information about structuring elements.

If you know enough about the shape features of the particles you want to keep or remove, use the IMAQ Particle Filter 2 VI to filter out particles that do not interest you.

Separating Touching Particles

Use watershed transform and binary morphology to separate touching particles in images.

Using Watershed Transform

Use the IMAQ Danielsson VI to transform the binary image into a grayscale distance map in which each particle pixel is assigned a gray-level value equal to its shortest Euclidean distance from the particle border. Apply the IMAQ Watershed Transform VI to the distance map to find the watershed separation lines. Use the IMAQ Mask VI to superimpose the watershed lines on the original image.

Refer to Chapter 8, Image Segmentation, of the NI Vision Concepts Manual for more information about segmenting images using a watershed transform.

Using Binary Morphology

Use the IMAQ Separation VI or apply an erosion or an open function with the IMAQ Morphology VI to separate touching objects. The IMAQ Separation VI is an advanced VI that separates particles without modifying their shapes. However, erosion and open operations alter the shape of all the particles.

Note  A separation is a time-intensive operation compared to an erosion, watershed transform, or open operation. Consider using one of the methods other than separation if speed is an issue in your application.

Improving Particle Shapes

Use the IMAQ FillHole VI to fill holes in the particles. Use the IMAQ Morphology VI to perform a variety of operations on the particles. You can use the Open, Close, POpen, PClose, and AutoM operations to smooth the boundaries of the particles. Open and POpen smooth the boundaries of the particle by removing small isthmuses while Close widens the isthmuses. Close and PClose fill small holes in the particle. AutoM removes isthmuses and fills holes. Refer to Chapter 9, Binary Morphology, of the NI Vision Concepts Manual for more information about these operations.