Matlab: connected components analysis

43 Views Asked by At

From the following binary raster:

R = [0 1 0 0 0 0 1 1;
     0 1 1 0 0 1 1 0;
     0 1 0 0 0 0 1 0;
     0 0 0 1 1 0 0 0;
     1 0 1 0 0 0 1 1];

I would like to remove all 4-connected components with less than 3 pixels.

Initially, the amounts of connected components are evaluated:

CC = bwconncomp(R,4);
L  = labelmatrix(CC);
IC = CC.PixelIdxList;
np = cellfun(@numel, IC);

Subsequently, 4-connected components with less than 3 pixels are found:

idxs = find(np < 3)

However, the final attempt to remove the connected components from the input raster R is not successful:

R(IC{idxs}) = 0;   %Result: 4-D double 

The output raster is converted to "4D" matrix. This may be caused by incorrect work with the output cell of cells, but I am not sure...

Thanks for your help.

0

There are 0 best solutions below