background image

Chapter 3

Making Grayscale and Color Measurements

IMAQ Vision for LabWindows/CVI User Manual

3-6

ni.com

The following list describes how you can display the tools palette in a 
separate window and manipulate the palette.

Use 

imaqShowToolWindow()

 to display the tools palette in a floating 

window.

Use 

imaqSetupToolWindow()

 to configure the appearance of the 

tools palette.

Use 

imaqMoveToolWindow()

 to move the tools palette.

Use 

imaqCloseToolWindow()

 to close the tools palette.

If you want to draw an ROI without using an ROI constructor or displaying 
the tools palette in a separate window, use 

imaqSetCurrentTool()

This function allows you to select a contour from the tools palette without 
opening the palette.

Defining Regions Programmatically

When you have an automated application, you may need to define regions 
of interest programmatically. To programmatically define an ROI, create 
the ROI using 

imaqCreateROI()

, and then add the individual contours. 

A contour is a shape that defines an ROI. You can create contours from 
points, lines, rectangles, ovals, polygons, and annuli. For example, to add a 
rectangular contour to an ROI, use 

imaqAddRectContour()

Specify regions by providing basic parameters that describe the region you 
want to define. For example, define a point by providing the x-coordinate 
and y-coordinate. Define a line by specifying the start and end coordinates. 
Define a rectangle by specifying the coordinates of the top, left point; the 
width and height; and in the case of a rotated rectangle, the rotation angle.

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 whether the corresponding 
pixel in the source image needs to be processed. If a pixel in the image 
mask has a value different 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.

When you need to make intensity measurements on particles in an image, 
you can use a mask to define the particles. First, threshold your image to 
make a new binary image. For more information about binary images, refer 
to Chapter 4, 

Performing Particle Analysis

. You can input the binary image 

Содержание IMAQ Vision for LabWindows TM /CVI

Страница 1: ...IMAQ TM IMAQ Vision for LabWindows TM CVI TM User Manual IMAQ Vision for LabWindows CVI User Manual August 2004 Edition Part Number 371266A 01...

Страница 2: ...90000 Israel 972 0 3 6393737 Italy 39 02 413091 Japan 81 3 5472 2970 Korea 82 02 3451 3400 Malaysia 603 9131 0918 Mexico 01 800 010 0793 Netherlands 31 0 348 433 466 New Zealand 0800 553 322 Norway 47...

Страница 3: ...produced or transmitted in any form electronic or mechanical including photocopying recording storing in an information retrieval system or translating in whole or in part without the prior written co...

Страница 4: ...Q Machine Vision Function Tree 1 3 Creating IMAQ Vision Applications 1 4 Chapter 2 Getting Measurement Ready Images Set Up Your Imaging System 2 1 Calibrate Your Imaging System 2 2 Create an Image 2 2...

Страница 5: ...2 Removing Unwanted Particles 4 3 Separating Touching Particles 4 3 Improving Particle Shapes 4 3 Make Particle Measurements 4 4 Chapter 5 Performing Machine Vision Tasks Locate Objects to Inspect 5...

Страница 6: ...6 Distance Measurements 5 26 Analytic Geometry Measurements 5 27 Instrument Reader Measurements 5 27 Identify Parts Under Inspection 5 28 Classifying Samples 5 28 Reading Characters 5 29 Reading Barco...

Страница 7: ...Contents IMAQ Vision for LabWindows CVI User Manual viii ni com Appendix A Technical Support and Professional Services Glossary Index...

Страница 8: ...the Page Setup item and select Options from the last dialog box This icon denotes a tip which alerts you to advisory information This icon denotes a note which alerts you to important information bold...

Страница 9: ...tutorial NI Vision Assistant Help If you need descriptions or step by step guidance about how to use any of the functions or features of NI Vision Assistant refer to this help file NI Vision Builder...

Страница 10: ...on about the features functions and operation of the NI IMAQ image acquisition VIs or functions refer to these help files IMAQ Vision Deployment Engine Note to Users If you need information about how...

