ITK/Examples/Smoothing/CurvatureFlowImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Use QuickView and moved to Smoothing)
Line 4: Line 4:
#include "itkCastImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "itkCurvatureFlowImageFilter.h"
#include "itkSubtractImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
 
#include "QuickView.h"


int main( int argc, char *argv[])
int main( int argc, char *argv[])
{
{
   if( argc < 3 )
   if( argc < 2 )
  {
    {
    std::cerr << "Missing Parameters " << std::endl;
     std::cerr << "Usage: " << argv[0];
     std::cerr << "Usage: " << argv[0];
     std::cerr << " inputImage outputImage" << std::endl;
     std::cerr << " inputImage [iterations]" << std::endl;
     return 1;
     return EXIT_FAILURE;
   }
    }
 
   int iterations = 5;
  if (argc > 2)
    {
    iterations = atoi(argv[2]);
    }


   typedef  float          InternalPixelType;
   typedef  float          InternalPixelType;
  typedef unsigned char    ExternalPixelType;
   const    unsigned int    Dimension = 2;
   const    unsigned int    Dimension = 2;
   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
   typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
  typedef itk::Image< ExternalPixelType, Dimension >  ExternalImageType;


   typedef  itk::ImageFileReader< InternalImageType > ReaderType;
   typedef  itk::ImageFileReader< InternalImageType > ReaderType;
  typedef  itk::ImageFileWriter< ExternalImageType  > WriterType;


   ReaderType::Pointer reader = ReaderType::New();
   ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();


   reader->SetFileName( argv[1] );
   reader->SetFileName( argv[1] );
  writer->SetFileName( argv[2] );


   typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >CurvatureFlowImageFilterType;
   typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >CurvatureFlowImageFilterType;
Line 37: Line 39:


   smoothing->SetInput( reader->GetOutput() );
   smoothing->SetInput( reader->GetOutput() );
  smoothing->SetNumberOfIterations( iterations );
  smoothing->SetTimeStep( 0.125 );


   typedef itk::CastImageFilter< InternalImageType, ExternalImageType > CastingFilterType;
   typedef itk::SubtractImageFilter< InternalImageType > SubtractImageFilterType;
   CastingFilterType::Pointer caster = CastingFilterType::New();
   SubtractImageFilterType::Pointer diff = SubtractImageFilterType::New();
  diff->SetInput1(reader->GetOutput());
  diff->SetInput2(smoothing->GetOutput());


   caster->SetInput( smoothing->GetOutput() );
   QuickView viewer;
  writer->SetInput( caster->GetOutput() );
  viewer.AddImage<InternalImageType>(
    reader->GetOutput(),true,
    itksys::SystemTools::GetFilenameName(argv[1]));


   smoothing->SetNumberOfIterations( 5 );
   std::stringstream desc;
   smoothing->SetTimeStep( 0.125 );
  desc << "CurvatureFlow\niterations = " << iterations;
  viewer.AddImage<InternalImageType>(
    smoothing->GetOutput(),
    true,
    desc.str()); 
 
  std::stringstream desc2;
   desc2 << "Original - CurvatureFlow";
  viewer.AddImage<InternalImageType>(
    diff->GetOutput(),
    true,
    desc2.str());


   writer->Update();
   viewer.Visualize();


   return 0;
   return EXIT_SUCCESS;
}
}
</source>
</source>

Revision as of 16:23, 19 December 2010

CurvatureFlowImageFilter.cxx

<source lang="cpp">

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

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

 if( argc < 2 )
   {
   std::cerr << "Usage: " << argv[0];
   std::cerr << " inputImage [iterations]" << std::endl;
   return EXIT_FAILURE;
   }
 int iterations = 5;
 if (argc > 2)
   {
   iterations = atoi(argv[2]);
   }
 typedef   float           InternalPixelType;
 const     unsigned int    Dimension = 2;
 typedef itk::Image< InternalPixelType, Dimension >  InternalImageType;
 typedef  itk::ImageFileReader< InternalImageType > ReaderType;
 ReaderType::Pointer reader = ReaderType::New();
 reader->SetFileName( argv[1] );
 typedef itk::CurvatureFlowImageFilter< InternalImageType, InternalImageType >CurvatureFlowImageFilterType;
 CurvatureFlowImageFilterType::Pointer smoothing = CurvatureFlowImageFilterType::New();
 smoothing->SetInput( reader->GetOutput() );
 smoothing->SetNumberOfIterations( iterations );
 smoothing->SetTimeStep( 0.125 );
 typedef itk::SubtractImageFilter< InternalImageType > SubtractImageFilterType;
 SubtractImageFilterType::Pointer diff = SubtractImageFilterType::New();
 diff->SetInput1(reader->GetOutput());
 diff->SetInput2(smoothing->GetOutput());
 QuickView viewer;
 viewer.AddImage<InternalImageType>(
   reader->GetOutput(),true,
   itksys::SystemTools::GetFilenameName(argv[1]));  
 std::stringstream desc;
 desc << "CurvatureFlow\niterations = " << iterations;
 viewer.AddImage<InternalImageType>(
   smoothing->GetOutput(),
   true,
   desc.str());  
 std::stringstream desc2;
 desc2 << "Original - CurvatureFlow";
 viewer.AddImage<InternalImageType>(
   diff->GetOutput(),
   true,
   desc2.str());  
 viewer.Visualize();
 return EXIT_SUCCESS;

} </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>