How to get the coordinates of the center of gravity of various triangles and rectangles on the image?

I would like to get the center of gravity of various (size / gradient) triangles and rectangles drawn on one image. Is there any useful toolbox or functions to get it in MATLAB? In some triangles are partially out of image, only one or two angles are drawn on the image. I'd installed MATLAB last month and am a beginner, so if possible, could you please let me which toolbox/function I should use, with a sample code?

3 Comments

In case of attached file, 5 triangles on the image, this code does not recognize any triangle. I tried to find which function controls this, but I couldn't. Could you please which variable factor I should change?
You forgot to attach the image. I don't know what to change without it. Perhaps change the threshold or the direction of the < or > symbol. Or perhaps you should get rid of the size filtering. I don't really know what you want to find in the image because you didn't post it and didn't explain what "recognize" means. Do you simply want a count? Are there circles and triangles and you want to segment out only the triangles and not the circles? I have no idea.
Sorry, here's the attachment file. Please take a look it.

Sign in to comment.

 Accepted Answer

See my Image Segmentation Tutorial in my File Exchange. It does exactly that.

4 Comments

Thank you so much for your quick advice. I downloaded your suggested file, as you said, this is exactly thing that I wanted to know.
You'll have to explain what the problem is, because from your attached image, in the right image in the middle row, it looks like it's finding them all. Of course the rest of the demo finding nickels and dimes is probably not needed unless you wanted to find large triangles and small triangle.
So say exactly what you want to know. Is it a binary image of the triangles? A binary image or triangles of just a certain size? A vector containing the areas or perimeters of the triangles? What???
And attach your original images, all you attached above was the screenshots, not the actual images themselves.
Thank you for your comments. And sorry for my poor explanations. The left side image is "correct result" (that means, it is same as I expected), the problem is right side one. I'm not sure why this code does not recognize all triangles of right side image, even the both figure sizes of left and right, is almost same. I would like to know, which line's variable number I should change, to detect all triangle's center of gravity. Please see attached tif files, I hope it's to be some helps.

Sign in to comment.

More Answers (0)

Asked:

phi
on 9 Aug 2015

Commented:

phi
on 15 Aug 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!