ITK/Examples/Smoothing/VectorCurvatureAnisotropicDiffusionImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
<div class="floatcenter">[[File:ITK_Examples_Baseline_Smoothing_VectorCurvatureAnisotropicDiffusionImageFilter.png]]</div>
{{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releases.   In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
==VectorCurvatureAnisotropicDiffusionImageFilter.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkVectorCurvatureAnisotropicDiffusionImageFilter.h"
#include "itkVectorToRGBImageAdaptor.h"
#include "itkRGBToVectorImageAdaptor.h"
#include "itkCastImageFilter.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
  typedef  itk::ImageFileReader< RGBImageType > ReaderType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( inputFileName );
 
  // 2) Cast to Vector image for processing
  typedef itk::RGBToVectorImageAdaptor<RGBImageType> AdaptorInputType;
  AdaptorInputType::Pointer adaptInput = AdaptorInputType::New();
  adaptInput->SetImage(reader->GetOutput());
  typedef itk::CastImageFilter<AdaptorInputType,FloatImageType> CastInputType;
  CastInputType::Pointer castInput = CastInputType::New();
  castInput->SetInput(adaptInput);
 
  // 3) Smooth the image
   typedef itk::VectorCurvatureAnisotropicDiffusionImageFilter< FloatImageType,  
    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
  typedef itk::VectorToRGBImageAdaptor<FloatImageType> AdaptorOutputType;
  AdaptorOutputType::Pointer adaptOutput = AdaptorOutputType::New();
  adaptOutput->SetImage(filter->GetOutput());
  typedef itk::CastImageFilter<AdaptorOutputType,RGBImageType> CastOutputType;
  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;
}
</source>
 
{{ITKVTKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 17:47, 6 June 2019

Warning: The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions.