How about comparing length around the blob and length around the bounding box of the blob, like:
I = imread('pillsetc.png');
Iblob = rgb2gray(I) > 200;
stats = regionprops(Iblob,{'BoundingBox','perimeter'});
stats = struct2table(stats);
stats.Ratio = 2*sum(stats.BoundingBox(:,3:4),2)./stats.Perimeter;
idx = abs(1 - stats.Ratio) < 0.1;
stats(~idx,:) = [];
imshow(Iblob);
hold on
for kk = 1:height(stats)
rectangle('Position', stats.BoundingBox(kk,:),...
'LineWidth', 3,...
'EdgeColor', 'g',...
'LineStyle', ':');
end
Best Answer