Страница 11: ...scientific imaging applications The Vision Development Module also includes the same imaging functions for LabVIEW and ActiveX controls for Microsoft Visual Basic Vision Assistant another Vision Devel...

Страница 12: ...errors Acquisition Functions that acquire images through an IMAQ hardware device Display Functions that cover all aspects of image visualization and image window management Overlay Functions that cre...

Страница 13: ...enuation addition subtraction multiplication and division of complex images Barcode I O Functions that find and read barcodes LCD Functions that find and read seven segment LCD characters Meter Functi...

Страница 14: ...ination of the items in the last step to create your IMAQ Vision application Refer to the corresponding chapter listed to the side of the item for more information about items in either diagram Measur...

Страница 15: ...are optional steps Set Up Your Imaging System Calibrate Your Imaging System Create an Image Acquire or Read an Image Display an Image Attach Calibration Information Analyze an Image Improve an Image...

Страница 16: ...4 Grayscale and Color Measurements Measure Grayscale Statistics Measure Color Statistics 2 Create a Binary Image Improve a Binary Image Make Particle Measurements Chapter 5 Particle Analysis 3 Chapter...

Страница 17: ...constraints and the size of the object you need to inspect Refer to Chapter 3 System Setup and Calibration of the IMAQ Vision Concepts Manual for more information a Make sure your camera sensor is lar...

Страница 18: ...r errors inherent in your imaging system Perspective errors occur when your camera axis is not perpendicular to the object under inspection Nonlinear distortion may occur from aberrations in the camer...

Страница 19: ...mage pixels The return value of imaqCreateImage is a pointer to the image structure Supply this pointer as an input to all subsequent IMAQ Vision functions Most functions in the IMAQ Vision library re...

Страница 20: ...n image to hold the result if the destination is not the appropriate size The following examples illustrate source and destination images with imaqTranspose imaqTranspose myImage myImage This function...

Страница 21: ...size of an image Some functions take an additional mask parameter The presence of this parameter indicates that the processing or analysis is dependent on the contents of another image the image mask...

Страница 22: ...a copy of the current image Use imaqStopAcquisition to stop the acquisition Acquire a fixed number of images using a sequence acquisition Set up the acquisition using imaqSetupSequence Use imaqStartA...

Страница 23: ...nt external windows Use the other display functions to configure the appearance of each external window Properties you can set include whether the window has scroll bars a title bar and whether it is...

Страница 24: ...e the contents of the image for the following reasons To determine whether the image quality is high enough for your inspection task To obtain the values of parameters that you want to use in processi...

Страница 25: ...escribed in the Improve an Image section of this chapter Use imaqLineProfile to get the pixel distribution along a line in the image or use imaqROIProfile to get the pixel distribution along a one dim...

Страница 26: ...contrast in images containing few grayscale values imaqInverse Inverts the pixel intensities of an image to compute the negative of the image For example use imaqInverse before applying an automatic...

Страница 27: ...erform 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 the...

Страница 28: ...ng 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 frequenci...

Страница 29: ...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 unaltere...

Страница 30: ...aws in parts and comparing a color component with a reference Figure 3 1 illustrates the basic steps involved in making grayscale and color measurements Figure 3 1 Steps to Taking Grayscale and Color...

Страница 31: ...quare in the image Action Click one corner and drag to the opposite corner Rotated Rectangle Draw a rotated rectangle in the image Action Click one corner and drag to the opposite corner to create the...

Страница 32: ...esize the rectangle If you want to draw more than one ROI in a window hold down the Ctrl key while drawing additional ROIs Freehand Line Draw a freehand line in the image Action Click the initial posi...

Страница 33: ...l it designates the area you want to inspect 4 Click OK to output a descriptor of the region you selected You can input this ROI descriptor into many analysis and processing functions You can also con...

