Now I want to detect the shapes from this binary image.
First I started with the ‘circle’ shape. We know that the circularity for circle is 1. So we take near about 1 in if statement. And we can see clearly in image that there are 2 circles and also there are 2 blobs having values near about 1 above.
So here is my getShape.m function:
function ans = getShape(im, shape)
[L,mx] = ilabel(im);
b = iblobs(im);
array = zeros(1,mx); %created a matrix for storing labels of matching blobs
for i = 1:mx
if(shape=='circle' & b(i).circularity>=0.9 & b(i).circularity <=1.1)
array(i) = b(i).label;
exclude = array(array~=0); %exclude the extra zeros added
ans = b(exclude); %here the resulting blobs's features are stored
To use this function we must be in same directory of where the function is stored (in MATLAB). We can use this function as: