# BinaryPruningImageFilter

**URL:** <https://discourse.itk.org/t/binarypruningimagefilter/4924>\
**Category:** Beginner Questions\
**Tags:** itk, itk-releases, simpleitk, python\
**Created:** [April 19, 2022, 12:35pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924 "2022-04-19T12:35:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![assia855](https://discourse.itk.org/user_avatar/discourse.itk.org/assia855/32/2642_2.png) [@assia855](https://discourse.itk.org/u/assia855)\
**Post date:** [April 19, 2022, 12:35pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924/1 "2022-04-19T12:35:57Z")

</div>

Hello, I want to apply this function on my data, but I couldn’t understand the documentation and there’s no example. I would like an example on how can I apply it. Thanks in advance.

---

<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:** [April 19, 2022, 1:04pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924/2 "2022-04-19T13:04:33Z")

</div>

Hello @assia855,

First , see the wikipedia explanation of [binary pruning](https://en.wikipedia.org/wiki/Pruning_(morphology)#:~:text=The%20pruning%20algorithm%20is%20a,unwanted%20parasitic%20components%20(spurs).).

As you appear to be using SimpleITK, exploring the effects of a filter, even without understanding the underlying algorithms, is very straightforward. I would encourage you to try things out using toy images. Sample code below:

```auto
import SimpleITK as sitk

# Create skeleton image with spurs
original_binary_image = sitk.Image([128,128], sitk.sitkUInt8)
original_binary_image[50,20:120] = 1
original_binary_image[50:60,50] = 1
original_binary_image[40:50,70] = 1
original_binary_image[50:100,100] = 1

# multiply by 255 so that the binary data is readily visible in Fiji
sitk.Show(original_binary_image*255, 'original')

binary_pruned = sitk.BinaryPruning(original_binary_image, 10)
sitk.Show(binary_pruned*255, 'pruned')

```

---

<div class="post-metadata">

**Author:** ![assia855](https://discourse.itk.org/user_avatar/discourse.itk.org/assia855/32/2642_2.png) [@assia855](https://discourse.itk.org/u/assia855)\
**Post date:** [April 19, 2022, 1:29pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924/3 "2022-04-19T13:29:25Z")

</div>

Thank you so much. I thought that will help me to remove a small object from my image but inseat it helps in thinning the data which isn’t my goal for the moment. Do you know any operation in sitk who can help me in removing the small objects. Thanks a lot.

---

<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:** [April 19, 2022, 1:34pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924/4 "2022-04-19T13:34:29Z")

</div>

You could try [binary opening](https://itk.org/Doxygen/html/classitk_1_1BinaryMorphologicalOpeningImageFilter.html), or [approximation to that by use of signed distance field](https://github.com/KitwareMedical/HASI/blob/c75d6c45e573c143abe71dd836a639922347d3fb/include/itkSegmentBonesInMicroCTFilter.hxx#L67-L111).

---

<div class="post-metadata">

**Author:** ![assia855](https://discourse.itk.org/user_avatar/discourse.itk.org/assia855/32/2642_2.png) [@assia855](https://discourse.itk.org/u/assia855)\
**Post date:** [April 19, 2022, 1:40pm UTC](https://discourse.itk.org/t/binarypruningimagefilter/4924/6 "2022-04-19T13:40:05Z")

</div>

Thanks for the reply. Actually I want to improve the result of open binary filter.
