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!