Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

How to create a valid template image?

Hello,
We have automated the creation of template images for use in pattern matching.  We are extracting a region of an acquired image, and saving the extracted image using the tool "Write Image and Vision Info", which saves the file in PNG.  In investigating some quirky pattern match behavior, I tried to load the template into vision assistant for use with the pattern match tool, and got the error "not a valid template file".  Do we need to be using a different tool/alogorithm to save template images?  What is the proper way to save a valid template file?  The way we have been doing it works, but I'm wondering now if the quirky behavior we are seeing is related to how we are saving template images, now that I see that error.  Anyone?

Thanks

David Jenkinson
0 Kudos
Message 1 of 7
(8,132 Views)
In reference to my message above, the pattern match failures we are seeing does not appear to be the fault of our method of acquiring a template. 

I managed to load the template image into vision assistant by We loaded the acquired image, and template we were using into vision builder by doing as "setup learn pattern" and "learn pattern" operation on the template, then saving and loading into vision assistant.  It appears to do this operation every time you do a pattern match, if your template image does not  have pattern match data with it. 

So after successfully loading the template we used, we were able to duplicate the false failures, which I have attached screen captures of.  With a score threshold of 700, by making the ROI slightly smaller than our original ROI, it will finally find the template with a score of ~890.  Making the template slightly larger, it will not find it.  Also, by MOVING the ROI, we are able to get it to pass fail based on imagery around the portion of the image matching the template.  So we are a bit confused how we are supposed to know what is a good ROI and a bad ROI.  Are there any rough guidelines to follow so we do not get false failures, which was the original indication of this problem?  Is this a bug in the vision pattern matching alogorithm?

Thanks for any input and replies
David Jenkinson
425-383-2654

0 Kudos
Message 2 of 7
(8,121 Views)

David,

    I found a document in our Knowledgebase that refers to this issue:

When you create a pattern matching template in Vision Builder or Vision Assistant, there is extra information saved in addition to the image itself, including overlay information, pattern matching template information, and calibration information. This information lets LabVIEW and Vision Builder know how the template was learned. When you open that template in LabVIEW using the IMAQ ReadFile VI, this extra vision information is not transferred with the image. Likewise, if you try to create a template file using the IMAQ Write PNG File VI the extra vision information is not saved to file with the image, so Vision Builder or Vision Assistant do not recognize it as a valid pattern matching template. To retain the extra vision information with the image, open and create your pattern matching template using the IMAQ Read Image And Vision Info VI and the IMAQ Write Image And Vision Info VI, respectively. These VIs are located in the Vision » Vision Utilities » Files palette.

Let me know if you have any questions!

-Allison S.
Calibration Services
Product Support Engineer
Message 3 of 7
(8,120 Views)
Ok.
So as an added piece of information that I brushed over in my earlier post, I dug down into the "pattern match 2" vi to see what was going on with the template image in that tool.  In there, the template image is queried "IMAQ is vision info present" to see if it has "vision info present".  If it does  not, which our template images have not, vision info is added using the tools "IMAQ setup learn pattern" and subsequently "IMAQ learn pattern".  So I made a small subvi to run on the template in question, which I previously had trouble loading into vision builder, and afterward,l was able to load the template into vision builder.  The resulting screen shots attached in the upper post were resulting from that successful conversion/load of the original template.  So the way I see it, it does not matter if your template has setup/learn pattern steps done prior to saving, because they will be done anyway.  And since I know the template in the end has this required information (otherwise I could not load it into vision assistant), and I still see the strange behavior outlined above and in the screen shots, there is still an underlying problem regardless.  Do you agree?

Let me go one more, and attach the aquired image and template I was working with in vision builder.  We have been assuming the pattern should be found not matter the size of the ROI, but that apparently is not the case.  This particular example even behaves more strangely in that, when you keep the ROI the same, but only move it around, it sometimes finds the template, sometimes not.

Regards,
David Jenkinson
Download All
Message 4 of 7
(8,101 Views)

David,

I am curious as to whether the VIs posted in Allison's reply were helpful to you:  IMAQ Read Image And Vision Info VI  and IMAQ Write Image And Vision Info VI. Have you tried using these?

Regards,

Jasper S

0 Kudos
Message 5 of 7
(8,062 Views)
On one end, we were already using the "write vision info" to save, though it does not have any info to save because none was being generated.  On the loading side, no, but from what I see being done in the patternmatch vi, it adds vision info if none is present anyway.  Correct?  So, the lack of vision info in the template image does not appear to be the source of the problem, since it is auto-generated anyway by the patternmatch vi if it is not present. 

I attached 2 images in my above post, one being the template (which contains vision information), and the acquired image which we used in vision assistant to reproduce our problem.  By simply increasing the ROI, the pattern is not found (see above screen shots).  It would be really great if someone could load those up in their vision assistant and see what I'm seeing, and recommend some general guildelines we should use when creating an ROI and template images, and also the size relationship that the ROI should have vs. the template. 

So really my question is, is the problem with the patternmatch not finding the template based only on ROI size a bug in the vision patternmatch software?  And if not, what are the guidelines we should be using in defining a ROI for a given template?  It seems like we cannot use the entire image as a ROI reliably given our results, so is the guideline to make the ROI as close as possible to the template size?  Is that bad for a different reason?

Any input greatly appreciated.

Thanks
David Jenkinson
0 Kudos
Message 6 of 7
(8,031 Views)
So the mystery of this issue has been solved by a call to Robert Van DeVanter at NI, who has been most helpful in the past as well.

He enlightened us to the behind the scenes operations that are going on with a pattern match.  Apparently a list of "candidates" within the ROI for a match is first built.  The pattern match alogorithm  then sequences through these candidates using a more thorough pattern match to find the template, and determine a score.  If the template is fairly low contrast, which the one in this post is, the number of candidates it sees may or may not include the match we are looking for.  We had our "number of matches requested" set to 1, which behind the scenes tries to find (number of matches requested + X) candidates.  By raising the number of matches requested, we were able to get it to find the  pattern. 

So the issue is understood, and we are implementing the necessary changes in our test routine/process of acquiring templates.  Thought I'd post this here in case someone else has the same issue.

Regards,
David Jenkinson 

0 Kudos
Message 7 of 7
(7,895 Views)