ITK/Examples/Smoothing/CurvatureFlowImageFilter

From KitwarePublic
Jump to navigationJump to search

CurvatureFlowImageFilter.cxx

<source lang="cpp">

  1. include "itkImage.h"
  2. include "itkCastImageFilter.h"
  3. include "itkCurvatureFlowImageFilter.h"
  4. include "itkImageFileReader.h"
  5. include "itkImageFileWriter.h"

int main( int argc, char *argv[]) {

 if( argc < 3 )
 {
   std::cerr << "Missing Parameters " << std::endl;
   std::cerr << "Usage: " << argv[0];
   std::cerr << " inputImage  outputImage" << std::endl;
   return 1;
 }
 typedef   float           InternalPixelType;
 typedef unsigned char     ExternalPixelType;
 const     unsigned int    Dimension = 2;
 typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
 typedef itk::Image< ExternalPixelType, Dimension >  ExternalImageType;
 typedef  itk::ImageFileReader< InternalImageType > ReaderType;
 typedef  itk::ImageFileWriter< ExternalImageType  > WriterType;
 ReaderType::Pointer reader = ReaderType::New();
 WriterType::Pointer writer = WriterType::New();
 reader->SetFileName( argv[1] );
 writer->SetFileName( argv[2] );
 typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >CurvatureFlowImageFilterType;
 CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
 smoothing->SetInput( reader->GetOutput() );
 typedef itk::CastImageFilter< InternalImageType, ExternalImageType > CastingFilterType;
 CastingFilterType::Pointer caster = CastingFilterType::New();
 caster->SetInput( smoothing->GetOutput() );
 writer->SetInput( caster->GetOutput() );
 smoothing->SetNumberOfIterations( 5 );
 smoothing->SetTimeStep( 0.125 );
 writer->Update();
 return 0;

} </source>

CMakeLists.txt

<source lang="cmake"> cmake_minimum_required(VERSION 2.6)

PROJECT(CurvatureFlowImageFilter)

FIND_PACKAGE(ITK REQUIRED) INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(CurvatureFlowImageFilter CurvatureFlowImageFilter.cxx) TARGET_LINK_LIBRARIES(CurvatureFlowImageFilter ITKIO)


</source>