PMAlign Edit ControlCognex VisionPro

The PMAlign edit control provides a graphical user interface to the CogPMAlignTool and its component, which allows you to train a pattern and then have the tool search for it in successive input images. You can specify the type of algorithm to use when performing the pattern training or the pattern search, and choose between creating a trained pattern from an image or from a collection of shape models. The pattern search can be constrained by an optional search region within the input image. The following figure shows an example PMAlign edit control:

Cognex Patmax Align Reference Patmax Control Whole Control

To include the control in your Dev Studio.NET application, you must first add it to the Visual Basic project toolbox. The PMAlign edit control object type is named CogPMAlignEdit. See the topic Adding Edit Controls to Visual Studio for instructions.

The PMAlign edit control includes the following components:

  • A row of control buttons at the top left.
  • A tool display window that can display the PMAlign tool image buffers: Current.TrainImage, Current.InputImage, and LastRun.InputImage. These buffers contain the trained pattern, the search image in which the PMAlign tool searches for the pattern, and the same image with the results of the search. Right click the tool display to bring up menu options that include zooming in or out of the image or showing a pixel or subpixel grid.
  • A set of tabs organized by function. These functions include parameter settings to run the tool, parameter settings for the search region of interest, display settings for the tool displays, and training results. Pressing the Control + Tab keys scrolls through the set of tabs.
  • A status bar at the bottom left of the control. A green circle indicates that the tool ran successfully; red means the tool ran unsuccessfully. The status bar also displays the time to run the tool and any error codes or messages. The first time that the status bar displays is the raw tool execution time. The second includes the time needed to update the edit control.

Control Buttons

Cognex Patmax Align Reference Patmax Control All Buttons

The following table describes the functions of the buttons at the top left of the control.

Table 1. Control buttons
ButtonDescription

Cognex Patmax Align Reference Patmax Control Run

Run the PMAlign tool. You must have a trained pattern, an input image, and specified run parameters. PMAlign searches for the trained pattern in the input image. You may constrain the pattern search to a search region within the input image.

Cognex Patmax Align Reference Patmax Control Electric

Toggles electric mode. When selected, the PMAlign tool runs automatically if certain parameters have changed. These parameters are indicated by electric bolt icons that appear when the tool is in electric mode.

Cognex Patmax Align Reference Patmax Control Local

Opens the local tool display window, which can display the Current.InputImage, Current.TrainImage, or LastRun.InputImage buffer.

Cognex Patmax Align Reference Patmax Control Float

Opens one or more floating tool display windows. You can display the Current.InputImage, Current.TrainImage, or LastRun.InputImage buffer. Unlike the local tool display, you can resize or move the position of the floating tool display window.

Cognex Patmax Align Reference Patmax Control Open

Loads a VisionPro persistence (.vpp) file, which contains a set of saved properties for this vision tool object type. Loading a persistence file for another object type throws an error and the load is unsuccessful.

For more information about VisionPro persistence features, see the topic Persistence in VisionPro.

Cognex Patmax Align Reference Patmax Control Save

Saves the current properties of the underlying tool to a VisionPro persistence file. You have the option to save either the entire tool or the tool without its images or results.

Cognex Patmax Align Reference Patmax Control Save As

Saves the current properties of the underlying tool to a new VisionPro persistence file.

Cognex Patmax Align Reference Patmax Control Reset

Resets the underlying tool to a default state.

Cognex Patmax Align Reference Pat Max Control Image Mask

Opens the Image Mask Editor for creating a mask to add to the training image.

Cognex Patmax Align Reference Patmax Control Grid Results

Opens a new, separate results window, allowing you to view run results without turning to the Results tab.

Cognex Patmax Align Reference Patmax Control Model Maker

Launches the Model Maker for editing shape models when you are using Synthetic PatMax.

Cognex Patmax Align Reference Patmax Control Tool Tips

Enables or disables the display of tooltips for individual items in this edit control.

Cognex Patmax Align Reference Patmax Control Help

Access the VisionPro Software Documentation.
PMAlign Edit Control Buffers

