# Relabeling components with regard to minimum physical object size

**URL:** <https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175>\
**Category:** Algorithms\
**Tags:** simpleitk\
**Created:** [August 14, 2024, 2:51pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175 "2024-08-14T14:51:09Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ibro45](https://discourse.itk.org/user_avatar/discourse.itk.org/ibro45/32/1639_2.png) [@ibro45](https://discourse.itk.org/u/ibro45)\
**Post date:** [August 14, 2024, 2:51pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/1 "2024-08-14T14:51:09Z")

</div>

Hi,

I would like to relabel components with regard to physical size rather than the number of voxels. So a hypothetical `SetMinimumObjectPhysicalSize` rather than `SetMinimumObjectSize`. What would be the most efficient way to do that?

Thank you!

---

<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:** [August 14, 2024, 3:46pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/2 "2024-08-14T15:46:04Z")

</div>

Hello,

Thank you for reposted in a new topic:)

In an ITK image all voxel have the size physical size defined by the “spacing” attribute. So if the components are sorted by number of voxels they are also sorted by the physical size.

The number of voxel can be converted to the physical size with the following formula:

number\_of\_pixel \* \sum\_{i=0}^n spacing[i]

---

<div class="post-metadata">

**Author:** ![ibro45](https://discourse.itk.org/user_avatar/discourse.itk.org/ibro45/32/1639_2.png) [@ibro45](https://discourse.itk.org/u/ibro45)\
**Post date:** [August 14, 2024, 3:57pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/3 "2024-08-14T15:57:48Z")

</div>

Thanks! You’re right. However, when working with a dataset of scans and masks with varying spacing, a fixed number of voxels corresponds to different physical sizes.

My goal is to process each case in my dataset, which may have different spacings, and remove islands smaller than, for example, 1 mm³ in the masks.

---

<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:** [August 14, 2024, 5:44pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/4 "2024-08-14T17:44:20Z")

</div>

You can accomplish that by converting 1mm³ into number of voxels by taking into account image spacing, and call `SetMinimumObjectSize()` with the converted limit.

---

<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:** [August 14, 2024, 5:45pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/5 "2024-08-14T17:45:53Z")

</div>

Of course, if the spacing varies from case to case, the conversion computation will need to be done per case.

---

<div class="post-metadata">

**Author:** ![ibro45](https://discourse.itk.org/user_avatar/discourse.itk.org/ibro45/32/1639_2.png) [@ibro45](https://discourse.itk.org/u/ibro45)\
**Post date:** [August 14, 2024, 6:15pm UTC](https://discourse.itk.org/t/relabeling-components-with-regard-to-minimum-physical-object-size/7175/6 "2024-08-14T18:15:37Z")

</div>

Ah, makes perfect sense, thank you! I was overthinking this one 😅