Страница 34: ...LightMeterRect Uses the output of imaqSelectRect Tools Palette Transformation The tools palette shown in Figure 3 3 automatically transforms from the palette on the left to the palette on the right wh...

Страница 35: ...annuli For example to add a rectangular contour to an ROI use imaqAddRectContour Specify regions by providing basic parameters that describe the region you want to define For example define a point by...

Страница 36: ...ity standard deviation minimum intensity maximum intensity area and the percentage of the image that you analyzed You can specify regions in the image with a labeled image mask A labeled image mask is...

Страница 37: ...an 8 bit image Note You can also use imaqExtractColorPlanes to process the red green and blue components of a 64 bit image 32 Color Image 8 bit Image Processing Saturation Value Hue Green Blue Red Sa...

Страница 38: ...g 3 Define an entire image a region or multiple regions in an image as the inspection or comparison area 4 Use imaqMatchColor to compare the learned color information to the color information in the i...

Страница 39: ...ents the entire color distribution of the image In a fabric identification application for example an entire image can specify the color information associated with a certain fabric type as shown in F...

Страница 40: ...r spectrums for identical fuses If you learn the color spectrum by drawing a region of interest around the 3 amp fuse in the upper row and then do a color matching for the 3 amp fuse in the upper row...

Страница 41: ...nformation An image containing a few well separated colors in the color space requires a lower sensitivity to describe the color than an image that contains colors that are close to one another in the...

Страница 42: ...ng determine the index to the color spectrum by locating the corresponding bins in the color wheel where each bin corresponds to a component in the color spectrum array Ignoring certain colors such as...

Страница 43: ...the steps involved in performing particle analysis Figure 4 1 Steps to Performing Particle Analysis Create a Binary Image Threshold your grayscale or color image to create a binary image Creating a bi...

Страница 44: ...mage resulting from a color threshold is an 8 bit binary image Improve the Binary Image After you threshold your image you may want to improve the resulting binary image with binary morphology You can...

Страница 45: ...cles and other user specified shapes Refer to Chapter 9 Binary Morphology of the IMAQ Vision Concepts Manual for more information about structuring elements If you know enough about the shape features...

Страница 46: ...This function returns the number of particles in an image and calculates various measurements for each particle imaqMeasureParticle This function uses the calculations from imaqCountParticles to retur...

Страница 47: ...ce between opposite corners of the bounding rectangle IMAQ_MT_CENTER_OF_MASS_X X coordinate of the point representing the average position of the total particle mass assuming every point in the partic...

Страница 48: ...cle IMAQ_MT_EQUIVALENT_RECT_LONG_SIDE Longest side of the rectangle with the same perimeter and area as the particle IMAQ_MT_EQUIVALENT_RECT_SHORT_SIDE Shortest side of the rectangle with the same per...

Страница 49: ...e image IMAQ_MT_MAX_FERET_DIAMETER Distance between the start and end of the line segment connecting the two perimeter points that are the furthest apart IMAQ_MT_MAX_FERET_DIAMETER_END_X X coordinate...

Страница 50: ...inertia in the x direction twice IMAQ_MT_MOMENT_OF_INERTIA_XY Moment of inertia in the x and y directions IMAQ_MT_MOMENT_OF_INERTIA_YY Moment of inertia in the y direction twice IMAQ_MT_MOMENT_OF_INE...

Страница 51: ...MENTS Number of horizontal segments in the particle IMAQ_MT_NUMBER_OF_VERT_SEGMENTS Number of vertical segments in the particle IMAQ_MT_ORIENTATION Angle of the line that passes through the particle c...

Страница 52: ...SUM_XXX Sum of all x coordinates cubed in the particle IMAQ_MT_SUM_XXY Sum of all x coordinates squared multiplied by y coordinates in the particle IMAQ_MT_SUM_XYY Sum of all x coordinates multiplied...

Страница 53: ...concentric rakes and spokes use edges represented in the image They locate with high accuracy the position of the edge of an object in the image For example a technique called clamping uses edge loca...

