# Can LabelImageToStatisticsLabelMapFilter yield invalid statistics for some labels?

**URL:** https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691
**Category:** Engineering
**Created:** [February 20, 2018, 9:56am UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691 "2018-02-20T09:56:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![grothausmann.roman](https://discourse.itk.org/user_avatar/discourse.itk.org/grothausmann.roman/32/582_2.png) [@grothausmann.roman](https://discourse.itk.org/u/grothausmann.roman)
#### Post date: [February 20, 2018, 9:56am UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691/1 "2018-02-20T09:56:26Z")

</div>

Hello,

LabelStatisticsImageFilter has a ValidLabelValuesContainerType where as  
LabelImageToStatisticsLabelMapFilter has not. To my understanding LabelImageToStatisticsLabelMapFilter only incorporates LabelMapToLabelImageFilter in addion to LabelStatisticsImageFilter, so I’m wondering why ValidLabelValuesContainerType is missing there and whether that is critical concerning the use of any statistic values calculated by the filter.  
I’m using GetNthLabelObject to iterate over the labels:

> <https://github.com/romangrothausmann/ITK-CLIs/blob/eb55ce4/label_stats.cxx>

  
Can some labels have incorrect statistic values?

Thanks for any feedback.  
Roman

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [February 20, 2018, 3:08pm UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691/2 "2018-02-20T15:08:43Z")

</div>

Hello Roman,

You are looking at the wrong filter.

The `LabelImageToStatisticsLabelMapFilter` a wrapper for a composite pipeline of `LabelMapToLabelImageFilter` and [`StatisticsLabelMapFilter`](https://itk.org/Doxygen/html/classitk_1_1StatisticsLabelMapFilter.html). These filters are from the LabelMap module, while the `StatisticsImageFilter` is computed directly on a pair or traditional `itk::Image`s.

---

<div class="post-metadata">

### Author: ![grothausmann.roman](https://discourse.itk.org/user_avatar/discourse.itk.org/grothausmann.roman/32/582_2.png) [@grothausmann.roman](https://discourse.itk.org/u/grothausmann.roman)
#### Post date: [February 21, 2018, 10:05am UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691/3 "2018-02-21T10:05:21Z")

</div>

Hallo Brad,

Thanks for your reply. I’m not referring to the `StatisticsImageFilter` but to the `LabelImageToStatisticsLabelMapFilter` which seems to lack the `ValidLabelValuesContainerType` that the `LabelStatisticsImageFilter` has. Since `LabelImageToStatisticsLabelMapFilter` is a composition (giving statistics for each label) I would expect `ValidLabelValuesContainerType` unless it is somehow wrapped by the `GetNthLabelObject`. As I understand it, both `LabelImageToStatisticsLabelMapFilter` and `LabelStatisticsImageFilter` give statistics for each label concerning the underlying scalar-image.

---

<div class="post-metadata">

### Author: ![blowekamp](https://discourse.itk.org/user_avatar/discourse.itk.org/blowekamp/32/79_2.png) [@blowekamp](https://discourse.itk.org/u/blowekamp)
#### Post date: [February 21, 2018, 2:19pm UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691/4 "2018-02-21T14:19:04Z")

</div>

This is very confusing and I miss spoke before. I had the correct link but incorrect name! I have corrected the prior post now.

There are traditionally there Image and Image as labels. Under these concepts are the [`StatisticsImageFilter`](https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&cad=rja&uact=8&ved=0ahUKEwivnq-nmLfZAhWPY98KHV7zCbsQFggnMAA&url=https%3A%2F%2Fitk.org%2FDoxygen%2Fhtml%2Fclassitk_1_1StatisticsImageFilter.html&usg=AOvVaw36xhmTbbjoroP_EOJE4csq) and the ( which you are referencing ) [`LabelStatisticsImageFilter`](https://itk.org/Doxygen/html/classitk_1_1LabelStatisticsImageFilter.html).

There was introduced a new data structure called a [`LabelMap`](http://www.insight-journal.org/browse/publication/176) which is not an array of pixels but a map of label ids to run-length-encoded labels with associated data. There an MANY filters in the module with MANY composite filters. The filter you are inquiring about `LabelImageToStatisticsLabelMapFilter` utilize the LabelMap which has the separate interface to determine which labels are in the [`LabelMap`](https://itk.org/Doxygen/html/classitk_1_1LabelMap.html). With methods such as `GeNthLabelObject` and `GetLabels`.

---

<div class="post-metadata">

### Author: ![grothausmann.roman](https://discourse.itk.org/user_avatar/discourse.itk.org/grothausmann.roman/32/582_2.png) [@grothausmann.roman](https://discourse.itk.org/u/grothausmann.roman)
#### Post date: [February 21, 2018, 4:29pm UTC](https://discourse.itk.org/t/can-labelimagetostatisticslabelmapfilter-yield-invalid-statistics-for-some-labels/691/5 "2018-02-21T16:29:11Z")

</div>

Many thanks Brad for that clarification.  
So to make sure I understand correctly: Using `GeNthLabelObject` with `LabelImageToStatisticsLabelMapFilter` will ensure that all statistic for any reported label will be valid?  
I.e. iterating over `ValidLabelValuesContainerType` (as in this [example](https://itk.org/Wiki/ITK/Examples/ImageProcessing/LabelStatisticsImageFilter)) is just a (very) different name for iteration over `GetNumberOfLabelObjects` using `GeNthLabelObject` in `LabelImageToStatisticsLabelMapFilter` (as in my code)?