The PMAlign edit control has three image buffers. Two of the buffers use the underlying PMAlign tool's InputImage and TrainImage; the third buffer displays the last input image that the PMAlign tool ran on and the results of that search. All three buffers can be shown in both the local and floating tool display windows.

  • The Current.InputImage provides the input images to the PMAlign tool.
  • The Current.TrainImage contains the training image.
  • The LastRun.InputImage buffer displays the last image on which the tool most recently ran. Use the Graphics tab to highlights the search area and the results of the search.

When you run the PMAlign tool, the tool searches the Current.InputImage for the pattern in the Current.TrainImage buffer, and stores the results of this search on the Results tab.

Train Params Tab

Cognex Patmax Align Reference Patmax Control Train Params

Use the Train Params tab to set training parameters and to train the search pattern. Clicking the Advanced Feature button

Cognex Patmax Align Reference Patmax Control Advanced Features

on the far right of the tab displays less commonly used features.

Table 2. Features on the Train Params Tab
FeatureDescription
PatternDisplays the trained pattern, created either from an image or from a collection of shape models. This is specified by the TrainRegion, which is highlighted by a blue border, within TrainImage. You can set the train region using the Train Region and Origin tab or by resizing its display in Current.TrainImage. The message text at the bottom of the tab indicates whether the PMAlign tool is trained.
LoadObjectFromFileOpens a VisionPro persistence file, which has a VPP extension, that contains a trained pattern.
SaveObjectToFileSaves the current trained pattern into a VisionPro persistence file, which has a VPP extension.

RunAlgorithm

Select the search algorithm to use for training:

  • PatMax: Requires more time to execute but is more accurate and returns additional score information
  • PatQuick: Faster but less accurate than PatMax
  • PatMax and PatQuick
  • PatFlex: Locate patterns that have undergone a variety of nonlinear deformations
  • PatMax - High Sensitivity: Appropriate for images with very low contrast or significant video noise or image degradation
  • Perspective PatMax: Locate 2D features that have undergone perspective distortion

TrainModeChoose whether the PMAlign pattern should be trained based on the pixel content of the training image or trained based on the shape models you create and modify with the Model Maker.
IgnorePolarityIf enabled, pattern polarity is ignored. If disabled, only patterns with polarity matching the trained pattern will be found. You must allow the tool to ignore polarity if you are using a trained pattern made of shape models and any of the models have an undefined polarity.

RepeatingPatterns

Use this parameter when the pattern you want to train contains elements that repeat, such as a grid or a set of bars or a pattern of parallel lines.

This parameter is valid only when you choose PatMax from the Algorithm pulldown list.

TrainTrains the desired pattern as specified by the TrainRegion in the TrainImage or by the current collection of shape models. If the tool already has a trained pattern then the tool will untrain and then retrain. When the pattern is successfully trained, the text at the bottom of the control says, "Trained."

Grab Train Image button

Copies the image in the InputImage buffer into the TrainImage buffer.

This button is not enabled unless there is an image in Current.InputImage. It is also not enabled if you are creating a trained pattern from shape models and a transform.

Feature Grain LimitsIf GrainLimitAutoSelect is not selected, then the GrainLimitCoarse and GrainLimitFine grain limits that you supply are used.
ElasticitySpecifies the Elasticity property, which is the amount of variance, in pixels, allowed by the PMAlign tool. In general, you should specify a nonzero elasticity value if you expect inconsistent variation in patterns in run-time images.
AutoEdgeThresholdEnabledDisable the automatic value if you want to set a different threshold for the absolute minimum value of edge magnitude, below which the edge direction will be randomized.
GetInfoStringsTrain-time diagnostic message containing information about this pattern.
PCPStringThe PCP (PatMax Customizable Pack) string associated with this pattern. Appears only if a PCP file, which configures PMAlign parameters for specific applications, has been loaded.
PCPLoadFromFileLoads a PCP file.
Clear PCPClears the underlying tool of the configurations derived from the currently loaded PCP file.
RuntimeScoringMethodInstructs the pattern how to treat non-visible pixels at run-time when the input image is of type CogImage16Range.

Train Region and Origin Tab

Cognex Patmax Align Reference Patmax Control Train Region