Страница 54: ...the images you need to process defining an ROI is simple Refer to the Set Search Areas section of this chapter for information about selecting an ROI Often the object under inspection appears rotated...

Страница 55: ...pect to the reference coordinate system Refer to Chapter 13 Dimensional Measurements of the IMAQ Vision Concepts Manual for information about coordinate systems You can build a coordinate transform us...

Страница 56: ...ld a coordinate transform using edge detection Note To use this technique the object cannot rotate more than 65 in the image 1 Specify one or two rectangular ROIs a If you use imaqFindTransformRect sp...

Страница 57: ...nate System Axes with Two Search Areas 2 Use the options parameter to choose the options you need to locate the edges on the object the coordinate system axis direction and the results that you want t...

Страница 58: ...part of the object that you want to use as a reference feature Refer to the Find Measurement Points section of this chapter for more information about defining a template 2 Define a rectangular ROI in...

Страница 59: ...on has a straight distinct edge main axis The object contains a second distinct edge not parallel to the main axis in a separate search area The object contains a second distinct edge not parallel to...

Страница 60: ...ck OK to output a descriptor of the region you selected You can input the ROI descriptor into many analysis and processing functions You can also use imaqSelectRect and imaqSelectAnnulus to define ROI...

Страница 61: ...f the center inner radius outer radius start angle and end angle You can specify a point by setting its x coordinates and y coordinates You can specify a line by setting the coordinates of the start a...

Страница 62: ...nd find a line describing the edge use imaqFindEdge and imaqFindConcentricEdges The imaqFindEdge function finds edges based on rectangular search areas as shown in Figure 5 5 The imaqFindConcentricEdg...

Страница 63: ...tween the lines that the functions use to detect edges The functions determine the intersection points based on their contrast width and steepness The software calculates a best fit line with outliers...

Страница 64: ...umber of search lines in the region by specifying the distance in pixels between each line Specify the search direction as left to right or right to left for a horizontally oriented rectangle Specify...

Страница 65: ...reference pattern to train the pattern matching algorithm with imaqLearnPattern2 3 Define an image or an area of an image as the search area A small search area reduces the time to find the features...

Страница 66: ...symmetric shown in Figure 5 7b A rotationally symmetric template provides good positioning information but no orientation information Figure 5 7 Symmetry Feature Detail A template with relatively coar...

Страница 67: ...e improves search performance and accuracy Figure 5 10a shows a pattern with insufficient background information Figure 5 10b illustrates a pattern with sufficient background information Figure 5 10 B...

Страница 68: ...ce incorrect results To avoid this reduce the search area so that only the desired pattern lies within the search area The time required to locate a pattern in an image depends on both the template si...

Страница 69: ...ing your particular application and the images you want to process is useful in selecting the pattern matching parameters Use the imaqMatchPattern2 function to set the following elements that influenc...

Страница 70: ...ure that the pattern matching algorithm looks for the template in all regions of the image Rotation Angle Ranges If you know that the pattern rotation is restricted to a certain range such as between...

Страница 71: ...matching algorithms provide a quick way to locate objects when color is present Use color pattern matching if your images have the following qualities The object you want to locate has color informati...

Страница 72: ...creating a template image These critical factors include color information symmetry feature detail positional information and background information Refer to the Defining and Creating Good Template I...

Страница 73: ...form By default the color pattern matching algorithm learns only those features from the template that are necessary for shift invariant matching However if you want to match the template at any orien...

Страница 74: ...oduce incorrect results To avoid this reduce the search area so that only the desired pattern lies within the search area For example in the fuse box inspection example use the location of the fuses t...

Страница 75: ...e pattern matching parameters Use the options parameter of imaqMatchColorPattern to set these elements The following are elements of the IMAQ Vision pattern matching algorithm that influence color pat...

Страница 76: ...occurrences of the template in the image This strategy is the fastest way to find templates in an image Color Score Weight When you search for a template using both color and shape information the co...

