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

Respuestas (2)

Thorsten
Thorsten el 20 de Nov. de 2015

0 votos

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 el 20 de Nov. de 2015

0 votos

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.

La pregunta está cerrada.

Etiquetas

Preguntada:

el 20 de Nov. de 2015

Cerrada:

el 20 de Ag. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by