Trying to extract stats from a DICOM image after using watershed segmentation and relabeling components

Hi!

I have a pipeline where I do watershed segmentation and then I filter the number of components retaining only those with a given size. My code looks like this:

im_watershed = sitk.MorphologicalWatershed(im_gradient, level=5, markWatershedLine=False, fullyConnected=False)

rel_filter = sitk.RelabelComponentImageFilter()
rel_filter.SetMinimumObjectSize(42875)
im_relabeled = rel_filter.Execute(im_watershed)

Now, according to rel_filter I obtain 4 components after filtering by size:

print(rel_filter.GetOriginalNumberOfObjects()) # prints 1404
print(rel_filter.GetNumberOfObjects()) # prints 4

Then I want to use these 4 components to extract stats from my original image (a.k.a image). So, I do this:

stats = sitk.LabelIntensityStatisticsImageFilter()
stats.Execute(image, im_relabeled)
n_labels = stats.GetNumberOfLabels()
print(n_labels) # prints 1007

I expect n_labels to be 4 (as I obtained four components previously) but the number that I get here is 1007.

It looks like my assumption is incorrect?

How can I obtain stats from the 4 regions that I identified with the RelabelComponentFilter ?

Thanks,

Diego

It looks like I need to use LabelStatisticsImageFilter instead?

What is the difference between LabelImageStatisticsImageFilter and LabelStatisticsImageFilter?

Thanks