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

**URL:** <https://discourse.itk.org/t/trying-to-extract-stats-from-a-dicom-image-after-using-watershed-segmentation-and-relabeling-components/3930>\
**Category:** Engineering\
**Tags:** labels, simpleitk, python\
**Created:** [March 5, 2021, 6:09am UTC](https://discourse.itk.org/t/trying-to-extract-stats-from-a-dicom-image-after-using-watershed-segmentation-and-relabeling-components/3930 "2021-03-05T06:09:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 5, 2021, 6:09am UTC](https://discourse.itk.org/t/trying-to-extract-stats-from-a-dicom-image-after-using-watershed-segmentation-and-relabeling-components/3930/1 "2021-03-05T06:09:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Diego\_C](https://discourse.itk.org/user_avatar/discourse.itk.org/diego_c/32/279_2.png) [@Diego\_C](https://discourse.itk.org/u/Diego_C)\
**Post date:** [March 5, 2021, 6:17am UTC](https://discourse.itk.org/t/trying-to-extract-stats-from-a-dicom-image-after-using-watershed-segmentation-and-relabeling-components/3930/2 "2021-03-05T06:17:08Z")

</div>

It looks like I need to use `LabelStatisticsImageFilter` instead?

What is the difference between `LabelImageStatisticsImageFilter` and `LabelStatisticsImageFilter`?

Thanks
