1. Blob Analysis and Counting Objects Overview
A simple definition of a blob is a group of connected pixels. In general, blobs are thought of as group of contiguous pixels that have the same intensity. Image processing operates on these blobs to calculate the area, perimeter, or to count the number of distinguishable blobs. Before you can apply blob analysis you must preprocess the image by converting a gray scale image (an image with 256 levels) to an image with only two gray scales – zeros and ones. The objective is to separate the important objects, blobs, from the unimportant information, background. A technique called thresholding appropriately separates the blobs from the background. The result of the thresholding process is a binary image which is an image of pixel values of only ones and zeros. The blobs are represented by the connected pixels of ones, and the background is represented by the zeros. By binarizing the image into ones and zeros, the task of writing image processing algorithms for blob analysis is made easier. For example, to find the area of a blob, you simply need to count the pixels with values of one that are connected. Another benefit of binarizing the image for blob analysis is that the blob analysis calculations are fast. This application note will introduce blob analysis with a simple cell counting application. Realize that blob analysis is used not only in biomedical imaging applications, but also in industrial inspection applications for counting components and calculating the locations of objects. Each of the IMAQ Vision image processing steps is discussed – acquiring the image, preprocessing, and then blob analysis.
Here are the steps for counting objects using IMAQ Vision:
- Acquiring the image
- Histographing to identify the threshold values
- Thresholding to create a binary image
- Filtering to remove noise and particles on the border of the image
- Particle (blob) analysis to count cells
2. Step 1 -- Acquiring the Image
You can use a National Instruments IMAQ 1408 board to acquire images from standard and nonstandard analog cameras and microscopes. You can easily configure the board for acquisition using a point-and-click user interface. The configuration software saves the settings for the board to a configuration file, which is then used by the NI-IMAQ driver software in the development environment to simplify acquisition of images.
Configuring Your Camera or Microscope
For most particle or cell counting applications it is easier to configure and acquire images from a camera that uses standard video. Many cameras use popular analog video standards that include the VSYNC and HSYNC timing information as well as an image size. The standard video formats are EIA RS-170 and CCIR for monochrome video, and National Television Systems Committee (NTSC) and Phase Alternate Line (PAL) for color video. For example, camcorders most often output color-composite video in NTSC or PAL formats, combining the luminance (brightness) and chrominance (color) components into a single analog signal. NTSC is used in the US and Asia, while PAL is popular in Europe. Overall, you can easily configure the IMAQ board for standard video using an interactive software utility that is shipped with the board, the NI-IMAQ Configuration Utility. You can use this utility to set up the IMAQ hardware to acquire gray scale images from a color video signal (NTSC or PAL). In hardware, an antichrominance filter is applied to remove the color information. By selecting this filter, the incoming color video is translated to an 8-bit gray scale signal.
Some devices, such as microscopes, may output the analog video signal and the synchronization signals, such as VSYNC and HSYNC, on separate lines. Using the IMAQ hardware and the IMAQ-2514 cabling option, you can input each of these separate signals (PCLK, HSYNC, VSYNC) and composite SYNC (CSYNC) inputs to the IMAQ-2514 cable assembly. Plus, the IMAQ-2514 provides connections to all video sources (Video 0, 1, 2, 3, single-ended or differential), the external digital I/O lines and triggers, and external sync lines.
3. Step 2 -- Histographing to Identify the Threshold Values
In the image shown in Figure 1, some cells have been chemically stained, or tagged, to make them easier to count. The stained cells have a higher contrast from the background and the other cells. This is a common technique used in cell counting applications. In factory automation or component counting applications, you can adjust the lighting to get the maximum contrast between the background and the particles you wish to count.
Figure 1. Stained Cells.
Figure 2. Histograph of Cell Image.
A histograph of an image gives the frequency (count) of the number of pixels per gray level value. It provides a general description of the appearance of an image and helps identify its various components, such as the background, blobs, and noise. Figure 2 is an 8-bit image with 256 gray scales. The black background is the spike at 0 and the white-stained cells are the gray scale values above 110. For this application, the gray scale values above 110 are the pixels we are interested in processing.
The LabVIEW diagram in Figure 3 loads an image from file, then a histograph function is applied to the image. The histograph function is used to determine the upper and lower gray scale threshold limits.
Figure 3. LabVIEW Diagram for Loading the Cell Image from File, Displaying the Image, and Calculating the Histograph.
4. Step 3 -- Thresholding to Create a Binary Image
The diagram shown in Figure 4 has been modified to add the threshold function. The threshold function segments an image into two regions, an object region and a background region. In this process, all pixels that fall within the gray scale interval defined as the threshold interval are given the value one. All other pixels in the image are set to zero. In this cell counting example, all pixels above gray scale value 110 are set to a value of one, and all pixels below 110 are set to zero.
The result is a binary image – an image with zero and one values. Binary images contain only the important information, and often can be processed very rapidly. Generally, algorithms to process binary images are faster than algorithms for gray scale images.
Figure 4. LabVIEW Diagram for Calculating the Threshold and Displaying a Binary Image.
Several new functions are used in Figure 4. The IMAQ Create function creates an image buffer for the image. Plus, a border size input has been added to the IMAQ Create function, which adds 3 pixels around the perimeter of the image. This border is necessary because many image processing functions use several adjacent pixels to process the image. Adding pixels around the image ensures that calculations on the outermost pixels in the original image can be used in processing the image. The IMAQ Threshold function calculates the threshold, and the IMAQ GetPalette function sets up the display window to display a binary image. A window number constant has been added to the IMAQ Wind-Draw function to identify the raw and binary images. The range input controls the upper and lower threshold values. The result of this diagram is the binary image shown in Figure 5. The white pixels are "one" values and the black pixels are "zero" values.
Figure 5. Binary Image of Cells.
Thresholding an Image
5. Step 4 -- Filtering to Remove Noise and Particles on the Border of the Image
The section of code in Figure 6 operates on the binary image. The IMAQ RemoveParticle function filters or removes the particles below a certain pixel size. The IMAQ RejectBorder function removes the particles on the border of the image, which is a common technique, because you cannot accurately determine the size of particles on the border of an image.
Figure 6. LabVIEW Diagram to Filter Noise and Remove Particles from the Border of an Image.
Figure 7. Cells after Thresholding and Filtering.
After the thresholding and filtering, as seen in Figure 7, only the cells or blobs of interest are left.
Isolating Objects via Particle Filtering
6. Step 5 -- Particle (Blob) Analysis to Count Cells
You can use the IMAQ Vision blob analysis function to analyze blobs in an image. You can count, label, and measure cells and objects. Calculate the area, perimeter, orientation, and location and 49 other parameters with blob analysis functions. Plus, to make counting easier, change the shape of blobs with morphology functions, and remove and filter blobs of certain size with spatial filters.
There are many blob calculations such as area, perimeter, moment of inertia, orientation, mean chord, width, height, ellipse axis, elongation factor, circularity factor, type factor, projection, location, bounding rectangle, and many more.
IMAQ Vision includes many different functions for manipulating particles or blobs. For example, if two cells are overlapping, you can use the erode function to remove the pixels from the perimeter of the particles until there are two distinct particles. Once the particles are separated, they can be counted. Use morphology functions to erode, dilate, fill holes, convex (fill holes on the edges), reject objects on the border, and separate blobs.
Figure 8. The IMAQ BasicParticle function calculates the area of each blob.
The processed binary image is then passed to the IMAQ BasicParticle function (shown in Figure 8). The Basic Reports output returns the area of each blob in pixels. There are five cells in Figure 7 with sizes of 189, 379, 374, 374, and 374 pixels. Plus, the IMAQ BasicParticle function returns the upper left and lower right pixel coordinates of a rectangle around each blob.
For more complex measurements, you can use the IMAQ ComplexParticle function (shown in Figure 9). This function calculates up to 49 different parameters for each blob. You can use each of these parameters in inspection and counting applications to uniquely quantify parts or particles. For example, you can use the perimeter, area, and center of mass calculations to quantify the difference between particles. Use more parameters for finer quantification.
Figure 9. The IMAQ ComplexParticle function calculates up to 49 parameters for each blob.
Table 1. IMAQ ComplexParticle Function Output.
|0||Area (pixels)||Surface area of particle in pixels|
|1||Area (calibrated)||Surface area of particle in user units|
|2||Number of holes||Number of holes|
|3||Hole's Area||Surface area of the holes in user units|
|4||Total Area||Total surface area (holes and particles) in user units|
|5||Scanned Area||Surface area of the entire image in user units|
|6||Ratio: Area/Scanned Area %||Percentage of the surface area of a particle in relation to the scanned area|
|7||Ratio: Area/Total Area %||Percentage of the surface area of a particle in relation to the total area|
|8||Center of mass (X)||X coordinate of the center of gravity|
|9||Center of mass (Y)||Y coordinate of the center of gravity|
|10||Left column (X)||Left X coordinate of bounding rectangle|
|11||Upper row (Y)||Top Y coordinate of bounding rectangle|
|12||Right column (X)||Right hand X coordinate of bounding rectangle|
|13||Lower row (Y)||Bottom Y coordinate of bounding rectangle|
|14||Width||Width of bounding rectangle in user units|
|15||Height||Height of bounding rectangle in user units|
|16||Longest segment length||Length of longest horizontal line segment|
|17||Longest segment left column (X)||Leftmost X coordinate of longest horizontal line segment|
|18||Longest segment row (Y)||Y coordinate of longest horizontal line segment|
|19||Perimeter||Length of outer contour of particle in user units|
|20||Hole's Perimeter||Perimeter of all holes in user units|
|21||SumX||Sum of the X-axis for each pixel of the particle|
|22||SumY||Sum of the Y-axis for each pixel of the particle|
|23||SumXX||(Sum of the X-axis)2, for each pixel of the particle|
|24||SumYY||(Sum of the Y-axis)2, for each pixel of the particle|
|25||SumXY||Sum of the X-axis and Y-axis for each pixel of the particle|
|26||Corrected projection X||Projection corrected in x|
|27||Corrected projection Y||Projection corrected in y|
|28||Moment of inertia Ixx||Inertia matrix coefficient in xx|
|29||Moment of inertia Iyy||Inertia matrix coefficient in yy|
|30||Moment of inertia Ixy||Inertia matrix coefficient in xy|
|31||Mean chord X||Mean length of horizontal segments|
|32||Mean chord Y||Mean length of vertical segments|
|33||Max intercept||Length of longest segment|
|34||Mean intercept perpendicular||Mean length of the chords in an object perpendicular to its max intercept|
|35||Particle orientation||Direction of the longest segment|
|36||Equivalent ellipse minor axis||Total length of the axis of the ellipse having the same area as the particle and a major axis equal to half the max intercept|
|37||Ellipse major axis||Total length of major axis having the same area and perimeter as the particle in user units|
|38||Ellipse minor axis||Total length of minor axis having the same area and perimeter as the particle in user units|
|39||Ratio of equivalent ellipse axis||Fraction of major axis to minor axis|
|40||Rectangle big side||Length of the large side of a rectangle having the same area and perimeter as the particle in user units|
|41||Rectangle small side||Length of the small side of a rectangle having the same area and perimeter as the particle in user units|
|42||Ratio of equivalent rectangle sides||Ratio of large side to small side of a rectangle|
|43||Elongation factor||Max intercept/mean perpendicular intercept|
|44||Compactness factor||Particle area (length x width)|
|45||Heywood circularity factor||Particle perimeter/perimeter of circle having same area as particle|
|46||Type factor||A complex factor relating the surface area to the moment of inertia|
|47||Hydraulic radius||Particle area/particle perimeter|
|48||Waddel disk diameter||Diameter of the disk having the same area as the particle in user units|
|49||Diagonal||Diagonal of an equivalent rectangle in user units|
Performing a Particle Analysis
With just a few IMAQ Vision functions you can easily count particles or cells and find their area. IMAQ Vision is flexible and fast for both laboratory and factory automation applications. For advanced inspection applications you can use multiple parameters to accurately quantify the difference between the particles or cells you are inspecting. Although this note presents graphical examples of IMAQ Vision functions for LabVIEW and BridgeVIEW, IMAQ Vision also contains the identical functions in C for LabWindows/CVI programmers and ActiveX Controls for ComponentWorks programmers.