Turn pixels in connected components to zero based on logical array

I want to switch all pixels in connected components to zero, based on a logical array.
I have CC.PixelIdxList obtained from bwconncomp performed on binary image BW.
I have a logical array, X, the size of CC.PixelIdxList, based on which I would like to turn pixels in CC.PixelIdxList{y} to zero if the value in X=0 at index y.
I tried this:
BW(CC.PixelIdxList{y}) =X;
where y is just an array of numbers from 1 to the size of CC.PixelIdxList.
But it is not working, there must be another way that I cant think of.
Appreciate any suggestions. Thanks.

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by