Difference between revisions of "ITK/Examples/Broken/Functions/GaussianBlurImageFunctionFilter"

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
error C2248: 'itk::GaussianBlurImageFunction<TInputImage>::~GaussianBlurImageFunction' : cannot access protected member declared in class 'itk::GaussianBlurImageFunction<TInputImage>'
{{warning|1=The media wiki content on this page is no longer maintainedThe examples presented on the https://itk.org/Wiki/*  pages likely require ITK version 4.13 or earlier releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
 
}}
==GaussianBlurImageFunctionFilter.cxx==
<source lang="cpp">
#include "itkGaussianBlurImageFunction.h"
#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkImageRegionIterator.h"
#include "itkUnaryFunctorImageFilter.h"
   
int main( int argc, char * argv[] )
{
  // Verify arguments
  if( argc < 5 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << "  inputImageFile  outputImageFile sigma maxKernelWidth" << std::endl;
    return EXIT_FAILURE;
    }
  // Parse arguments
  std::string inputFileName = argv[1];
  std::string outputFileName = argv[2];
  float sigma = 0;
  {
  std::stringstream ss(argv[3]);
  ss >> sigma;
  }
  int maxKernelWidth = 0;
  {
  std::stringstream ss(argv[4]);
  ss >> maxKernelWidth;
  }
  typedef itk::Image< float, 2 >            ImageType;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  typedef itk::ImageRegionIterator< ImageType > IteratorType;
  typedef itk::ImageRegionConstIterator< ImageType > ConstIteratorType;
  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( inputFileName );
  reader->Update();
  /*
  // This manually creates the output and computes the values at each pixel
  const ImageType * inputImage = reader->GetOutput();
   
  ImageType::RegionType region = inputImage->GetBufferedRegion();
  ImageType::Pointer output = ImageType::New();
  output->SetRegions( region );
  output->SetOrigin(  inputImage->GetOrigin()  );
  output->SetSpacing( inputImage->GetSpacing() );
  output->Allocate();
  ConstIteratorType it( inputImage, region );
  IteratorType out( output, region );
  it.GoToBegin();
  out.GoToBegin();
  while( !it.IsAtEnd() )
    {
    out.Set( gaussianFunction->EvaluateAtIndex(it.GetIndex() ) );
    ++it;
    ++out;
    }
   */
  typedef itk::GaussianBlurImageFunction< ImageType > GaussianBlurImageFunctionType;
  // SetFunctor seems to need an actual object (not a pointer), but we can't create one like this:
  //GaussianBlurImageFunctionType gaussianFunction;
  GaussianBlurImageFunctionType::Pointer gaussianFunction = GaussianBlurImageFunctionType::New();
  //gaussianFunction->SetInputImage( reader->GetOutput() ); // Do we need to do this since we are going to do unaryFunctor->SetInput?
 
  typedef itk::UnaryFunctorImageFilter<ImageType,ImageType,
                                  GaussianBlurImageFunctionType> FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetInput(reader->GetOutput());
 
  GaussianBlurImageFunctionType::ErrorArrayType setError;
  setError.Fill( 0.01 );
  filter->GetFunctor().SetMaximumError( setError );
  filter->GetFunctor().SetSigma( sigma );
  filter->GetFunctor().SetMaximumKernelWidth( maxKernelWidth );
 
  filter->Update();
  typedef itk::ImageFileWriter < ImageType > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(outputFileName);
  writer->SetInput(filter->GetOutput());
  writer->Update();
  return EXIT_SUCCESS;
}
</source>
 
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 16:15, 4 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.