Help needed in debugging the code for Identifying round objects ..
Afficher commentaires plus anciens
This is a matlab function that i wrote for identifying tound objects.i'm kinda a newbie in image processing so i'm guessing my code is messed up some where.But i don't seem to understand my error.please do help..:)
The code is ::
function [ ] =imagetestfile( im )
%This is a fuction to identify round objects from the given input image
im1=rgb2gray(im);
thresh=graythresh(im1);
im1=im2bw(im1,thresh);
[a b]=bwboundaries(im1);
info=regionprops(b,'Area','Centroid','Perimeter');
i=1;
for k=1:length(a)
q=(4*pi*info(k).Area)/(info(k).Perimeter)^2;
if q>0.80
c{i}=a{k};
info1{i}.Centroid=info{k}.Centroid;
i=i+1 ;
end
end
imshow(im);
hold on
for k=1:i-1
x=info1(k).Centroid(1);
y=info1(k).Centroid(2);
boundary = c{k};
plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 6);
line(x,y, 'Marker', '*', 'MarkerEdgeColor', 'r');
end
hold off
end
Réponse acceptée
Plus de réponses (1)
Image Analyst
le 13 Nov 2011
0 votes
You should be able to get rid of your first loop by doing something like (untested):
isCircle =(4*pi*[info.Area] ./ [info.Perimeter]^2) > 0.8;
That should get the entire "isCircle" array all in one shot without using a loop.
3 commentaires
Abel Babu
le 14 Nov 2011
Image Analyst
le 17 Nov 2011
That makes no sense. You must have done something wrong, like omitted a dot or something.
Abel Babu
le 24 Nov 2011
Catégories
En savoir plus sur Object Analysis dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!