"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_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:

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 :slight_smile:
nick

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/

Thanks,
Matt

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

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.