"Anisotropic diffusion function is not set" error

hey friends,

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

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 … so maybe it’s an issue with my build?

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

cmake \
    -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  "\
    -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 \

code looks like this:

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 );

    return  filter->GetOutput();

Thanks :slight_smile:

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?



1 Like

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.

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)

1 Like

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.