# Gradient Anisotropic Diffusion itk filter in my .py extension

**URL:** <https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805>\
**Category:** Support\
**Tags:** python, filters, itk\
**Created:** [November 26, 2021, 7:57pm UTC](https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805 "2021-11-26T19:57:10Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aaregar](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@aaregar](https://discourse.slicer.org/u/aaregar)\
**Post date:** [November 26, 2021, 7:57pm UTC](https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805/1 "2021-11-26T19:57:10Z")

</div>

Operating system: w10  
Slicer version: 4.11

Hi!!  
I’m trying to include in my in-house Extension the possibility to generate a filtered version of a selected volume using Gradient Anisotropic Diffusion itk filter. The parameters (conductance, iterations…) would be fixed in my .py, with no GUI, so my unique outcome after pushing the “Start” button would be generate the new filtered volume.  
I followed this notebook ( [300\_Segmentation\_Overview](http://insightsoftwareconsortium.github.io/SimpleITK-Notebooks/Python_html/300_Segmentation_Overview.html) ) but the arguments seems to fail.

Coul you please help me?  
Thanks!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 28, 2021, 4:19am UTC](https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805/2 "2021-11-28T04:19:16Z")

</div>

> [@aaregar](#):
>
> but the arguments seems to fail.

Please provide the code that you are running and the error message you get.

Alternatively, since these ITK filters are \available in CLI modules (“Curvature Anisotropic Diffusion” and “Gradient Anisotropic Diffusion” modules), you can perform this filtering from Python as described [here](https://slicer.readthedocs.io/en/latest/developer_guide/python_faq.html#how-to-run-a-cli-module-from-python).

---

<div class="post-metadata">

**Author:** ![aaregar](https://avatars.discourse-cdn.com/v4/letter/a/6f9a4e/32.png) [@aaregar](https://discourse.slicer.org/u/aaregar)\
**Post date:** [November 29, 2021, 3:40pm UTC](https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805/3 "2021-11-29T15:40:31Z")

</div>

Thank you for your quick response!  
I tried what you put forward above using these lines:  
outputVolume = slicer.mrmlScene.AddNewNodeByClass(“vtkMRMLScalarVolumeNode”)  
outputVolume.SetName(’{}-GADFILTER’.format(inputVolume.GetName()))

```
        parameters = {}
        parameters["inputVolume"] = inputVolume.GetID()
        parameters["outputVolume"] = outputVolume.GetID()
        parameters["useImageSpacing"] = True
        parameters["conductance"] = 0.9
        parameters["numberOfIterations"] = 7
        parameters["timeStep"] = 0.0625
        print(parameters)

        cliNode = slicer.cli.run(slicer.modules.gradientanisotropicdiffusion, None, parameters)

```

The output volume is created but as Invalid Volume, with no spatial information. Should I clone the input and then apply the filter? I’m not sure in which step it is the trouble.

Thank you!

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [November 29, 2021, 4:07pm UTC](https://discourse.slicer.org/t/gradient-anisotropic-diffusion-itk-filter-in-my-py-extension/20805/4 "2021-11-29T16:07:25Z")

</div>

You need to use `runSync` or wait for the execution to complete. See details at the link in my previous post.
