Auto recognizing of shapes and measuring length and width

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Auto recognizing of shapes and measuring length and width

meir
I'm sure it must be pretty simple but I've been breaking my head over it in the last few days. Would be extremely grateful if someone could help me out with this.
Have a set of images with different straight-edged shapes lying in different orientations. What I need to end up with is the length and width of the rectangular shapes.
Running into three issues

1.After I threshold the image I select one of the shapes with the wand. But when I measure it I get the length and width of the bounding rectangle. Isn't there a way for ImageJ to straighten the object and measure it accurately?

2. When the objects are touching or overlapping, the analyze particles function will recognize them as one. (In second image) Is there a way to change the analyze particles function to only recognize particles that conform to a specific shape.

2.Is there a way to write a macro that will auto analyze all the images and recognize and measure each shape separately?

first image: http://postimg.org/image/yc78dkxmr/
second image: http://postimg.org/image/krtg9g0p9/

Thanks a lot!
Meir

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Auto recognizing of shapes and measuring length and width

Kenneth Sloan-2
These images don’t look all that challenging, but…you are bumping up against the boundary between “image processing” and “scene analysis”.  The difference is that “scene analysis” takes advantage of (and requires - there’s the rub) a model of the world that your camera is looking at.  The bottom line is that there is probably not a built-in function, and it is probably difficult to do what you want as a macro.  On the other hand, it looks fairly easy for someone willing to write (or hire someone to write) some Java code.

Here is how I would attack the problem:

a) segment the image into “foreground”/“background”.  This looks easy, with the caveat that you’ll want to remove the darker parts of the objects so that you get clean boundaries.

b) use something like the Hough Transform, with some post-processing to identify all extended edge elements.  Another possibility is to directly detect (probably with template matching) the “obvious”
long, straight boundaries.  Some of the edges on the non-quadrilateral objects might be a bit challenging, but that’s probably a matter of tweaking parameters.

c) analyze the collection of extended edge-elements to match them with your model of what your objects look like.  This model would include # of sides and size.  With a little work, this would allow you to recognize most (perhaps not all) overlapping objects.

It’s also possible to use the Generalized Hough Transform to directly model the shapes you are looking at, as long as you have only a small number and the scale does not vary too widely.  I suspect that direct template matching would also work.

Based on the images you posted, I would probably start by reducing the size of the images a bit - this might help with filling in the darker regions of the objects, and would certainly speed things up.

If you can already successfully segment foreground/background, and your only problem is rotation and overlap, then you can jump directly to step c).  Apply a Hough transform to find edges, a Generalized Hough Transform to find objects, or use template matching.

For completeness (which means you might want to stop reading here…), another technique that would work for the seperable objects is to use a “rotating calipers” approach.  The simplest version of this involves projecting the image function onto a series of lines and many orientations - extracting the function w(angle) - the width of the object as a function of projection angle.  From w(angle) it is easy enough to extract orientation and size information for all of your objects - but it only works for non-overlapping objects.

Hint to developers: if w(angle), given a single segmented, isolated particle does not already exist, I think it might be a good addition to the toolbox.  If it’s already there - great!  If not, consider adding it.


Kenneth Sloan
[hidden email]
"La lutte elle-même vers les sommets suffit à remplir un coeur d'homme; il faut imaginer Sisyphe heureux."


--
Kenneth Sloan
[hidden email]


> On Nov 10, 2014, at 08:54 , Meir Harry <[hidden email]> wrote:
>
> I'm sure it must be pretty simple but I've been breaking my head over it in the last few days. Would be extremely grateful if someone could help me out with this.
> Have a set of images with different straight-edged shapes lying in different orientations. What I need to end up with is the length and width of the rectangular shapes.
> Running into three issues
>
> 1.After I threshold the image I select one of the shapes with the wand. But when I measure it I get the length and width of the bounding rectangle. Isn't there a way for ImageJ to straighten the object and measure it accurately?
>
> 2. When the objects are touching or overlapping, the analyze particles function will recognize them as one. (In second image) Is there a way to change the analyze particles function to only recognize particles that conform to a specific shape.
>
> 2.Is there a way to write a macro that will auto analyze all the images and recognize and measure each shape separately?
>
> first image: http://postimg.org/image/yc78dkxmr/
> second image: http://postimg.org/image/krtg9g0p9/
>
> Thanks a lot!
> Meir
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html