National Instruments IMAQTM 用户手册

下载
页码 121
Chapter 3
Making Grayscale and Color Measurements
3-6
ni.com
CWIMAQRegion contains. When you know the type of shape that the 
region contains, you can set the region into a shape variable and use that 
variable to manipulate the shape properties. For example, the following 
code resizes a rectangle selected on the viewer:
Dim MyRectangle As CWIMAQRectangle
Set MyRectangle = CWIMAQViewer1.Regions(1)
MyRectangle.Width = 100
MyRectangle.Height = 100
You also can pass CWIMAQRegion objects to any IMAQ Vision method 
that takes a shape as a parameter. However, if the CWIMAQRegion does 
not contain the type of shape object that the method requires, a type 
mismatch error results.
Defining Regions with Masks
You can define regions to process with image masks. An image mask is 
an 8-bit image of the same size as or smaller than the image you want to 
process. Pixels in the mask image determine if the corresponding pixel 
in the source image needs to be processed. If a pixel in the image mask 
has a value other than 0, the corresponding pixel in the source image is 
processed. If a pixel in the image mask has a value of 0, the corresponding 
pixel in the source image is left unchanged.
You can use a mask to define particles in a grayscale image when you need 
to make intensity measurements on those particles. First, threshold the 
image to make a new binary image. For more information about binary 
images, refer to Chapter 4
. You can input the 
binary image or a labeled version of the binary image as a mask image to 
the intensity measurement method. If you want to make color comparisons, 
convert the binary image into a CWIMAQRegions collection using 
CWIMAQVision.MaskToRegions
.
Measure Grayscale Statistics
You can measure grayscale statistics in images using light meters or 
quantitative analysis methods. You can obtain the center of energy for an 
image with the centroid method.
Use 
CWMachineVision.LightMeterPoint
 to measure the 
light intensity at a point in the image. Use 
CWMachineVision.LightMeterLine
 to get the pixel value statistics 
along a line in the image, such as mean intensity, standard deviation,