# HausdorffDistance on an image with multiple Labels

**URL:** https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582
**Category:** Beginner Questions
**Created:** [November 15, 2021, 10:20am UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582 "2021-11-15T10:20:38Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![toladner](https://discourse.itk.org/user_avatar/discourse.itk.org/toladner/32/2377_2.png) [@toladner](https://discourse.itk.org/u/toladner)
#### Post date: [November 15, 2021, 10:20am UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/1 "2021-11-15T10:20:39Z")

</div>

I’m evaluating the predictions of a lung lobe segmentation model using the HausdorffDistanceImageFilter.  
Thus, I’m passing the ground truth and the prediction (both have equal size with 6 labels) into the image filter.

I’m a bit puzzled about the result, that is the results make sense that worse models have a higher distance and better models have a smaller distance. But I’m a bit puzzled about the unit of the results and how multiple labels change the results.  
In the documentation, I only find the explanation for sets.

Additionally, what’s the difference between GetHausdorffDistance and GetAverageHausdorffDistance?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 15, 2021, 2:06pm UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/2 "2021-11-15T14:06:29Z")

</div>

Looking at the code explains it:

> <https://github.com/InsightSoftwareConsortium/ITK/blob/828453d1bf61c487310d2d8c9570093e08798a40/Modules/Filtering/DistanceMap/include/itkDirectedHausdorffDistanceImageFilter.hxx#L139-L148>

> <https://github.com/InsightSoftwareConsortium/ITK/blob/828453d1bf61c487310d2d8c9570093e08798a40/Modules/Filtering/DistanceMap/include/itkHausdorffDistanceImageFilter.hxx#L136-L145>

Average is distance average for all pixels, HausdorffDistance is maximum distance among all pixels.

---

<div class="post-metadata">

### Author: ![toladner](https://discourse.itk.org/user_avatar/discourse.itk.org/toladner/32/2377_2.png) [@toladner](https://discourse.itk.org/u/toladner)
#### Post date: [November 15, 2021, 2:30pm UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/3 "2021-11-15T14:30:20Z")

</div>

Thanks a lot!

Can you also explain how this works with multiple labels? Is each label considered as a set and then the hausdorff distance is calculated for the given images per label/set and then the maximum of those is returned?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 15, 2021, 3:00pm UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/4 "2021-11-15T15:00:15Z")

</div>

From the documentation, I understood that all non-zero pixels are considered to belong to the same label. So if you want per label measures, you would use threshold filter to extract the appropriate label before measuring distance.

---

<div class="post-metadata">

### Author: ![toladner](https://discourse.itk.org/user_avatar/discourse.itk.org/toladner/32/2377_2.png) [@toladner](https://discourse.itk.org/u/toladner)
#### Post date: [November 18, 2021, 8:41am UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/5 "2021-11-18T08:41:19Z")

</div>

Thanks again. Do you know if this happens for the dice coefficient calculation as well?

---

<div class="post-metadata">

### Author: ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)
#### Post date: [November 18, 2021, 2:56pm UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/6 "2021-11-18T14:56:19Z")

</div>

[LabelOverlapMeasuresImageFilter](https://itk.org/Doxygen/html/classitk_1_1LabelOverlapMeasuresImageFilter.html) seems to treat the different labels separately.

---

<div class="post-metadata">

### Author: ![BennoGesierich](https://discourse.itk.org/user_avatar/discourse.itk.org/bennogesierich/32/3237_2.png) [@BennoGesierich](https://discourse.itk.org/u/BennoGesierich)
#### Post date: [March 2, 2023, 1:15pm UTC](https://discourse.itk.org/t/hausdorffdistance-on-an-image-with-multiple-labels/4582/7 "2023-03-02T13:15:09Z")

</div>

> [@dzenanz](#):
>
> Average is distance average for all pixels

I would be interested to understand the GetAverageHausdorffDistance function more in detail. Is it calculating the average distance for all points (pixels/voxels) in both masks, directly? Or is it first calculating separate (directed) average distances for each of the two masks to the respectively other mask and then calculating in a second step the average across these two averages? The code suggests the second procedure, but I am not a C++ programmer and not sure. And is GetAverageHausdorffDistance also working on the point clouds (all pixels/voxels) as the GetHausdorffDistance function does, or is it working the surface pixels/voxels instead?