Страница 77: ...ide a quick way to locate regions in an image with specific colors Use color location when your application has the following characteristics Requires the location and the number of regions in an imag...

Страница 78: ...gion First clamp functions detect points along the two edges using the Rake function Then they compute the distance between the points detected on the edges along each search line of the rake and retu...

Страница 79: ...d by two lines imaqGetMidLine Finds the line that is midway between a point and a line and is parallel to the line imaqGetPolygonArea Calculates the area of a polygon specified by its vertex points In...

Страница 80: ...f varied shapes For example sorting different mechanical parts on a conveyor belt into different bins Inspection Inspects objects by assigning each object an identification score and then rejecting ob...

Страница 81: ...based on the report imaqDispose report imaqDispose session Reading Characters Use OCR to read text and or characters in an image Typical uses for OCR in an inspection application include identifying o...

Страница 82: ...fying control values specific to your application imaqReadDataMatrixBarcode can locate automatically one or multiple Data Matrix barcodes in an image However you can improve the inspection performance...

Страница 83: ...rixBarcode automatically detects the type of barcode to read You can improve the performance of the your function by specifying the type of barcode in your application IMAQ Vision supports Data Matrix...

Страница 84: ...imaqOverlayMetafile Overlays a metafile on the image imaqOverlayText Overlays text on an image imaqOverlayROI Overlays an ROI on an image imaqOverlayClosedContour Overlays a closed contour on an image...

Страница 85: ...nction With imaqFindPattern imaqCountObjects and imaqFindTransformPattern you can overlay the search area and the result Select the information you want to overlay by setting the element that correspo...

Страница 86: ...e nonlinear distortion calibration Perspective and Nonlinear Distortion Calibration Perspective errors and lens aberrations cause images to appear distorted This distortion misplaces information in an...

Страница 87: ...s should be equal dx dy The dots should cover the entire desired working area The radius of the dots in the acquired image should be 6 10 pixels The center to center distance between dots in the acqui...

Страница 88: ...tically determines the direction of the horizontal axis in the real world The vertical axis direction can either be indirect as shown in Figure 6 2a or direct as shown in Figure 6 2b Figure 6 2 Axis D...

Страница 89: ...ndirect If you define a coordinate system yourself carefully consider the needs of your application Express the origin in pixels Always choose an origin location that lies within the calibration grid...

Страница 90: ...hapter 2 Getting Measurement Ready Images The grid does not need to occupy the entire image You can choose a region within the image that contains the grid After you acquire an image of the grid learn...

Страница 91: ...ctive way to increase correction speeds Set the user defined ROI using the roi parameter of either imaqLearnCalibrationGrid or imaqLearnCalibrationPoints Note The user defined ROI represents the area...

Страница 92: ...stortion use the nonlinear method The nonlinear method guarantees accurate results only in the area that the calibration grid covers as shown in Figure 6 6 If your system exhibits both perspective and...

Страница 93: ...e options parameter to TRUE to learn the error map Learning the Correction Table If the speed of image correction is a critical factor for your application use a correction table The correction table...

Страница 94: ...assign the calibration to an arbitrary image using imaqSetSimpleCalibration To perform a simple calibration set a coordinate reference angle center and axis direction and scaling factors on the define...

Страница 95: ...etup to each image you acquire This function takes in a source image containing the calibration information and a destination image that you want to calibrate The destination image is your inspection...

Страница 96: ...per Exchange at ni com exchange National Instruments Application Engineers make sure every question receives an answer Training and Certification Visit ni com training for self paced training eLearnin...

Страница 97: ...ion about a color image The alpha channel is stored as the first byte in the four byte representation of an RGB pixel area 1 A rectangular portion of an acquisition window or frame that is controlled...

Страница 98: ...xel can take 2n different values For example if n equals 8 a pixel can take 256 different values ranging from 0 to 255 If n equals 16 a pixel can take 65 536 different values ranging from 0 to 65 535...

