MATLAB: Detect shape in image

digital image processingimage processingImage Processing Toolbox

how i can use code regionprops to detect square,circle and other shapes using only one command?

Best Answer

You can't do it in one command. The best you can do is a few commands, depending on what you mean by "detect." Basically you have to measure a bunch of things and figure out which of those, in which ranges, uniquely identifies each type of shape you want to "detect." A good starting place is to computer the "circularity" which is:
allAreas = [measurements.Area];
allPerimeters = [measurements.Perimeter];
circularities = allPerimeters.^2 ./ (4*pi*allAreas);
A perfect circle is 1 and other shapes will lie in certain ranges above 1. There may be overlap of the ranges for shapes that are indeterminate, such as a triangle with bulging sides (almost rounded).
Related Question