0
The program in Matlab has to have as input an image (black and white) and as output a string with the format name of this image (circle, star, rectangle, square, ellipse). the code I made this recognizing some of these figures, but I would like some suggestions and tips to improve it.
clear all
close all
im=imread('circulo_fr.jpg');
img=rgb2gray(im);
BW=im2bw(img);
stats=regionprops(BW,'Perimeter','Area','Centroid','BoundingBox');
figure,imshow(BW);
hold on
for k=1:length(stats)
thisboundingbox=stats(k).BoundingBox;
if stats(k).Area>10000
retangulo('Position',[thisboundingbox(1), thisboundingbox(2), thisboundingbox(3), thisboundingbox(4)], 'EdgeColor','r','LineWidth',2);
else
retangulo('Position',[thisboundingbox(1), thisboundingbox(2), thisboundingbox(3), thisboundingbox(4)], 'EdgeColor','b','LineWidth',2);
end
if stats(k).Perimeter^2/stats(k).Area > 18
text(stats(k).Centroid(1),stats(k).Centroid(2),'Triangulo','Color','r');
elseif stats(k).Perimeter^2/stats(k).Area < 14.3
text(stats(k).Centroid(1),stats(k).Centroid(2),'Circulo','Color','g');
else
text(stats(k).Centroid(1),stats(k).Centroid(2),'Quadrado','Color','b');
end