Machine Vision

cancel
Showing results for 
Search instead for 
Did you mean: 

Problem Iterating Through Image via ROI Segments

Dear NI Community,

 

I am having problems iterating through an image via ROI segments and have not been able to figure out a solution.  My program currently does the following:

 

1.) I apply an edge detection algorithm and extract a ROI to use as a template via the IMAQ IVA Mask from ROI" function.

2.) I pass the extracted ROI into an analysis sub VI and get statistics of the template (mean, std. dev, etc.).

3.) I iterate through the original image by the template size and extract the region I am currently at using the "IMAQ IVA Mask from ROI" function.  I pass the extracted image into the analysis subVI to get its statistics. 

4.) I compare the statistics of the template to the statistics of the ROI.  After I do this for the whole image, I continue on with the program.

 

My problem arises between steps 3 and 4.  The first time I extract a region from the image, everything works fine, however, for subsequent iterations, the extracted image ROI does not update (seen via a probe on the image wire coming out of the "IVA Mask from ROI" function).  I am assuming that I somehow have to clear the image after the first iteration, or I have to create a new image that I can write to the second, third, fourth, etc. times I extract a region for analysis from the original image.   I thought I solved this by recalling the original image from the buffer at the beginning of the loop, but this still does not solve the problem.

 

Any help you could provide would be greatly appreciated.

 

Thank you in advance,

German Coast Guard

0 Kudos
Message 1 of 14
(5,032 Views)

Hi German Coast Guard,

 

Would you mind posting your VI?  Thanks!

 

Kristen H.

0 Kudos
Message 2 of 14
(5,017 Views)

Hi Kristen,

 

Absolutely.  Please see the attached zip file for the files needed to run the VI.

 

Thanks,

German Coast Guard

0 Kudos
Message 3 of 14
(5,006 Views)

Hi GCG

 

I've got just one general advice. Those IVA VIs are used only by Vision Assistant when generating LabVIEW code. However, I also have some bad experience when trying to build something on top of the generated VI. It's usually a better idea to have a look at how the Vision Assistant is doing that, but then write your VI from scratch, without using the IVA VIs. The functionality of the IVA VIs is not well documented and the pure LabVIEW code can be written much cleaner than the generated one.

 

Vladimir


View my profile on LinkedIn
0 Kudos
Message 4 of 14
(4,988 Views)

Hi German Coast Guard!

 

 

Thank you for posting your VIs.  Could you explain what you want as an end result?  In other words, what is your goal for this VI?  Thanks!

 

Kristen H.

0 Kudos
Message 5 of 14
(4,973 Views)

Hi Kristen,

 

The goal of this VI is to compare the statistics of an extracted template to image regions of the same size extracted from a picture.  If the mean of the current region is plus/minus within one standard deviation of the template mean, the region will be marked as a match.  The image is iterated through by squares of the template size.  This information is then passed to another VI (which has not yet been written) that will take the pixel locations of the match, and create a binary array the same size as the original image and fill the matching locations of the binary array with 1.

 

For example:  If my template size is a 25x25 pixel image, I have a 640x480 base image and the upper left hand corner of the current region I am extracting from the 640x480 image is located at (350,250).  A 25x25 image is extracted from the 640x480 image using the IVA ROI function and is passed to the template analysis VI which calculates the region statistics.  If it matches, the pixel locations of the extracted image are passed to another VI, which fills in the square area between (350->375,250->275) of the binary array with a 1.

 

The problem I am encountering is this: The first time I run the VI, a 25x25 region with the upper left hand corner at (0,0) is successfully extracted from the image, and analyzed as it should be.  However, during the next iteration, a 25x25 region with the upper left hand corner at (25,0) should be extracted (based on the arguments I am passing to the IVA ROI function, which by probing indicate that the numbers used to define the bounding box are correct), but the image wire indicates that the extracted region did not change from the previous iteration (i.e. the picture of the extracted region does not change and looks the same).  This is true for all subsequent iterations.  Therefore, I need to find a way to fix this, so that a new region is successfully extracted and the image wire is updated for each iteration of the loop. 

 

I believe that this problem is due to the fact that the image that is in the wire after the first IVA ROI extraction is not being overwritten.  I have encountered a similar situation before, but was able to resolve it "overwriting" the image in the wire by recalling an older image from the buffer.  I tried to do the same here, but as you can see, this does not solve the problem.

 

Thank you for your continued help,

German Coast Guard

0 Kudos
Message 6 of 14
(4,962 Views)

Hi German Coast Guard!

 

Thanks for your thorough response.  I assume you are wanting to do this with the image you included in the zip file? 

 

Kristen H.

0 Kudos
Message 7 of 14
(4,943 Views)

That is correct.  However, this could be applied to any image.  I attached the image so that the package could be executed by other users easily.

 

Thank you,

German Coast Guard

0 Kudos
Message 8 of 14
(4,941 Views)

Hi German Coast Guard!

 

Thank you for the clarification.  I am looking through your code and testing different things out.  I will post back soon!

 

Kristen H.

0 Kudos
Message 9 of 14
(4,925 Views)

Hi Kristen,

 

How are you?  I was wondering if you had made progress on this issue.


Thank you for your time,

German Coast Guard

Message Edited by German Coast Guard on 03-02-2009 02:31 PM
0 Kudos
Message 10 of 14
(4,889 Views)