Help me understand this code
정보
이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.
이전 댓글 표시
a = imread('circles.png'); x=[ 1 -2 1]; y=[ 1; -2; 1]; gx=filter2(x,a); gy=filter2(y,a); g=sqrt(gx.^2 + gy.^2); [r c]= bwlabel(g,4) This code will find out how many objects are in the image 'circles.png' However I don't understand how it did it. Can someone please explane how this code works. Thanks
댓글 수: 0
답변 (2개)
Thorsten
2015년 11월 20일
0 개 추천
gx and gy mark edges in the image in x and y direction. g is an image of the edges. You have 5 distinct edges in g, the outer boundary of all circles and 4 inner holes. These are returned by bwlabel.
댓글 수: 0
Image Analyst
2015년 11월 20일
0 개 추천
Whoever used that method did so because they wanted to find edges, rather than find an exact submatrix like you asked for. They are basically finding the gradient magnitude manually rather than using the preferred built-in functions imgradient() or imgradientxy(). Then they label the edges, which, assuming the edges are completely closed around the circle, will identify each ring/perimeter as a separate connected blob. It doesn't have anything at all to do with circles, except that they were in the demo image. The same code would find perimeters of any objects of any shape whatsoever. That code doesn't have anything at all to do with what you asked for.
댓글 수: 0
이 질문은 마감되었습니다.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!