How to split a Connected Component into components , after following particular criteria.????

Hi, After decomposing binary image into different connected components, I want extract each connected component and split a connected component if it has particular number of pixels in it. So that total number of connected components are increased....Is there any way to do that...

 Accepted Answer

Sure. Just loop over CC(i) and use the CC(i).PixelIdxList field to determine the number of components and to apply your splitting criterion. At the very end, modify all the CC(i).NumObjects values.

5 Comments

Sir, If I split a connected component , How will be the total number of connected components updated, will the split connected component share the same label with parent , After splitting each components (splitted if any) should have the different labels...Is it possible with above procedure...
The output of bwconncomp (which is what you should be using) does not assign labels to components. It gives a structure array CC, where each CC(i) contains data on a component. You simply have to make CC longer and update its fields.
Well, the label is implicit, the label of CC.PixelIdxList{i} is i.
Note that CC is scalar. It is the PixelIdxList that is a vector (cell array). But Matt is essentially correct, just had the new half of the split component to the end of the PixelIdxList and adjust the NumObject field:
%e.g. split component 5 into 2 halves:
pixellist = CC.PixelIdxList{5};
pixelhalf1 = pixellist(1:floor(end/2));
pixelhalf2 = pixellist(floor(end/2)+1:end);
CC.PixelIdxList{5} = pixelhalf1; %update component 5 with new list
CC.PixelIdxList{end+1} = pixelhalf2; %add new component
CC.NumObjects = CC.NumObjects + 1; %update object count
Sir, one problem occurred , You have taken example of dividing a connected component into two, How we can do for general (e.g. 3,4,5,....), becuase in pixelhalf1 = pixellist(1:floor(end/2)); pixelhalf2 = pixellist(floor(end/2)+1:end);
How we can tune above statements..

Sign in to comment.

More Answers (2)

pixellist = CC.PixelIdxList{k};
pixelhalf1 = pixellist(1:floor(sizes(k)/2));
pixelhalf2 = pixellist(floor(sizes(k)/2)+1:sizes(k));
CC.PixelIdxList{k} = pixelhalf1;
CC.PixelIdxList{k+1} = pixelhalf2;
But it is not reflected in original image......
Here , I have two connected component, I decomposed one of the connected component into two, but it is not reflected in the original image...

Community Treasure Hunt

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

Start Hunting!