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!