Страница 99: ...lor closing A dilation followed by an erosion A closing fills small holes in objects and smooths the boundaries of objects clustering A technique where the image is sorted within a discrete number of...

Страница 100: ...lse response of the filter that they represent D Danielsson function Similar to the distance functions but with more accurate results determinism A characteristic of a system that describes how consis...

Страница 101: ...contrast in dark regions of an image F FFT Fast Fourier Transform A method used to compute the Fourier transform of an image fiducial A reference pattern on a part that helps a machine vision applica...

Страница 102: ...y variations in an image detects edges or object boundaries and enhances fine details in an image highpass frequency filter Removes or attenuates low frequencies present in the frequency domain of the...

Страница 103: ...tz Frequency in units of 1 second I I O Input output The transfer of data to from a computer system involving communications channels operator interface devices and or data acquisition and control int...

Страница 104: ...mage processing Encompasses various processes and analysis functions that you can apply to an image image source The original input image imaging Any process of acquiring and displaying images and ana...

Страница 105: ...at the execution of an algorithm varies from one execution to the next JPEG Joint Photographic Experts Group An image file format for storing 8 bit and color images with lossy compression JPEG images...

Страница 106: ...the decompressed image is identical to the original image lossy compression Compression in which the decompressed image is visually similar but not identical to the original image lowpass attenuation...

Страница 107: ...ates how closely an acquired image matches the template image A match score of 1000 indicates a perfect match A match score of 0 indicates no match MB Megabyte of memory median filter A lowpass filter...

Страница 108: ...adient information nonlinear Sobel filter A highpass edge extraction filter based on two dimensional gradient information The filter has a smoothing effect that reduces noise enhancements caused by gr...

Страница 109: ...nnected region or grouping of non zero pixels in a binary image particle analysis A series of processing operations and analysis functions that produce some information about the particles in an image...

Страница 110: ...ge R real time A property of an event or system in which data is processed as it is acquired instead of being accumulated and processed at a later time resolution The number of rows and columns of pix...

Страница 111: ...of white added to a pure color Saturation relates to the richness of a color A saturation of zero corresponds to a pure color with no white added Pink is a red with low saturation scale invariant matc...

Страница 112: ...rdinates in terms of fractions of a pixel T template A color shape or pattern that you are trying to match in an image using the color matching shape matching or pattern matching functions A template...

Страница 113: ...s the average of the maximum and minimum red green and blue values of that pixel VI Virtual Instrument 1 A combination of hardware and or software elements typically used with a PC that has the functi...

Страница 114: ...s creating 4 1 improving 4 2 C calibrating images 6 1 imaging systems 2 2 calibration defining templates 6 2 saving calibration information 6 10 using simple calibration 6 9 calibration information at...

Страница 115: ...ata matrix barcodes reading 5 30 defining calibration templates 6 2 color template images 5 20 coordinate systems using edge detection 5 4 coordinate systems using pattern matching 5 6 image masks 3 6...

Страница 116: ...mage 3 7 image statistics 3 7 grayscale morphology 2 11 grayscale statistics measuring 3 7 H help technical support A 1 highpass attenuation 2 13 filters 2 10 truncation 2 13 holes filling in particle...

Страница 117: ...2 9 sharpness of transitions 2 10 inspecting images 2 8 objects 5 2 inspection tasks performing 5 1 instrument drivers xi NI resources A 1 interpreting pattern matching results 5 19 invalidating cali...

Страница 118: ...ies 5 23 training color pattern matching algorithm 5 21 training the pattern matching algorithm 5 15 using color pattern matching 5 19 PDF417 barcodes reading 5 31 performing machine vision inspection...

Страница 119: ...taking color measurements 3 1 grayscale measurements 3 1 technical support A 1 template images background information 5 15 5 21 color information 5 20 defining color template images 5 20 feature detai...

Отзывы: