background image

Chapter 3

Making Grayscale and Color Measurements

IMAQ Vision for Visual Basic User Manual

3-2

ni.com

Table 3-1.  

Tools Palette Functions

Tool Name

Function

None

Disable the tools.

Selection Tool

Select an ROI in the image and adjust the position 
of its control points and contours.

Action: Click the appropriate ROI or control 
points.

Point

Select a pixel in the image.

Action: Click the appropriate position.

Line

Draw a line in the image.

Action: Click the initial position and click again 
on the final position.

Rectangle

Draw a rectangle or square 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 rectangle. Then, click on the 
lines inside the rectangle and drag to adjust the 
rotation angle.

Oval

Draw an oval or circle in the image.

Action: Click the center position and drag to the 
appropriate size.

Annulus

Draw an annulus in the image.

Action: Click the center position and drag to the 
appropriate size. Adjust the inner and outer radii, 
and adjust the start and end angle.

Broken Line

Draw a broken line in the image.

Action: Click to place a new vertex and 
double-click to complete the ROI element.

Summary of Contents for IMAQTM

Page 1: ...IMAQ TM IMAQ Vision for Visual Basic User Manual IMAQ Vision for Visual Basic User Manual August 2004 Edition Part Number 371257A 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: ...de reasonable control Copyright Under the copyright laws this publication may not be reproduced or transmitted in any form electronic or mechanical including photocopying recording storing in an infor...

Page 4: ...ntrol 1 3 CWIMAQViewer Control 1 3 niocr ocx 1 4 NIOCR control 1 4 cwmv ocx 1 4 CWMachineVision control 1 4 ActiveX Objects 1 5 Creating IMAQ Vision Applications 1 5 Chapter 2 Getting Measurement Read...

Page 5: ...ng Colors 3 9 Learning Color Information 3 9 Specifying the Color Information to Learn 3 10 Using the Entire Image 3 10 Choosing a Color Representation Sensitivity 3 12 Ignoring Learned Colors 3 13 Ch...

Page 6: ...Testing the Search Algorithm on Test Images 5 18 Using a Ranking Method to Verify Results 5 19 Finding Points Using Color Pattern Matching 5 19 Defining and Creating Effective Color Template Images 5...

Page 7: ...ibration Information 6 5 Specifying Scaling Factors 6 6 Choosing a Region of Interest 6 6 Choosing a Learning Algorithm 6 6 Using the Learning Score 6 7 Learning the Error Map 6 8 Learning the Correct...

Page 8: ...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 Bold tex...

Page 9: ...access this file by selecting Start Programs National Instruments Documentation Vision IMAQ Vision for Visual Basic Reference NI Vision Assistant NI Vision Assistant Tutorial If you need to install N...

Page 10: ...manual NI IMAQ VI or function reference guides If you need information about the features functions and operation of the NI IMAQ image acquisition VIs or functions refer to these help files IMAQ Visi...

Page 11: ...hat you can use to develop machine vision and scientific imaging applications The Vision Development Module also includes the same imaging functions for LabWindows CVI and other C development environm...

Page 12: ...to open this file Example programs If you want examples of how to create specific applications in Visual Basic go to Vision Examples MSVB If you want examples of how to create specific applications in...

Page 13: ...r software installed on the target system to use the CWIMAQ control For information about NI IMAQ refer to the NI IMAQ User Manual that came with the IMAQ device CWIMAQVision Control Use this control...

Page 14: ...you create in a character set file Training might be a one time process or it might be a process you repeat several times creating several character sets to broaden the scope of characters you want to...

Page 15: ...e Dim image As New CWIMAQImage Tip If you intend to develop an application in Visual C National Instruments recommends that you use IMAQ Vision for LabWindows CVI However if you decide to use IMAQ Vis...

Page 16: ...ibrate Your Imaging System Create an Image Acquire or Read an Image Display an Image Attach Calibration Information Analyze an Image Improve an Image Make Measurements or Identify Objects in an Image...

Page 17: ...nts Measure Grayscale Statistics Measure Color Statistics 2 Create a Binary Image Improve a Binary Image Make Particle Measurements Chapter 4 Performing Particle Analysis 3 Chapter 5 Performing Machin...

Page 18: ...ore information refer to Chapter 3 System Setup and Calibration of the IMAQ Vision Concepts Manual a Make sure the camera sensor is large enough to satisfy the minimum resolution requirement b Make su...

Page 19: ...linear errors inherent in the imaging system Perspective errors occur when the camera axis is not perpendicular to the object under inspection Nonlinear distortion may occur from aberrations in the ca...

Page 20: ...e source image Methods that process the contents of the image require one or more source images and a destination image Exceptions to the preceding statements are methods that take a mask image as inp...

Page 21: ...hot or Continuous The Acquisition Type combo box is located on the Acquisition property page of the CWIMAQ control You can set the value at run time by setting the CWIMAQ AcquisitionType property to c...

Page 22: ...ition and continuously acquire frames into the image buffers and then explicitly stop the acquisition Use the CWIMAQ Start method to start the acquisition Use the CWIMAQ Stop method to stop the acquis...

Page 23: ...depth recommended image type and calibration units without actually reading all the image data Converting an Array to an Image Use the CWIMAQImage ArrayToImage method to convert an array to an image...

Page 24: ...tionInformation This method takes in a source image that contains the calibration information and a destination image that you want to calibrate The output image is the inspection image with the calib...

Page 25: ...s If the image quality does not meet your needs try to improve the imaging conditions to get the appropriate image quality You may need to re evaluate and modify each component of the imaging setup li...

Page 26: ...re information about these lookup tables refer to Chapter 5 Image Processing in the IMAQ Vision Concepts Manual CWIMAQVision UserLookup Converts the pixel values of an image by replacing them with val...

Page 27: ...ize of the kernel and the CWIMAQKernel Element property to set the data in the kernel Nth Order Filter CWIMAQVision NthOrder allows you to define a lowpass or highpass filter depending on the value of...

Page 28: ...dges are associated with mid to high spatial frequencies because they introduce significant gray level variations over short distances Gradually varying patterns are associated with low spatial freque...

Page 29: ...y of the image in the spatial domain Highpass attenuation The amount of attenuation is inversely proportional to the frequency information At high frequencies there is little attenuation As the freque...

Page 30: ...g 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 Measurements Define Regio...

Page 31: ...raw a rectangle or square 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...

Page 32: ...bout the characteristics of ROIs you draw as shown in Figure 3 2 Check the Show Tool Info check box on the Status Bar property page during design time or set the CWIMAQViewer ShowToolInfo property to...

Page 33: ...Tools Information 1 Anchoring Coordinates of a Region of Interest 2 Size of the Image 3 Zoom Factor 4 Image Type Indicator 8 bit 16 bit Float RGB32 RGBU64 HSL Complex 5 Pixel Intensity 6 Coordinates o...

Page 34: ...to the regions Use the CWIMAQRegions CopyTo method to copy all the data from one CWIMAQRegions object to another You can define the regions on a viewer and access the regions using the CWIMAQViewer R...

Page 35: ...ocessed 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 sour...

Page 36: ...mask Use CWIMAQVision Centroid2 to compute the energy center of the image or of a region within an image Measure Color Statistics Most image processing and analysis methods apply to 8 bit and 16 bit i...

Page 37: ...rt a pixel value represented in any color model into its components in any other color model using CWIMAQVision ColorValueConversion2 32 Color Image 8 bit Image Processing Saturation Value Hue Green B...

Page 38: ...rmation that you learned Refer to Chapter 14 Color Inspection of the IMAQ Vision Concepts Manual for more information Use the CWIMAQColorInformation object to represent the learned color information f...

Page 39: ...ceptable region containing background colors Figure 3 5 Template Color Information The following sections specify when to learn the color information associated with an entire image a region in an ima...

Page 40: ...s Figure 3 8 shows how light reflects differently off of the 3D surfaces of the fuses resulting in slightly different colors for identical fuses To view the color differences compare the 3 amp fuse in...

Page 41: ...n you learn a color you need to specify the granularity required to specify the color information An image that contains a few well separated colors in the color space requires a lower granularity to...

Page 42: ...second to last component in the color spectrum array to 1 ignores the color black To ignore other color components in color matching determine the index to the color spectrum by locating the correspon...

Page 43: ...eps involved in performing particle analysis Figure 4 1 Steps for Performing Particle Analysis Create a Binary Image Threshold the grayscale or color image to create a binary image Creating a binary i...

Page 44: ...and Luminance The binary image resulting from a color threshold is an 8 bit binary image Improve the Binary Image After you threshold the image you may want to improve the resulting binary image with...

Page 45: ...t angles along the edges of particles and other user specified shapes For more information about structuring elements refer to Chapter 9 Binary Morphology of the IMAQ Vision Concepts Manual If you kno...

Page 46: ...he location of particles and their shape features Use the following methods to perform particle measurements CWIMAQVision ParticleReport This method returns a CWIMAQParticleReport object which contain...

Page 47: ...mentBoundingRectRight X coordinate of the rightmost particle point cwimaqMeasurementBoundingRectTop Y coordinate of highest particle point cwimaqMeasurementBoundingRectWidth Distance between the X coo...

Page 48: ...ength to the Max Feret Diameter cwimaqMeasurementEquivalentRectDiagonal Distance between opposite corners of the rectangle with the same perimeter and area as the particle cwimaqMeasurementEquivalentR...

Page 49: ...y the particle perimeter cwimaqMeasurementImageArea Area of the image cwimaqMeasurementMaxFeretDiameter Distance between the start and end of the line segment connecting the two perimeter points that...

Page 50: ...urementMomentOfInertiaXXX The moment of inertia in the X direction three times cwimaqMeasurementMomentOfInertiaXXY The moment of inertia in the X direction twice and the Y direction once cwimaqMeasure...

Page 51: ...rOfVertSegments Number of vertical segments in the particle cwimaqMeasurementOrientation The angle of the line that passes through the particle Center of Mass about which the particle has the lowest m...

Page 52: ...m of all X coordinates times Y coordinates squared in the particle cwimaqMeasurementSumY The sum of all Y coordinates in the particle cwimaqMeasurementSumYY The sum of all Y coordinates squared in the...

Page 53: ...ed in the image They locate with high accuracy the position of the edge of an object in the image For example you can a technique called clamping which uses the edge location to measure the width of t...

Page 54: ...is chapter for information about selecting a region of interest Often the object under inspection appears rotated or shifted in the image you need to process with respect to the reference image in whi...

Page 55: ...djust the regions of inspection automatically You also can use these outputs to move the regions of inspection relative to the object programmatically Using Edge Detection to Build a Coordinate Transf...

Page 56: ...ordTransformUsingTwoRects specify two rectangular ROIs each containing one separate straight boundary of the object as shown in Figure 5 3 The boundaries cannot be parallel The regions must be large e...

Page 57: ...tion in subsequent images set this parameter to False Using Pattern Matching to Build a Coordinate Transformation You can build a coordinate transformation using pattern matching Use CWMachineVision F...

Page 58: ...search area in which you expect to find the template 3 Set the MatchMode property of the CWMVFindCTUsingPatternOptions object to cwimaqRotationInvariant when you expect the template to appear rotated...

Page 59: ...spection 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 parall...

Page 60: ...on the image Resize or reposition the ROI until it defines the area of the image you want to process 3 Use CWMachineVision GetSelected shapename FromViewer to programmatically retrieve the shape from...

Page 61: ...n specify a line by setting the coordinates of the start and end points Refer to Chapter 3 Making Grayscale and Color Measurements for more information about defining regions of interest Find Measurem...

Page 62: ...ConcentricEdge CWMachineVision FindStraightEdge finds edges based on rectangular search areas as shown in Figure 5 5 CWMachineVision FindConcentricEdge finds edges based on annular search areas Figure...

Page 63: ...SimpleEdge and CWIMAQVision FindEdges2 to find edge points along a contour You can find the first edge last edge or all edges along the contour Use CWIMAQVision SimpleEdge when the image contains litt...

Page 64: ...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 c...

Page 65: ...election of a effective template image plays a critical part in obtaining good results Because the template image represents the pattern that you want to find make sure that all the important and uniq...

Page 66: ...tion than a model with fine features However the model must contain enough detail to identify it Figure 5 8 Feature Detail Positional Information A template with strong edges in both the x and y direc...

Page 67: ...atch the template at any orientation the learning mode must consider the possibility of arbitrary orientations To specify which type of learning mode to use pass the learn mode to the LearnPatternOpti...

Page 68: ...reasing the template size you can reduce the required search time In many inspection applications you have general information about the location of the fiducial Use this information to define a searc...

Page 69: ...are not optimal To efficiently select the best pattern matching parameters for the application you must have a clear understanding of the application and the images you want to process The following s...

Page 70: ...Use CWIMAQMatchPatternOptions MinimumContrast to set the minimum contrast Rotation Angle Ranges If you know that the pattern rotation is restricted to a certain range such as between 15 to 15 provide...

Page 71: ...olor pattern matching algorithms provide a quick way to locate objects when color is present Use color pattern matching under the following circumstances The object you want to locate has color inform...

Page 72: ...e pattern are well defined in the image Several factors are critical in creating a template image These critical factors include color information symmetry feature detail positional information and ba...

Page 73: ...e of matching that you expect to perform By default the color pattern matching algorithm learns only those features from the template that are necessary for shift invariant matching However if you wan...

Page 74: ...incorrect results To avoid this reduce the search area so that only the appropriate pattern lies within the search area For example in the fuse box inspection example use the location of the fuses to...

Page 75: ...want to process The following sections discuss parameters of the IMAQ Vision color pattern matching algorithm and how they influence the algorithm Color Sensitivity Use the color sensitivity to contr...

Page 76: ...ost reliable method to look for a template in any image at potentially reduced speed Note Use the conservative strategy if you have multiple targets located very close to each other in the image Decid...

Page 77: ...o Chapter 12 Pattern Matching in the IMAQ Vision Concepts Manual for more information about pattern matching Testing the Search Algorithm on Test Images To determine if the selected template or refere...

Page 78: ...IMAQMatchColorPatternOptions 6 Use CWIMAQVision MatchColorPattern to test the color location algorithm on test images 7 Verify the results using a ranking method Use CWIMAQVision WriteImageAndVisionIn...

Page 79: ...n a rectangular search region Use CWIMAQVision FindPointDistances to compute the distances between consecutive pairs of points in an array of points You can obtain these points from the image using an...

Page 80: ...QVision ReadMeter to read the position of the needle using the CWIMAQMeterArc object Use CWIMAQVision FindLCDSegments to calculate the regions of interest around each digit in an LCD or LED To find th...

Page 81: ...text and or characters in an image you must create a character set file with samples of the characters using the OCR Training Interface Go to Start Programs National Instruments Vision OCR Training to...

Page 82: ...ly one barcode per image set CWIMAQDataMatrixOptions SearchMode to cwimaqBarcode2DSearchSingleConservative to increase the speed of the method By default CWIMAQVision ReadDataMatrixBarcode determines...

Page 83: ...ode parameter to cwimaqBarcode2DSearchSingleConservative to increase the speed of the method Display Results You can display the results obtained at various stages of the inspection process on the win...

Page 84: ...igure the following CWMachineVision methods to overlay different types of information about the inspection image FindStraightEdge FindCircularEdge FindConcentricEdge MeasureMaximumDistance MeasureMini...

Page 85: ...t Use CWIMAQOverlay Clear to clear any previous overlay information from the image Use CWIMAQVision WriteImageAndVisionInfo to save an image with its overlay information to a file You can read the inf...

Page 86: ...ation to calibrate the system Perspective and Nonlinear Distortion Calibration Perspective errors and lens aberrations cause images to appear distorted This distortion misplaces information in an imag...

Page 87: ...placement in the x and y directions must equal dx dy The dots must cover the appropriate portion of the working area The radius of the dots must be 6 10 pixels The center to center distance between do...

Page 88: ...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 Direction in the Image Plane If y...

Page 89: ...Orientation cwimaqAxisOrientationIndirect If you define a coordinate system yourself carefully consider the requirements of the application Express the origin in pixels Always choose an origin locatio...

Page 90: ...tting 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 the calibr...

