3
votes

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!

1
Share the code you have tried? - Divakar

1 Answers

6
votes

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 )