Brain Marker
Brain Marker

Reputation: 83

finding connected component of a given pixel in binary image

i want to find a connected component of a given pixel, and then test if another pixel belong to this component in matlab.

CC = bwconncomp(BW);
numPixels = cellfun(@numel,CC.PixelIdxList);
...

how to loop for all CC, and for each one, and test if a given pixels belong to it!

Upvotes: 3

Views: 927

Answers (1)

Shai
Shai

Reputation: 114976

I think you'd be better off representing the connected components as a labeled image

lb = bwlabel( BW );

Now, each pixel in BW has a label (1..N) while background pixels remains 0.
You can test for pixel x,y what is its label:

 lb( y, x )

You can compare the labels of two pixels

 lb( y1, x1 ) == lb( y2, x2 )

Upvotes: 6

Related Questions