Machine Vision

Showing results for 
Search instead for 
Did you mean: 

How to get a line of pixels after an edge?

This may end up boiling down to an algebra/geometry problem but, here it goes anyway.


I have a foil lid that is being applied to a plastic tub. I want to inspect the seal edge of the foil to see if any product has been squeezed out during the sealing process.


I am using "IMAQ Find Straight Edges 3" to find both the tub edge and the foil lid edge. (No problems here...)

Next I want to pull the a few lines of pixels that are on the tub side of the foil... This is where I think I am trying to over think it...


I can calculate the line equation based on the results from the "IMAQ Find Straight Edges 3" vi. It also give me an angle (which I will verify in the morning). So to get the lines I need I need to move 1 pixel at a time away from the foil edge... This is where I belive I am over thinking it... 

Could I simply define a ROI box based that one edge is the line indicated by the "IMAQ Find Straight Edges 3" for the foil edge and the defind the width of the box as say 5 pixels... hmmm back to the geometry calculation again...


Ok, I am going to post this to see if anyone has any ideas or know of some function or vi that would make this simpler. Tomorrow I will start working the math to calculate where the end points need to be and then see what I get when I pull that from an image. 


A few things that I have to keep in mind with this. From image acqusition to posting the pass/fail to the IO I have about 600 ms. I want to inspect the full parimiter of my foil lid so that will give me 4 sides + 3 curved corners and 1 sharp corner. Right now the "IMAQ Find Straight Edges 3" is very fast and processing the segments should be faster then how I was doing it before so I should be good on time but if I try to get to fancy with the math I could slow things down to much. And just to make things intresting I need to process 10 images (yes I am planning on doing this in parallel on a multi-core windows system) in each 600 ms window. 


Thank you for looking at this with me. I will post my final solution once I have it figured out.


0 Kudos
Message 1 of 7



Could you post a diagram or a sample image so we can get a better idea of what we are looking at?



Rebecca B. 

Becca B.
Product Marketing
National Instruments
0 Kudos
Message 2 of 7

If you know the pixel coordinates of the edge, it is easy to retrieve pixel values nearby.  Just use IMAQ GetPixelValue after adjusting the X or Y value as needed.



Bruce Ammons
Ammons Engineering
0 Kudos
Message 3 of 7

Here is an image of one edge. 


Edge of tub and lid.jpg


The red lines indicate the detected edges. First I found the edge of the tub. I created a coordinate system based on that line then found the edge of the tub.

I will try the Get Pixel Value to see if that will work now that I am using the coordinate systems. 

I am also going to try a simple ROI to see if i can position it based on the new coordinate system.

What I am trying to do is retrieve a strip that is between the two red lines that is about ~10 pixels wide. 


Once I get this figured out my next steps will be to do this for the curved edges. 

I was thinking about trying to make a custom ROI. Then I would use the method above to find the Left and Bottom Lid edges and align the ROI with those edges then rotate the ROI to align to the right and top. The foil lid will have small variances but they should be very consistent. this ROI would then have in it the area already defined that I want to analyze.  If I could figure out how to create a Dynamic ROI then I would get it to follow the lid and tub edge and I could just analyze the exposed tub edge. 


I have included a sample image that doesn't have anything "detected"

Clean Sample edge.jpg

0 Kudos
Message 4 of 7

You can extract all the pixels along a line, so you could move your line to the left one pixel, extract those values, and repeat until you have the strip you need.


Do you have any examples where the seal failed?  Seeing good and bad examples provides more information for us to make suggestions.  There might be a much easier way to detect the leakage, perhaps using color thresholding.  For example, you could threshold the gold color and create a binary mask.  Expand the mask 10 times using binary morphology, then subtract the original mask.  This would give you an image of a 10 pixel strip going all the way around the edge.  This might be easier to analyze.



Bruce Ammons
Ammons Engineering
0 Kudos
Message 5 of 7
I will add some more pictures late today or monday.
The lighting is not 100% consistent across the entire surface. To get around this on the last version I evaluated the seal edge in zones. The other factor is the foil lids, they are very reflective. We have a polarized filter that helps with this but they don't always get aligned correctly.

However I will experiment with you suggestion Bruce. I have quite a few images I can experiment with to see how stable it ends up.

Thanks for the comments everyone!

0 Kudos
Message 6 of 7

for your gol you need just this vi that i atach in image work with them you can find any thing you need 


0 Kudos
Message 7 of 7