How can I differentiate different polygon shapes in image
5 views (last 30 days)
Show older comments
I want to write some code which can help me to classify images according to the polygon shape it contains, such as an image contains a triangle, then system should return "Triangle", if it contains a square then it should return "Square", one image contains only one polygon shape. I have a basic idea of coding, but I am not sure how can I implement those functions, this is the coding structure I came up with:
containSquare = false;
containTriangle = false;
containPentagon = false;
function checkForSquare ()
%if there is square
containSquare = true;
end
function checkForTriangle ()
%if there is Triangle
containTriangle = true;
end
function checkForPentagon ()
%if there is Pentagon
containPentagon = true;
end
return result
and this is a sample image:

any help would be appreciated.
1 Comment
Answers (1)
Image Analyst
on 23 Apr 2017
That's exactly what my demos do. Basically you find the centroid and make a profile of the radius as you go around the shape. Then count the number of peaks. The number of peaks will be the number of vertices and from that you know the polygon type.
2 Comments
Image Analyst
on 23 Apr 2017
Circularity is not such a good method when the polygons start to become more rounded. I suggest you use the peak finding method instead.
See Also
Categories
Find more on Graph and Network Algorithms in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!