I used connected component labeling algorithm (bwconncomp) to label the different parts of a binary image (MATLAB). Now i need to calculate the area of different labels and remove the labels with smaller area. Can i use the default area finding command or is there any specific commands for that in matlab…Help..
I used connected component labeling algorithm (bwconncomp) to label the different parts of a
Share
From the documentation:
The final field in CC is
PixelIdxList, which is:You can find the area of each label by looking at the length of the corresponding entry in the cell array. Something like:
The PixelIdxList is a cell array, each member of which contains the linear indexes of the pixels present in that connected component. The line of code above finds the length of each cell in the cell array – i.e. the number of pixels in each connected component.
I’ve used
cellfunto keep the code short and efficient. A different way of writing the same thing would be something like:For each connected component, you can then find the size of that component in pixels by accessing an element in areas_in_pixels: