MATLAB: Finding number of connected components of a single value of pixel

digital image processingimage processingImage Processing ToolboxMATLAB

I have an image in the form of a matrix:
A zoomed-in portion of the upper right part is:
I would like to remove the disconnected black region, i.e. set that particular region's pixel values equal to that of the white region around it. I tried finidng the number of connected components using
CC = bwconncomp(filled_win);
but I am getting only 1 connected component.
CC.Connectivity = 8, CC.ImageSize = [416, 349]
CC.NumObjects = 1, CC.PixelIdxList = 1 X 1 cell
I have attached the relevant .mat file for reference. Can someone please help me with this?

Best Answer

If you want to find the two black (false) components, then you need to pass the complement and use 4-connectivity (no diagonal connections).
filled_win = imbinarize(filled_win);
CC = bwconncomp(~filled_win,4);
filled_win(CC.PixelIdxList{2}) = true;
What you found before was the single white component that is the white backgrund and the "boundary", returned as one object (as they are actually connected diagonally).
Related Question