Use the Train Region and Origin tab to define the TrainRegion, which defines the area of the TrainImage buffer that becomes the trained pattern. You can also define the train region graphically in the Current.TrainImage buffer. It may be easier to first specify the training region graphically, then use this tab to fine tune the train region parameters. The PMAlign edit control updates the train region values so that the values on this tab always match the shape of the train region in the Current.TrainImage buffer.

Some of the parameters on this tab, such as Rotation and Skew, can be specified in degrees (default) or radians. The underlying tool keeps the values in radians but the edit control converts them to degrees when appropriate.

Table 3. Train Region Features
FeatureDescription

TrainRegionMode

Defines the bounding box for the region.

  • Pixel Aligned Bounding Box encloses the defined region within a rectangle. This means that the portions of the image that are outside the defined region but within the bounding rectangle are included.
  • Pixel Aligned Bounding Box Adjust Mask encloses the defined region within a rectangle, but masks out the image portions that are outside the region but inside the enclosing rectangle. The result is that the defined region is closer to what you specify.

If you are training a pattern from a collection of shape models, you must use a Pixel Aligned Bounding Box, as a Pixel Aligned Bounding Box Adjust Mask region is not supported for shape training.

TrainRegion

Select the shape of the input region. Selecting None=Use entire image means that the tool uses the entire input image. A PMAlign tool supports the following input region shapes:

The set of region-defining parameters that appear depend on the region shape you use. For more information on using a polygon as an input region, see the topic Using Polygon Input Regions.

SelectedSpaceName

The coordinate space in which the training region is interpreted. For information, see Coordinate Space Names.

The selected space name of the training region is ignored when training from shape models and a transform.

Select ModeAvailable when Region Shape is cogRectangle or cogRectangleAffine. Selects the set of parameters that define the rectangle. If cogRectangleAffine is chosen, note that the angles of rotation and skew can be specified in degrees or radians, although the underlying tool keeps the measurements in radians.
FitToImageCenters the train region within Current.TrainImage.

Table 4. Train Origin Features
FeatureDescription

Origin X

Origin Y

Screen X Len

Screen Aspect

Rotation

Skew

Values that define the location and orientation of the train region's origin. These values will change if you modify the origin graphically. Note that the angles of rotation and skew can be specified in degrees or radians. Equivalent to the Origin property.

Center OriginSets the train region's origin at the center of the train region.

Tune Tab

The Tune tab lets you create and configure the CogPMAlignComposite object, which manages composite training for this pattern. The controls in this tab are used for both the Alignment and Tuning phases of composite training. You switch between the two phases by clicking the Alignment Setup and Tune & Train Setup option buttons at the top of the tab. The controls are different depending on which phase is selected.

Note Note
For information on AutoTune and composite model training, please see the topic PatMax AutoTune.
Tune Tab: Alignment Phase

Cognex Patmax Align Reference Tune Align

During the alignment setup phase of tuning, you use the controls on the Tune tab to manage the collection of Images and alignment Poses stored within this pattern's CogPMAlignComposite object's CompositeData collection.

FeatureDescription
Image List Buttons
Cognex Patmax Align Reference Tune Align Buttons
Use the image list buttons to manage the collection of images and alignment poses used for tuning. In addition to adding and removing images (the first two buttons), the third and fourth buttons allow you to save and load tuning data collections to and from files.
Find and Find All buttons. Clicking Find attempts to locate the trained pattern in the selected image; Find All attempts to locate the trained pattern in all the images.

Composite Data Item Graphics selectors.

During the initial alignment phase, check the Alignment check box to view the alignment graphics for the selected image. If you have tuned the pattern, then the tuning graphics are available as well.

Note Note
You must select Current.CompositeDataItemImage in the in the drop-down box of the image display associated with an image in the image collection list.

Tune Tab: Tuning Phase

Cognex Patmax Align Reference Tune Tune

During the tuning phase, you use the controls on the Tune tab to configure the tuning parameters, to select which of the images to use for tuning, and to review the tuning results.

FeatureDescription
Image List Buttons The add button is not available during the tuning phase, but you can still save and load the collection of tuning data.

Enabled check box.

Check the Enabled check box for an image to use features from that image when tuning the pattern. Changing the Enabled state of an image untrains the pattern.

Note Note
If the Enabled check box is checked for any image, then clicking the Tune & Train button or the Train in the Train Params tab will retrain the pattern using features from all the enabled images (not just the TrainImage for the pattern).

PercentCoarseFeaturesUsed

PercentFineFeaturesUsed

These columns display the percentage of coarse and fine features used in the final pattern from each enabled image. You can display both the used and discarded coarse and fine features by checking the appropriate check boxes in the Composite Data Item Graphics section.

ImageFraction Use the Image Frac control to determine what fraction of the tuning images need to contain a given feature for it to be included in the tuned pattern.
TuningElasticity Use the Tuning Elasticity to set the alignment tolerance (in pixels) for image features. Features must be within the specified distance to be counted as the same feature.

IgnorePolarity check box.

Check this option to ignore feature polarity in all tuning images.

The same setting for ignore polarity is used for all tuning images, including the TrainImage for the pattern

Note Note
If you check Ignore Polarity, and perform composite training, you must also check Ignore Polarity on the Train Params tab. Failure to do so will result in a run-time error.
Timeout Sets the timeout for the overall tuning and training operation.
Tune & Train Initiates the tuning and training operation.

Composite Data Item Graphics selectors.

During the tuning phase, use the check boxes in the Train Graphics frame to view the features used and discarded during tuning. You can also view the alignment graphics.

Note Note
You must select Current.CompositeDataItemImage in the in the drop-down box of the image display associated with an image in the image collection list.

Run Params Tab

Cognex Patmax Align Reference Patmax Control Run Params

Use the Run Params tab to specify how to perform the pattern search. These parameters include the run algorithm to use, thresholds and limits, and the amount of rotating and scaling allowable during the pattern search.

Click the Advanced Feature button

Cognex Patmax Align Reference Patmax Control Advanced Features

on the far right of the tab to display less commonly used features.

Table 5. Run Params Tab Features
FeatureDescription

RunAlgorithm

Selects the search algorithm. The Patmax algorithm is more accurate than Patquick and can return additional score information, but requires more processing time. You can also specify BestTrained, in which case the tool will run using the highest-accuracy algorithm for which it has been trained.

If you specified PatMax - High Sensitivity for the trained algorithm, specify either PatMax or Best Trained. In either case, PatMax high sensitivity mode is used.

If you specified Perspective PatMax for the trained algorithm, specify either Perspective PatMax or Best Trained.

RunMode

By default, the PMAlign tool uses Search Image mode to search the entire image for the coarse features that indicate the presence of the pattern it is trained to locate. Switch to Refine Start Pose mode to give this PMAlign tool a specific StartPose, which is a two-dimensional linear transformation that defines the starting location of the search. The StartPose typically comes from another vision tool that has already executed and generated results about known features in the image.

Note: To use Refine Start Pose mode you must add an input terminal to expose the StartPose property for this PMAlign tool.

CoarseAcceptThreshold

The PMAlign tool uses a default Coarse Accept threshold to refine early search results based on the coarse features of the pattern. You can enable the Coarse Accept threshold and specify a different value, forcing the tool to consider more (lower value) or fewer (higher value) potential matches in each run-time image.

The threshold value cannot exceed the current value for Accept threshold. The edit control will correct the value for Accept threshold automatically if you set a value for Coarse Accept threshold higher than Accept threshold.

ScoreUsingClutter

If checked, then the PatMax algorithm considers extraneous or clutter features when computing the score of a pattern instance. Considering clutter features usually results in lower scores. Available for the PatMax algorithm only.

You may need to disable this feature if the trained pattern consists of shape models.

ApproximateNumberToFindSpecifies the number of results to look for.
AcceptThresholdSpecifies the acceptance threshold for the result score. Only results with scores greater than or equal to this value are accepted.
TimeoutEnabledIf checked, then the timeout value limits the execution time of the PMAlign inspection.
ZoneAngleSpecifies the angle of rotation that is allowable when PMAlign performs a pattern search. You can specify a nominal value that the PMAlign results must match exactly or you can click the

Cognex Patmax Align Reference Patmax Control Vary

arrow to specify a range of values for the results.
ZoneScaleSpecifies the scale value to be used when PMAlign performs a pattern search. You can specify a nominal value that a searched pattern must match exactly or you can click the

Cognex Patmax Align Reference Patmax Control Vary

arrow to specify a range of values for the results.
ZoneScaleXSpecifies the scale value in the X direction to be used when PMAlign performs a pattern search. You can specify a nominal value that a searched pattern must match exactly or you can click the

Cognex Patmax Align Reference Patmax Control Vary

arrow to specify a range of values for the results.
ZoneScaleYSpecifies the scale value in the Y direction to be used when PMAlign performs a pattern search. You can specify a nominal value that a searched pattern must match exactly or you can click the

Cognex Patmax Align Reference Patmax Control Vary

arrow to specify a range of values for the results.
PartialMatchEnabledOnly available for the PatFlex algorithm, PatFlex will find results that match only a fraction of the full pattern with a score better than the AcceptThreshold.
PartialMatchCoverageThresholdOnly available for the PatFlex algorithm, this specifies the minimum fraction of the pattern that must be matched in a valid PatFlex result.
GrainLimitsUsePatternIf checked, then the granularity limits determined by the training pattern are used. If not checked, then the GrainLimitCoarse and GrainLimitFine values specified are in effect.
ContrastThresholdDefines the minimum acceptable contrast for a pattern instance. Only pattern instances where the average difference in pixel values across all feature boundaries exceeds the contrast threshold are considered by PMAlign.
XYOverlapResult candidates overlap in area if the percentage of area overlap is greater than XYOverlap. PMAlign discards the weaker pattern instance when two pattern instances overlap for all degrees of freedom as well as area by the specified overlap percentage.
AutoEdgeThresholdEnabledDisable the automatic value if you want to set a different threshold for the absolute minimum value of edge magnitude, below which the edge direction will be randomized.

If you use the PatFlex search algorithm, the Run Params tab presents several different parameters, as shown:

Cognex Patmax Align Reference Patmax Control Pat Flex Params

The following table describes the PatFlex algorithm parameters:

Table 6. PatFlex Parameters
FeatureDescription
RefinementThe amount of refinement done on the deformation transform. A value of 'None' may contain some error. Higher levels of refinement will be more accurate at the expense of time.
MaxDeformationRateThe maximum amount of deformation expected in run-time image.
SmoothnessThe smoothness value used in fitting the deformation transform to the runtime input image.
DeformationFitControls the type of fit PatFlex will use to model deformation in the runtime input image.
ControlPointsXThe number of control points in the X direction. Increasing the number of control points allows the transform to better match patterns with areas of heavily local deformation (i.e., sharper features).
ControlPointsYThe number of control points in the Y direction. Increasing the number of control points allows the transform to better match patterns with areas of heavy local deformation (i.e., sharper features).
Search Region Tab

Cognex Patmax Align Reference Patmax Control Search Region

Use the Search Region tab to define the SearchRegionMode, the area of the InputImage buffer to which the pattern search is constrained. The search region appears with a blue border in the Current.InputImage, and you can graphically define the search region in this buffer. It may be easier to specify the search region graphically, then use this tab to fine tune the search region parameters. When you resize the search region in the InputImage, the values on this tab change; likewise, changing the parameter values causes the search region to alter its size and shape.

Table 7. Search Region Tab Features
FeatureDescription

SearchRegionMode

Defines the bounding box for the region.

  • Pixel Aligned Bounding Box encloses the defined region within a rectangle. This means that the portions of the image that are outside the defined region but within the bounding rectangle are included.
  • Pixel Aligned Bounding Box Adjust Mask encloses the defined region within a rectangle, but masks out the image portions that are outside the region but inside the enclosing rectangle. The result is that the defined region is closer to what you specify.

Outside Region Scoring Parameters

Choose a Features Threshold value that specifies the percentage of features in the trained pattern that can be outside the search region without penalizing the score. The default value of 0 means that the PMAlign tool expects all the features of the trained pattern to be located within the search region, while a value of 0.3 means that up to 30% of the trained pattern can be outside the search region without affecting the final score.

Use this feature when you want to allow some portion of the features in the trained pattern to exist outside the search region without affecting the overall score given to the features the search region still contains.

