shape recognition in a complex image

10 visualizaciones (últimos 30 días)
howa ana
howa ana el 28 de Mzo. de 2018
Respondida: alaa shabeeb el 31 de Dic. de 2019
Hello, I have an image with many shapes , i made some effort to create a code that analyses image and detects shapes (just Reactangle, Traingle, Circle and square ) but it dosen't give a good result , so I need your help to make my code more efficient.
the image below show the first result given
My code
im=imread('formes.jpg');
S=imadjust(im,[.3 .7 .3; .7 .9 .9],[]);
a=rgb2gray(S);
bw=edge(a,'Canny',0.1);
bw = bwareaopen(bw,200);
bw = imfill(bw,'holes');
bw=bwpropfilt(bw,'Area',50);
L = logical(bw);
s = regionprops(L, 'centroid','BoundingBox','PixelList' );
dt = regionprops(L, 'area');
dim = size(s);
BW_filled = imfill(bw,'holes');
boundaries = bwboundaries(BW_filled);
imshow(S);
hold on;
for k=1:dim(1)
b= boundaries{k};
rectangle('Position', [s(k).BoundingBox(1),s(k).BoundingBox(2), s(k).BoundingBox(3),s(k).BoundingBox(4)],...
'EdgeColor','b', 'LineWidth', 3)
dim = size(b);
for i=1:dim(1)
r{k}(1,i) = sqrt ( ( b(i,2) - s(k).Centroid(1) )^2 + ( b(i,1) - s(k).Centroid(2) )^2 );
end
a=max(r{k});
b=min(r{k});
c=dt(k).Area;
dolech=a-b;
vuong = c/(4*b^2);
chunhat=c/(4*b*(a^2-b^2)^0.5);
tamgiacdeu=(c*3^0.5)/((a+b)^2);
if dolech < 10
text(s(k).Centroid(1)-20,s(k).Centroid(2),'circle','color','b');
elseif (vuong < 1.05 ) && (vuong > 0.95 )
text(s(k).Centroid(1)-20,s(k).Centroid(2),'square','color','b');
elseif ((chunhat <1.05) && (chunhat >0.95))
text(s(k).Centroid(1)-20,s(k).Centroid(2),'rectangle','color','b');
elseif (tamgiacdeu < 1.05 ) && (tamgiacdeu > 0.95 )
text(s(k).Centroid(1)-20,s(k).Centroid(2),'triangle','color','b');
end
end
%imshow(BW_filled);

Respuestas (2)

Image Analyst
Image Analyst el 29 de Mzo. de 2018
I don't think that's a good way. What I'd do is to use stdfilt() to find regions with low standard deviation. Threshold to find areas with low stddev, then regionprops to find the areas. Then determine what area is the smallest allowable and call bwareafilt() or bwareaopen() to throw out small, noise blobs. Then find the boundaries and centroid and find the distances from the centroid to the boundaries. Look for peaks, and count peaks to determine the number of vertices.
Once you have the binary image, see my attached shape recognition demo to see how to find peaks in the centroid to boundary distances.

alaa shabeeb
alaa shabeeb el 31 de Dic. de 2019
dear
what is meanning for the equations follwing
what is meanning the follwing
a=max(r{k});
b=min(r{k});
c=dt(k).Area;
dolech=a-b;
vuong = c/(4*b^2);
chunhat=c/(4*b*(a^2-b^2)^0.5);
tamgiacdeu=(c*3^0.5)/((a+b)^2);

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by