# Binary erode while preserving cell topology

**URL:** <https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499>\
**Category:** Algorithms\
**Tags:** simpleitk\
**Created:** [October 14, 2021, 9:54am UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499 "2021-10-14T09:54:41Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![joachim](https://discourse.itk.org/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.itk.org/u/joachim)\
**Post date:** [October 14, 2021, 9:54am UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499/1 "2021-10-14T09:54:41Z")

</div>

In Slicer using the _Simple Filters_ module, I’ve been doing binary thresholding of a CT volume:

 ![BinaryThreshold](https://discourse.itk.org/uploads/default/original/2X/a/a24838b7ed087e27824593f3c337a314078de321.png)

But I want thinner walls so I thought I could fix this with binary erosion:

 ![BinaryErode](https://discourse.itk.org/uploads/default/original/2X/a/a1c9025066abb0112b1b8507c098f2af6e63331b.png)

The problem is that the black cells starts to grow into each other and the walls disappears (red lines in picture). Is there a way to inflate the black cells without growing them into each other so that the cell topology is preserved? I just want thinner walls. The result doesn’t need to look exactly as the initial image.

I have the problem of finding a good thresholding value on the original CT volume: My thresholding either removes visual walls between the cells or fills up small cells. Could there be a way to postprocess my initial image (for example sharpening edges/shapes?) so I can make a binary image that looks like how we humans see the cells and walls?

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [October 14, 2021, 12:20pm UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499/2 "2021-10-14T12:20:20Z")

</div>

Hello @joachim,

Possibly look into using watershed based segmentation. Take a look at [this jupyter notebook](https://github.com/InsightSoftwareConsortium/SimpleITK-Notebooks/blob/master/Python/35_Segmentation_Shape_Analysis.ipynb), segmentation of bacteria from a 3D Focused Ion Beam Scanning Electron Microscopy. Specifically the section titled “Seed based watershed segmentation”.

---

<div class="post-metadata">

**Author:** ![joachim](https://discourse.itk.org/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.itk.org/u/joachim)\
**Post date:** [October 15, 2021, 2:00pm UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499/3 "2021-10-15T14:00:35Z")

</div>

Thank you, I will have a look at watershed in that notebook. It will take me a little time to get deeper into ITK.

J

---

<div class="post-metadata">

**Author:** ![codeling](https://discourse.itk.org/user_avatar/discourse.itk.org/codeling/32/2214_2.png) [@codeling](https://discourse.itk.org/u/codeling)\
**Post date:** [October 18, 2021, 1:33pm UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499/4 "2021-10-18T13:33:42Z")

</div>

Maybe the [binary thinning filter](https://simpleitk.org/doxygen/latest/html/classitk_1_1simple_1_1BinaryThinningImageFilter.html) might be of interest to you - it keeps all cell walls, but you will get al of them thinned down to a single pixel.

In my experience it does not work too well if the structures to be thinned are too thick in the input image; and we have encountered what seems to be a bug in the current version, leading to additional artefacts in the thinning - but I don’t have the details of that issue handy at the moment.

---

<div class="post-metadata">

**Author:** ![joachim](https://discourse.itk.org/letter_avatar_proxy/v4/letter/j/a87d85/32.png) [@joachim](https://discourse.itk.org/u/joachim)\
**Post date:** [October 18, 2021, 1:43pm UTC](https://discourse.itk.org/t/binary-erode-while-preserving-cell-topology/4499/5 "2021-10-18T13:43:14Z")

</div>

Thanks, I will take a look at the binary thinning filter too 🙂
