ITK  4.13.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];
typedef itk::Image< itk::Vector<float, 3>, 2 > FloatImageType;
typedef itk::Image< itk::RGBPixel<float>, 2 > RGBImageType;
// 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
FloatImageType > VectorCurvatureAnisotropicDiffusionImageFilterType;
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;
}