Difference between revisions of "ITK/Examples/Smoothing/SmoothingRecursiveGaussianImageFilter"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==SmoothingRecursiveGaussianImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileReader.h" #include "itkDiscreteGaussianImageFilter.h" #include "itkS...")
 
(Uses QuickView. Changed to smooth rgb images.)
Line 5: Line 5:
#include "itkDiscreteGaussianImageFilter.h"
#include "itkDiscreteGaussianImageFilter.h"
#include "itkSmoothingRecursiveGaussianImageFilter.h"
#include "itkSmoothingRecursiveGaussianImageFilter.h"
#include "itkCovariantVector.h"
#include "itkRGBPixel.h"
#include "itkNthElementImageAdaptor.h"
#include "itkNthElementImageAdaptor.h"
#include "itkComposeRGBImageFilter.h"
#include "QuickView.h"


int main(int argc, char * argv[])
int main(int argc, char * argv[])
{
{
const unsigned int Dimension = 2;
  // Verify command line arguments
typedef unsigned char PixelComponentType;
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile [sigma]" << std::endl;
    return EXIT_FAILURE;
    }
 
  double sigma = 4.0;
  if (argc > 2)
    {
    sigma = atof(argv[2]);
    }
 
 
  const unsigned int Dimension = 2;
  typedef unsigned char PixelComponentType;
 
  typedef itk::Image<itk::RGBPixel< PixelComponentType>,
    Dimension > ColorImageType;
  typedef itk::Image<PixelComponentType, Dimension >
    ScalarImageType;
  typedef itk::ImageFileReader< ColorImageType >
    ReaderType;
  // Create and setup a reader
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->Update();
 
  typedef itk::NthElementImageAdaptor<ColorImageType,
    PixelComponentType> ImageAdaptorType;
 
  typedef itk::SmoothingRecursiveGaussianImageFilter<
    ImageAdaptorType, ScalarImageType >  FilterType;
 
  ImageAdaptorType::Pointer adaptorR = ImageAdaptorType::New();
  adaptorR->SelectNthElement(0);
  adaptorR->SetImage(reader->GetOutput());
 
  FilterType::Pointer gaussianR = FilterType::New();
  gaussianR->SetInput(adaptorR);
  gaussianR->SetSigma(sigma);
 
  ImageAdaptorType::Pointer adaptorG = ImageAdaptorType::New();
  adaptorG->SelectNthElement(1);
  adaptorG->SetImage(reader->GetOutput());
 
  FilterType::Pointer gaussianG = FilterType::New();
  gaussianG->SetInput(adaptorG);
  gaussianG->SetSigma(sigma);


typedef itk::Image<itk::CovariantVector< PixelComponentType, 3>,
  ImageAdaptorType::Pointer adaptorB = ImageAdaptorType::New();
          Dimension > ColorImageType;
  adaptorB->SelectNthElement(2);
                     
  adaptorB->SetImage(reader->GetOutput());
typedef itk::Image<PixelComponentType, Dimension >   ScalarImageType;


ColorImageType::Pointer image = ColorImageType::New();
  FilterType::Pointer gaussianB = FilterType::New();
  gaussianB->SetInput(adaptorB);
  gaussianB->SetSigma(sigma);


typedef itk::NthElementImageAdaptor<ColorImageType,
  typedef itk::ComposeRGBImageFilter<
            PixelComponentType> ImageAdaptorType;
    ScalarImageType, ColorImageType >  ComposeFilterType;
  ComposeFilterType::Pointer composeFilter =
    ComposeFilterType::New();
  composeFilter->SetInput1(gaussianR->GetOutput());
  composeFilter->SetInput2(gaussianG->GetOutput());
  composeFilter->SetInput3(gaussianB->GetOutput());


ImageAdaptorType::Pointer adaptor = ImageAdaptorType::New();
  QuickView viewer;
adaptor->SelectNthElement(0);
  viewer.AddRGBImage(
adaptor->SetImage(image);
    reader->GetOutput(),true,
    itksys::SystemTools::GetFilenameName(argv[1]));


typedef itk::SmoothingRecursiveGaussianImageFilter<
  std::stringstream desc;
     ImageAdaptorType, ScalarImageType > filterType;
  desc << "SmoothingRecursiveGaussian\n sigma = " << sigma;
  viewer.AddRGBImage(
     composeFilter->GetOutput(),
    true,
    desc.str());  


filterType::Pointer gaussianFilter = filterType::New();
  viewer.Visualize();
gaussianFilter->SetInput(adaptor);
gaussianFilter->Update();


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

Revision as of 05:31, 24 December 2010

SmoothingRecursiveGaussianImageFilter.cxx

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkDiscreteGaussianImageFilter.h"
#include "itkSmoothingRecursiveGaussianImageFilter.h"
#include "itkRGBPixel.h"
#include "itkNthElementImageAdaptor.h"
#include "itkComposeRGBImageFilter.h"

#include "QuickView.h"

int main(int argc, char * argv[])
{
  // Verify command line arguments
  if( argc < 2 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile [sigma]" << std::endl;
    return EXIT_FAILURE;
    }

  double sigma = 4.0;
  if (argc > 2)
    {
    sigma = atof(argv[2]);
    }


  const unsigned int Dimension = 2;
  typedef unsigned char PixelComponentType;

  typedef itk::Image<itk::RGBPixel< PixelComponentType>,
    Dimension > ColorImageType;
  typedef itk::Image<PixelComponentType, Dimension >
    ScalarImageType;
  typedef itk::ImageFileReader< ColorImageType >
    ReaderType;
  // Create and setup a reader
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );
  reader->Update();

  typedef itk::NthElementImageAdaptor<ColorImageType,
    PixelComponentType> ImageAdaptorType;

  typedef itk::SmoothingRecursiveGaussianImageFilter<
    ImageAdaptorType, ScalarImageType >  FilterType;

  ImageAdaptorType::Pointer adaptorR = ImageAdaptorType::New();
  adaptorR->SelectNthElement(0);
  adaptorR->SetImage(reader->GetOutput());

  FilterType::Pointer gaussianR = FilterType::New();
  gaussianR->SetInput(adaptorR);
  gaussianR->SetSigma(sigma);

  ImageAdaptorType::Pointer adaptorG = ImageAdaptorType::New();
  adaptorG->SelectNthElement(1);
  adaptorG->SetImage(reader->GetOutput());

  FilterType::Pointer gaussianG = FilterType::New();
  gaussianG->SetInput(adaptorG);
  gaussianG->SetSigma(sigma);

  ImageAdaptorType::Pointer adaptorB = ImageAdaptorType::New();
  adaptorB->SelectNthElement(2);
  adaptorB->SetImage(reader->GetOutput());

  FilterType::Pointer gaussianB = FilterType::New();
  gaussianB->SetInput(adaptorB);
  gaussianB->SetSigma(sigma);

  typedef itk::ComposeRGBImageFilter<
    ScalarImageType, ColorImageType >  ComposeFilterType;
  ComposeFilterType::Pointer composeFilter =
    ComposeFilterType::New();
  composeFilter->SetInput1(gaussianR->GetOutput());
  composeFilter->SetInput2(gaussianG->GetOutput());
  composeFilter->SetInput3(gaussianB->GetOutput());

  QuickView viewer;
  viewer.AddRGBImage(
    reader->GetOutput(),true,
    itksys::SystemTools::GetFilenameName(argv[1]));  

  std::stringstream desc;
  desc << "SmoothingRecursiveGaussian\n sigma = " << sigma;
  viewer.AddRGBImage(
    composeFilter->GetOutput(),
    true,
    desc.str());  

  viewer.Visualize();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 2.6)

PROJECT(SmoothingRecursiveGaussianImageFilter)

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

ADD_EXECUTABLE(SmoothingRecursiveGaussianImageFilter SmoothingRecursiveGaussianImageFilter.cxx)
TARGET_LINK_LIBRARIES(SmoothingRecursiveGaussianImageFilter ITKIO)