# "Anisotropic diffusion function is not set" error

**URL:** <https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276>\
**Category:** Uncategorized\
**Created:** [October 9, 2017, 10:43pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276 "2017-10-09T22:43:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![nickmarch31](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/91b2a8/32.png) [@nickmarch31](https://discourse.itk.org/u/nickmarch31)\
**Post date:** [October 9, 2017, 10:43pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276/1 "2017-10-09T22:43:51Z")

</div>

hey friends,

when I try to use `itk::GradientAnisotropicDiffusionImageFilter`, I get a weird error saying:

```auto
RuntimeError: /Users/ncullen/desktop/PROJECTS/ANTsX/ANTsPy/itksource/Modules/Filtering/AnisotropicSmoothing/include/itkAnisotropicDiffusionImageFilter.hxx:52:
Anisotropic diffusion function is not set.

```

I’m basically just trying the example [here](https://itk.org/Doxygen/html/Examples_2Filtering_2GradientAnisotropicDiffusionImageFilter_8cxx-example.html#_a2) … so maybe it’s an issue with my build?

I’m using itktag `c5138560409c75408ff76bccff938f21e5dcafc6` and here is my itk cmake:

```auto
cmake \
    -DCMAKE_BUILD_TYPE:STRING="${CMAKE_BUILD_TYPE}" \
    -DCMAKE_C_FLAGS="${CMAKE_C_FLAGS} -Wno-c++11-long-long -fPIC -O2 -DNDEBUG "\
    -DCMAKE_CXX_FLAGS="${CMAKE_CXX_FLAGS} -Wno-c++11-long-long -fPIC -O2 -DNDEBUG "\
    -DITK_USE_GIT_PROTOCOL:BOOL=OFF \
    -DBUILD_SHARED_LIBS=OFF \
    -DBUILD_TESTING:BOOL=OFF \
    -DBUILD_EXAMPLES:BOOL=OFF \
    -DCMAKE_INSTALL_PREFIX:PATH=${R_PACKAGE_DIR}/libs/ \
    -DITK_LEGACY_REMOVE:BOOL=OFF \
    -DITK_FUTURE_LEGACY_REMOVE:=BOOL=ON \
    -DITKV3_COMPATIBILITY:BOOL=ON \
    -DITK_BUILD_DEFAULT_MODULES:BOOL=OFF \
    -DKWSYS_USE_MD5:BOOL=ON \
    -DITK_WRAPPING:BOOL=OFF \
    -DModule_MGHIO:BOOL=ON \
    -DModule_ITKDeprecated:BOOL=OFF \
    -DModule_ITKReview:BOOL=ON \
    -DModule_ITKVtkGlue:BOOL=ON \
    -DModule_ITKAnisotropicSmoothing:BOOL=ON \
    -D ITKGroup_Core=ON \
    -D Module_ITKReview=ON \
    -D ITKGroup_Filtering=ON \
    -D ITKGroup_IO=ON \
    -D ITKGroup_Numerics=ON \
    -D ITKGroup_Registration=ON \
    -D ITKGroup_Segmentation=ON \
    -DCMAKE_C_VISIBILITY_PRESET:BOOL=hidden \
    -DCMAKE_CXX_VISIBILITY_PRESET:BOOL=hidden \
    -DCMAKE_VISIBILITY_INLINES_HIDDEN:BOOL=ON ../itksource/

```

code looks like this:

```cpp
template <typename ImageType>
ImageType::Pointer locallyBlurImage( typename ImageType::Pointer itkImage, unsigned long nIterations, 
                                double conductance )
{
  
  typedef itk::GradientAnisotropicDiffusionImageFilter< ImageType, ImageType >FilterType;
  typedef typename FilterType::TimeStepType TimeStepType;

  // Select time step size.
  TimeStepType spacingsize = 0;
  for( unsigned int d = 0; d < ImageType::ImageDimension; d++ )
    {
    TimeStepType sp = itkImage->GetSpacing()[d];
    spacingsize += sp * sp;
    }
  spacingsize = sqrt( spacingsize );

  // FIXME - cite reason for this step
  double dimPlusOne = ImageType::ImageDimension + 1;
  TimeStepType mytimestep = spacingsize / std::pow( 2.0 , dimPlusOne );
  TimeStepType reftimestep = 0.4 / std::pow( 2.0 , dimPlusOne );
  if ( mytimestep > reftimestep )
    {
    mytimestep = reftimestep;
    }

  typename FilterType::Pointer filter = FilterType::New();
  filter->SetInput( itkImage );
  filter->SetConductanceParameter( conductance ); // might need to change this
  filter->SetNumberOfIterations( nIterations );
  filter->SetTimeStep( mytimestep );

  filter->Update();
    return filter->GetOutput();
}

```

Thanks 🙂  
nick

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [October 10, 2017, 1:37pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276/2 "2017-10-10T13:37:56Z")

</div>

Hi Nick,

Is this behavior observed on macOS?

I suspect the `dynamic_cast` is failing in AnisotropicDiffusionImageFilter due to issues with how symbols are handled on macOS.

Does this patch fix the behavior?

[http://review.source.kitware.com/#/c/22696/](http://review.source.kitware.com/#/c/22696/)

Thanks,  
Matt

---

<div class="post-metadata">

**Author:** ![nickmarch31](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/91b2a8/32.png) [@nickmarch31](https://discourse.itk.org/u/nickmarch31)\
**Post date:** [October 10, 2017, 2:03pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276/3 "2017-10-10T14:03:18Z")

</div>

Matt, thanks for the response. yes it is MacOS… but the ANTs version of the same code works \*sobs\* on my machine that’s why i was thinking build. I’ll try the patch - much appreciated.

---

<div class="post-metadata">

**Author:** ![ncullen93](https://discourse.itk.org/letter_avatar_proxy/v4/letter/n/8baadc/32.png) [@ncullen93](https://discourse.itk.org/u/ncullen93)\
**Post date:** [October 10, 2017, 3:34pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276/4 "2017-10-10T15:34:44Z")

</div>

it worked once I also added `ITK_TEMPLATE_EXPORT` to itkAnisotropicDiffusionFunction.h as well (maybe that’s all that is needed?). Glad you could find a simple solution. if i knew how to work the version control system yall use i’d add it to the commit haha sry -\_- one of these days…

(changed usernames)  
Nick

---

<div class="post-metadata">

**Author:** ![matt.mccormick](https://discourse.itk.org/user_avatar/discourse.itk.org/matt.mccormick/32/7_2.png) [@matt.mccormick](https://discourse.itk.org/u/matt.mccormick)\
**Post date:** [October 10, 2017, 5:39pm UTC](https://discourse.itk.org/t/anisotropic-diffusion-function-is-not-set-error/276/5 "2017-10-10T17:39:28Z")

</div>

Great, thanks for testing and the fix! I will add it to the patch.

We will be moving to GitHub soon, so reviews will be more familiar to many folks.
