How to extract labels of connected components?

I have used the itk::ConnectedComponentImageFilter. For each slice I have a certain number of connected component. I want to obtain a label associated to each of these ones, but with the following code I obtain only one label for each slice.

using ConnectedComponentImageFilterType = itk::ConnectedComponentImageFilter<ImageTypeUC, ImageTypeUC, ImageTypeUC>;
ConnectedComponentImageFilterType::Pointer connesso= ConnectedComponentImageFilterType::New();
connesso->SetInput(ITKIMAGE);
connesso->GetFullyConnected();
connesso->GetObjectCount();
connesso->Update();
connesso->GetOutput();
cout << "Number of connected components: " << connesso->GetObjectCount() << ‘\t’;
cout << "Labels associated: " << connesso->GetOutput() << ‘\t’;

Output image type (second template parameter) needs to be large enough to accommodate all the components. You are currently using ImageTypeUC for it. Try US or UL. If your connesso->GetObjectCount() is greater than 255 that is almost certainly the problem.

So what is the solution to get the labels of all the connected components in each slice

is there any way that we can see size and location of each connected componenent using label

sorry i am new to itk

Take a look at SliceBySliceImageFilter or ProcessA2DSliceOfA3DImage example.

1 Like