Help needed in debugging the code for Identifying round objects ..
显示 更早的评论
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
采纳的回答
更多回答(1 个)
Image Analyst
2011-11-13
0 个投票
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 个评论
Abel Babu
2011-11-14
Image Analyst
2011-11-17
That makes no sense. You must have done something wrong, like omitted a dot or something.
Abel Babu
2011-11-24
类别
在 帮助中心 和 File Exchange 中查找有关 Object Analysis 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!