Academic Company Events NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Document Type: Tutorial
NI Supported: Yes
Publish Date: Sep 6, 2006


Feedback


Yes No

Related Categories

Related Links - Developer Zone

Related Links - Products and Services

Counting Particles or Cells Using IMAQ Vision

42 ratings | 4.55 out of 5
Print

Overview

To count objects, you use a common image processing technique called particle analysis, often referred to as blob analysis. Blob analysis is the process of detecting and analyzing distinct two-dimensional shapes within a region of the image. Blob analysis can provide your application with information about the presence or absence, number, location, shape, area, perimeter, and orientation of blobs within an image. In machine vision applications, blob analysis is used for applications such as detecting the presence of flaws on silicon wafers, finding the orientation of an integrated circuit on a plug-in board, and locating objects in motion control applications when there is significant variance in part shape and orientation. Overall, National Instruments IMAQ Vision software can measure more than 49 different parameters of a blob. This document introduces you to blob analysis and shows you how to use IMAQ Vision software to count components, particles, or cells in an image.

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:
  1. Acquiring the image
  2. Histographing to identify the threshold values
  3. Thresholding to create a binary image
  4. Filtering to remove noise and particles on the border of the image
  5. Particle (blob) analysis to count cells

    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.
See Also:
Choosing a Camera
Choosing an Acquisition Mode

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.
See Also:
Performing a Histogram
Reading and Writing Image Files

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.
See Also:
Thresholding an Image

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.
See Also:
Isolating Objects via Particle Filtering

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.
ParameterDescription
0Area (pixels)Surface area of particle in pixels
1Area (calibrated)Surface area of particle in user units
2Number of holesNumber of holes
3Hole's AreaSurface area of the holes in user units
4Total AreaTotal surface area (holes and particles) in user units
5Scanned AreaSurface area of the entire image in user units
6Ratio: Area/Scanned Area %Percentage of the surface area of a particle in relation to the scanned area
7Ratio: Area/Total Area %Percentage of the surface area of a particle in relation to the total area
8Center of mass (X)X coordinate of the center of gravity
9Center of mass (Y)Y coordinate of the center of gravity
10Left column (X)Left X coordinate of bounding rectangle
11Upper row (Y)Top Y coordinate of bounding rectangle
12Right column (X)Right hand X coordinate of bounding rectangle
13Lower row (Y)Bottom Y coordinate of bounding rectangle
14WidthWidth of bounding rectangle in user units
15HeightHeight of bounding rectangle in user units
16Longest segment lengthLength of longest horizontal line segment
17Longest segment left column (X)Leftmost X coordinate of longest horizontal line segment
18Longest segment row (Y)Y coordinate of longest horizontal line segment
19PerimeterLength of outer contour of particle in user units
20Hole's PerimeterPerimeter of all holes in user units
21SumXSum of the X-axis for each pixel of the particle
22SumYSum of the Y-axis for each pixel of the particle
23SumXX(Sum of the X-axis)2, for each pixel of the particle
24SumYY(Sum of the Y-axis)2, for each pixel of the particle
25SumXYSum of the X-axis and Y-axis for each pixel of the particle
26Corrected projection XProjection corrected in x
27Corrected projection YProjection corrected in y
28Moment of inertia IxxInertia matrix coefficient in xx
29Moment of inertia IyyInertia matrix coefficient in yy
30Moment of inertia IxyInertia matrix coefficient in xy
31Mean chord XMean length of horizontal segments
32Mean chord YMean length of vertical segments
33Max interceptLength of longest segment
34Mean intercept perpendicularMean length of the chords in an object perpendicular to its max intercept
35Particle orientationDirection of the longest segment
36Equivalent ellipse minor axisTotal length of the axis of the ellipse having the same area as the particle and a major axis equal to half the max intercept
37Ellipse major axisTotal length of major axis having the same area and perimeter as the particle in user units
38Ellipse minor axisTotal length of minor axis having the same area and perimeter as the particle in user units
39Ratio of equivalent ellipse axisFraction of major axis to minor axis
40Rectangle big sideLength of the large side of a rectangle having the same area and perimeter as the particle in user units
41Rectangle small sideLength of the small side of a rectangle having the same area and perimeter as the particle in user units
42Ratio of equivalent rectangle sidesRatio of large side to small side of a rectangle
43Elongation factorMax intercept/mean perpendicular intercept
44Compactness factorParticle area (length x width)
45Heywood circularity factorParticle perimeter/perimeter of circle having same area as particle
46Type factorA complex factor relating the surface area to the moment of inertia
47Hydraulic radiusParticle area/particle perimeter
48Waddel disk diameterDiameter of the disk having the same area as the particle in user units
49DiagonalDiagonal of an equivalent rectangle in user units
See Also:
Performing a Particle Analysis

Conclusion


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.
42 ratings | 4.55 out of 5
Print

Reader Comments | Submit a comment »

The "Compactness Factor" calculation listed on this page is incorrect - it should be the ratio of a particle area to the area of the smallest rectangle containing the particle: particle area/(breadth*width) The compactness factor belongs to the interval [0, 1]. The closer the shape of a particle is to a rectangle, the closer to 1 the compactness factor.
- Nov 9, 2006

 

Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).