SearchRegionThe shape of the search region. Selecting "None=Use entire image" means that the entire Current.InputImage becomes the search region. The set of region-defining parameters depends on the selected Region Shape.
SelectedSpaceNameThe coordinate space in which the search region is interpreted. For more information, see Coordinate Space Names.
Select ModeAvailable when Region Shape is cogRectangle or cogRectangleAffine. Selects the set of parameters that define the rectangle. If cogRectangleAffine is chosen, note that the angles of rotation and skew can be specified in degrees or radians, although the underlying tool keeps the measurements in radians.
FitToImageCenters the search region within Current.InputImage.

Graphics Tab

Cognex Patmax Align Reference Patmax Control Graphics

Use the Graphics tab to choose the results graphics that are displayed in the LastRun.InputImage display.

Table 8. Graphics Tab Features
FeatureDescription

Train feature display

You can show these features in the Current.TrainImage buffer, which contains the trained pattern:

  • Show features that were trained at the coarse granularity limit. Features are displayed in yellow. Equivalent to CreateGraphicsCoarse method.
  • Show features that were trained at the fine granularity limit. Features are displayed in green. Equivalent to CreateGraphicsFine method.

The preceding features appear only if the pattern is trained successfully.

  • Show the shape models.
  • Show Search Image Mask shows a graphic representing the run-time mask, if you supplied one. The graphic is shown on the Current.InputImage display.
  • Show Train Image Mask shows a graphic representing the training-time mask, if you supplied one. The graphic is shown on the Current.TrainImage display.

Result graphics display

You can show these features in the LastRun.InputImage buffer, which contains the image that the PMAlign tool last searched, and the results of that search. Uses the CreateResultGraphics method to generate these results.

  • Train pattern's origin
  • Train pattern's coordinate axes.
  • The match region.
  • The shape models of found features

Diagnostics display

Displays the following features in the LastRun.InputImage buffer. Uses the CreateResultGraphics method to generate these results.

  • Show match features displays the found features that were used to match the trained pattern. Not all trained features may be present. For each matched feature, the color of the graphic indicates the quality of the match (red indicates poor matches, yellow fair matches, and green good matches).
  • Show search region displays the search region as defined in Current.InputImage buffer (or in the Search Region tab).
  • Show Diagnostic Search Image Mask displays the run-time mask, if one was specified.

The Show Input Image option buttons let you specify whether a reference to the input image or a deep copy of the input image is displayed for the LastRun.InputImage. You can also specify that no image be displayed.

The Show Flex Deformation Grid check box will display a grid that represents the computed deformation transformation. You must specify PatFlex for the run-time algorithm, and you must re-run the tool after checking this box to see the result.

The Show Flex Unwarped Images check box will display an unwarped version of the input image. The unwarping is most accurate within the region that corresponds to the trained pattern. You must specify PatFlex for the run-time algorithm, and you must re-run the tool after checking this box to see the result.

Results Tab

Cognex Patmax Align Reference Patmax Control Results

The Results tab displays the results of the most recent pattern searches. This corresponds to the CogPMAlignResult interface. Use the slider control below the results grid to display the complete set of results.

Table 9. Results Tab Features
FeatureDescription
GetInfoStringsDisplays the run-time diagnostic message text string(s) for the last PMAlign result. If there are no messages then the text box will be empty.

Results Grid

Displays the following information for each result.

  • Score for this result. The range is 0.0 to 1.0 with higher values indicating a closer match.
  • FitError, a measure of how closely the found pattern matches the features of the trained pattern, without regard to missing features. The range is zero (perfect fit) to infinity (poor fit). Used only for the PatMax algorithm.
  • Coverage, the percentage of the features in the trained pattern that are found in the search result. Range is 0.0 to 1.0. Used only for the PatMax algorithm.
  • Clutter, the number of extraneous features present in the result divided by the number of features in the trained pattern. Range from 0.0 to infinity. Used only for the PatMax algorithm.
  • MaxCoarseAcceptThreshold, the maximum coarse accept threshold that would allow this result to be found.

The coordinates, angle and scaling factors are retrieved with the GetPose method.

  • X, Y are the coordinates of the pattern's origin as measured in the selected space of the InputImage.
  • Angle is the rotation of pattern space as measured in the selected space of the InputImage.
  • Scale, ScaleX and ScaleY are the scaling factors between pattern space and the selected space of the InputImage.