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!