ITK/Release 4/Why Switch to ITKv4/SimplifiedITK/DiscreteGaussianFilter: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
No edit summary
Line 1: Line 1:
=== C++ ===
=== C++ ===
<source lang="cpp">
<source lang="cpp">
   // Setup image types.
#include <iostream>
 
#include "itkDiscreteGaussianImageFilter.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
 
int main( int argc, char* argv[] )
{
  if( argc < 3 )
    {
    std::cerr << "Usage: " << argv[0] << " inputImage outputImage" << std::endl;
    return 1;
    }
 
   // Define types
   typedef float InputPixelType;
   typedef float InputPixelType;
   typedef float OutputPixelType;
   typedef float OutputPixelType;
   typedef itk::Image<InputPixelType, 2> InputImageType;
   typedef itk::Image<InputPixelType, 2> InputImageType;
   typedef itk::Image<OutputPixelType,2> OutputImageType;
   typedef itk::Image<OutputPixelType,2> OutputImageType;
   // Filter type
 
   typedef itk::DiscreteGaussianImageFilter<
   typedef itk::ImageFileReader< InputImageType >                              ReaderType;
                InputImageType, OutputImageType >
   typedef itk::DiscreteGaussianImageFilter< InputImageType, OutputImageType > FilterType;
          FilterType;
  typedef itk::ImageFileWriter< OutputImageType >                            WriterType;
   // Create a filter
 
   // Create filters
  ReaderType::Pointer reader = ReaderType::New();
   FilterType::Pointer filter = FilterType::New();
   FilterType::Pointer filter = FilterType::New();
   // Create the pipeline
  WriterType::Pointer writer = WriterType::New();
 
   // Set the filter parameters
  reader->SetFileName( argv[1] );
  filter->SetVariance( 4.0 );
  filter->SetMaximumKernelWidth( 10 );
  writer->SetFileName( argv[2] );
 
  // Connect the pipeline
   filter->SetInput( reader->GetOutput() );
   filter->SetInput( reader->GetOutput() );
   filter->SetVariance( 1.0 );
   writer->SetInput( filter->GetOutput() );
  filter->SetMaximumKernelWidth( 5 );
   try
   filter->Update();
    {
   OutputImageType::Pointer blurred = filter->GetOutput();
    writer->Update();
    }
   catch( const itk::ExceptionObject & e )
    {
    std::cerr << "Error: " << e.what() << std::endl;
    return 1;
    }
 
  return 0;
}
</source>
</source>



Revision as of 19:20, 31 August 2011

C++

<source lang="cpp">

  1. include <iostream>
  1. include "itkDiscreteGaussianImageFilter.h"
  2. include "itkImageFileReader.h"
  3. include "itkImageFileWriter.h"

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

 if( argc < 3 )
   {
   std::cerr << "Usage: " << argv[0] << " inputImage outputImage" << std::endl;
   return 1;
   }
 // Define types
 typedef float InputPixelType;
 typedef float OutputPixelType;
 typedef itk::Image<InputPixelType, 2> InputImageType;
 typedef itk::Image<OutputPixelType,2> OutputImageType;
 typedef itk::ImageFileReader< InputImageType >                              ReaderType;
 typedef itk::DiscreteGaussianImageFilter< InputImageType, OutputImageType > FilterType;
 typedef itk::ImageFileWriter< OutputImageType >                             WriterType;
 // Create filters
 ReaderType::Pointer reader = ReaderType::New();
 FilterType::Pointer filter = FilterType::New();
 WriterType::Pointer writer = WriterType::New();
 // Set the filter parameters
 reader->SetFileName( argv[1] );
 filter->SetVariance( 4.0 );
 filter->SetMaximumKernelWidth( 10 );
 writer->SetFileName( argv[2] );
 // Connect the pipeline
 filter->SetInput( reader->GetOutput() );
 writer->SetInput( filter->GetOutput() );
 try
   {
   writer->Update();
   }
 catch( const itk::ExceptionObject & e )
   {
   std::cerr << "Error: " << e.what() << std::endl;
   return 1;
   }
 return 0;

} </source>

WrapITK

SimpleITK

<source lang="python"> import SimpleITK input = SimpleITK.ReadImage ( filename ) output = SimpleITK.DiscreteGaussianFilter( input, 1.0, 5 ) </source>