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

답변 (2개)

Thorsten
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.
Image Analyst
Image Analyst 2015년 11월 20일

0 개 추천

I just answered that in your other question, but here it is again:
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.

이 질문은 마감되었습니다.

질문:

2015년 11월 20일

마감:

2021년 8월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by