ITK  5.0.0
Insight Segmentation and Registration Toolkit
WikiExamples/Smoothing/VectorCurvatureAnisotropicDiffusionImageFilter.cxx
#include "itkImage.h"
#include "itksys/SystemTools.hxx"
#include <sstream>
#include "QuickView.h"
int main( int argc, char *argv[])
{
// Verify arguments
if( argc < 2 )
{
std::cerr << "Usage: "<< std::endl;
std::cerr << argv[0];
std::cerr << " InputFileName";
std::cerr << " [NumberOfIterations] ";
std::cerr << " [Conductance]" << std::endl;
return EXIT_FAILURE;
}
// 0) Parse arguments
std::string inputFileName = argv[1];
using FloatImageType = itk::Image< itk::Vector<float, 3>, 2 >;
using RGBImageType = itk::Image< itk::RGBPixel<float>, 2 >;
// 1) Read the RGB image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );
// 2) Cast to Vector image for processing
AdaptorInputType::Pointer adaptInput = AdaptorInputType::New();
adaptInput->SetImage(reader->GetOutput());
CastInputType::Pointer castInput = CastInputType::New();
castInput->SetInput(adaptInput);
// 3) Smooth the image
using VectorCurvatureAnisotropicDiffusionImageFilterType = itk::VectorCurvatureAnisotropicDiffusionImageFilter< FloatImageType,
FloatImageType >;
VectorCurvatureAnisotropicDiffusionImageFilterType::Pointer filter =
VectorCurvatureAnisotropicDiffusionImageFilterType::New();
filter->SetInput( castInput->GetOutput() );
filter->SetTimeStep(0.125);
if (argc > 2)
{
filter->SetNumberOfIterations(atoi(argv[2]));
}
if (argc > 3)
{
filter->SetConductanceParameter(atof(argv[3]));
}
// 4) Cast the Vector image to an RGB image for display
AdaptorOutputType::Pointer adaptOutput = AdaptorOutputType::New();
adaptOutput->SetImage(filter->GetOutput());
CastOutputType::Pointer castOutput = CastOutputType::New();
castOutput->SetInput(adaptOutput);
// 5) Display the input and smoothed images
QuickView viewer;
viewer.AddRGBImage(
reader->GetOutput(),
true,
itksys::SystemTools::GetFilenameName(inputFileName));
std::stringstream desc;
desc << "VectorCurvatureAnisotropicDiffusionImageFilter\niterations: "
<< filter->GetNumberOfIterations() << " conductance: "
<< filter->GetConductanceParameter();
viewer.AddRGBImage(
castOutput->GetOutput(),
true,
desc.str());
viewer.Visualize();
return EXIT_SUCCESS;
}