background image

Chapter 5

Performing Machine Vision Tasks

IMAQ Vision for LabWindows/CVI User Manual

5-12

ni.com

These functions require you to input the coordinates of the points along the 
search contour. Use 

imaqROIProfile()

 to obtain the coordinates along 

the edge of each contour in an ROI. If you have a straight line, use 

imaqGetPointsOnLine()

 to obtain the points along the line instead of 

using an ROI.

These functions determine the edge points based on their contrast and 
slope. You can specify whether you want to find the edge points using 
subpixel accuracy.

Finding Edge Points Along Multiple Search Contours

Use 

imaqRake()

imaqSpoke()

, and 

imaqConcentricRake()

 to find 

edge points along multiple search contours. These functions behave similar 
to 

imaqEdgeTool2()

, but they find edges on multiple contours. Pass in an 

ROI to define the search region for these functions.

The 

imaqRake()

 function works on a rectangular search region. The 

search lines are drawn parallel to the orientation of the rectangle. Control 
the number 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 the search 
direction as top to bottom or bottom to top for a vertically oriented 
rectangle.

The 

imaqSpoke()

 function works on an annular search region, scanning 

the search lines that are drawn from the center of the region to the outer 
boundary and that fall within the search area. Control the number of lines 
in the region by specifying the angle, in degrees, between each line. Specify 
the search direction as either going from the center outward or from the 
outer boundary to the center. 

The 

imaqConcentricRake()

 function works on an annular search 

region. The concentric rake is an adaptation of the Rake to an annular 
region. IMAQ Vision does edge detection along search lines that occur 
in the search region and that are concentric to the outer circular boundary. 
Control the number of concentric search lines that are used for the edge 
detection by specifying the radial distance between the concentric lines 
in pixels. Specify the direction of the search as either clockwise or 
counterclockwise.

Summary of Contents for IMAQ Vision for LabWindows TM /CVI

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 7: ...Contents IMAQ Vision for LabWindows CVI User Manual viii ni com Appendix A Technical Support and Professional Services Glossary Index...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Page 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...

Reviews: