07-07-2022 04:51 PM
I am working with, what looks to me to be, elliptical images of laser spots and I want to use the IMAQ Detect Shapes (Ellipses) function to identify the perimeter of those ellipses, yet I cannot seem to get it to find the ellipse. Here below is an image of the laser spot both before and after it has been thresholded. Yet my LabVIEW code cannot seem to recognize either as an ellipse. I know the code works because I can pass it an image of a ideal (drawn) ellipse and it finds it easily.
I'm hoping that someone can tell me what's wrong and how to fix it.
I have attached an example project folder/code/images (LabVIEW v14). Included in with it is a screenshot of the code being able to find the perfect (artificial) rotated ellipse. A second screen shot shows an attempt with the foregoing actual laser spot image where the code cannot find the ellipse. Note that after not having any luck finding a good combination of settings with the parameter clusters native to these IMAQ functions used as front-panel controls, for faster exploration of the parameter space, I revamped the code to use sliders for the many numeric values that control the image processing. I still did not find a magic combination that worked. Also, as part of the “faster exploration”, the code will make two different sounds depending on whether or not an error has occurred (bad combination of parameters, usually) or if the number of ellipses found has changed.
Solved! Go to Solution.
07-07-2022 05:57 PM
Have you looked into blob tools?
https://www.ni.com/docs/en-US/bundle/ni-vision-concepts-help/page/particle_measurements.html
Once you have a binary image, blob tools are very powerful. They tend to be a little slow.
Thoughts welcome.
Cheers
Robert
07-07-2022 06:31 PM - edited 07-07-2022 06:32 PM
I have a code that detects circles / ellipse perimeter.
But I don't understand what are exactly you are trying to do.
1. Detect the perimeter pixels by image processing?
2. Detect the major / minor axis?
Seems to me that your issue first is to create robust threshold.
I am using threshold by feature method. I know the expected spot size. So I am looking for particular spot size.
Is your threshold works OK?
07-07-2022 11:50 PM
I was trying my code that is not really design for this kind of image.
My images had lower resolution and was on circle.
But you can see the idea from the images.
1. You need good auto threshold. If you know the expected size of the laser spot that can help. I can expand on this subject if you need.
2. After the threshold you need to clean the holes from the ellipse. I recommend morphological operation. Try IMAQ fill holes or IMAQ Morphology (closing)
3. Then you can use find the perimeter by subtracting Image after erosion (IMAQ Morphology) from image after dilation (IMAQ Morphology). Perimeter = image dilation - Image erosion.
4. If you want to find the main axis the you can go from step #2 to blob analysis or alternatively use find ellipse.
07-08-2022 12:05 AM
Here is example how to find perimeter.
07-08-2022 12:26 PM
Thank you for your suggestions. The end goal is to find the geometric center of an ellipse that best fits the perimeter of the image. I have tried using the IMAQ GrayMorphology VI to both dilate and erode (with various numbers of iterations specified) the thresholded image followed by subtraction of the eroded image from the dilated image to get a perimeter (image below) and even with this to work with, the IMAQ Detect Shapes VI fails to find any sort of ellipse that will fit it.
07-11-2022 10:56 AM
Your other option is to use blob analysis to get the major axis and their crossing.
Blob analysis is using different math then detect shape (I am not familiar with the exact math of detect shape). It should always find the major and minor axis of the blob equivalent ellipse.
In that case you need to use the whole blob and not just the perimeter. You should also close all the holes by morphology before the blob analysis.
Blob analysis will use all the pixels inside the blob.
07-12-2022 12:16 PM
I had NI support look at this problem and they too could not find an acceptable set of parameters to use with the IMAQ Detect Shapes/Ellipses to get it to work with my laser spot. I guess that VI is just more picky than it has any right to be given all the parameters that it takes to define a "goodness of fit". On to plan B.
Following AmitShachaf’s suggestion (Thanks!) I did the following and got an alternative working:
The resulting demo (folder of VIs) is attached. (LabVIEW version 14, uses NI Vision Development and OpenG array libraries)
07-20-2022 02:47 PM
After further testing with more images from a variety of sources, I have revised the manner in which I'm finding the perimeter of the ellipse. The prior routine seemed to do OK when it was able to create a filled thresholded ellipse so it could look from the center/inside out to find edge values. However, in the case of one image, I could not get the center of the ellipse to reliably fill in properly so that working from the center out was likely to find bright-to-dark transitions that were not on the actual edge of the ellipse but instead somewhere in its interior. I managed to implement a different method where I take the thresholded image (an array of 0/1 values) and go through it row by row (Y) examining the column values (X) from the outside in (meaning that for each row I work in from the two ends of a row toward the middle) looking for where I find 3 or more non-zero values, indicating that I’ve found an outside left, right or shared edge. This new method doesn’t allow a user to specify the number of points to be used in the curve fit. It instead just returns all (a few thousand for the ellipses in my 5k test images) of the non-zero edge coordinate pairs that it finds. So far this does not seem to be too many to overwhelm the fit-ellipse function (an entire image’s worth of points is however). My new test routine is attached. It too is LabVIEW 2014 and the only external library it requires is the IMAQ Vision one.