Page 91: ...ration options selected Pass a CWIMAQRegions collection representing the region you want to learn to the Regions parameter of CWIMAQVision LearnCalibrationGrid or CWIMAQVision LearnCalibrationPoints N...

Page 92: ...ging setup exhibits nonlinear distortion 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 the syste...

Page 93: ...real world coordinate The transformation accuracy may be higher than the value the error range indicates Set CWIMAQLearnCalibrationOptions LearnErrorMap to True to learn the error map Learning the Cor...

Page 94: ...d The software rotates and scales a pixel coordinate according to predefined coordinate reference and scaling factors You can assign the calibration to an arbitrary image using CWIMAQVision SetSimpleC...

Page 95: ...mation you read from another image refer to the Attach Calibration Information section Attach Calibration Information When you finish calibrating the setup you can apply the calibration settings to im...

Page 96: ...age is different from a corrected image Note Because calibration information is part of the image it is propagated throughout the processing and analysis of the image Methods that modify the image siz...

Page 97: ...er 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 eLearning...

Page 98: ...on 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 a...

Page 99: ...el 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 o...

Page 100: ...or 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 c...

Page 101: ...se 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 consist...

Page 102: ...ntrast 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 applicatio...

Page 103: ...ensity 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 o...

Page 104: ...z 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 inte...

Page 105: ...age 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 anal...

Page 106: ...xt JPEG Joint Photographic Experts Group An image file format for storing 8 bit and color images with lossy compression JPEG images have the file extension JPG K kernel A structure that represents a p...

Page 107: ...est frequency and full attenuation at the highest frequency lowpass FFT filter Removes or attenuates high frequencies present in the FFT domain of an image lowpass filter Attenuates intensity variatio...

Page 108: ...is filter effectively removes isolated pixels without blurring the contours of objects memory buffer See buffer MMX Multimedia Extensions An Intel chip based technology that allows parallel operations...

Page 109: ...rocessed The pixel being processed is set to the Nth pixel value where N is the order of the filter number of planes in an image The number of arrays of pixels that compose the image A gray level or p...

Page 110: ...ital image Also called pixel pixel Picture element The smallest division that makes up the video scan line For display on a computer monitor a pixel s optimum dimension is square aspect ratio of 1 1 o...

Page 111: ...at a later time resolution The number of rows and columns of pixels An image composed of m rows and n columns has a resolution of reverse function Inverts the pixel values in an image producing a phot...

Page 112: ...f 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 match...

Page 113: ...dinates 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 c...

Page 114: ...nal Instruments Corporation G 17 IMAQ Vision for Visual Basic User Manual V value The grayscale intensity of a color pixel computed as the average of the maximum and minimum red green and blue values...

Page 115: ...des 5 30 reading PDF417 barcodes 5 31 binary images improving 4 2 Broken Line tool 3 2 building coordinate transformation with edge detection 5 3 coordinate transformation with pattern matching 5 5 bu...

Page 116: ...cy domain 2 11 pixel coordinates to real world coordinates 5 26 convolution filter 2 10 coordinate systems reference 6 3 coordinate transformation building with edge detection 5 3 building with patter...

Page 117: ...s 5 10 measurement points 5 9 points along the edge of a circle 5 10 points using color pattern matching 5 19 points using pattern matching 5 12 points with color location 5 25 Free Region tool 3 3 Fr...

Page 118: ...ying a learning algorithm 6 6 specifying a region of interest 6 6 specifying scaling factors 6 6 using learning scores 6 7 voiding calibrations 6 9 learning score using 6 7 light intensity measuring 3...

Page 119: ...spective calibration 6 1 pixel coordinates converting to real world coordinates 5 26 Point tool 3 2 points finding along one search contour 5 11 finding along the edge of a circle 5 10 finding measure...

Page 120: ...17 5 23 rotation angle ranges for pattern matching 5 18 5 25 scaling mode 6 8 search areas 5 8 setting up measurement systems 2 1 shape scores 5 24 signal to noise ratio 2 9 simple calibration 6 9 sof...

Page 121: ...haracters 5 29 color pattern matching algorithms 5 21 pattern matching algorithm 5 15 training and certification NI resources A 1 troubleshooting NI resources A 1 U using learning scores 6 7 ranking t...

Reviews: