ITK/Examples/Broken/Functions/GaussianBlurImageFunctionFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Reduced number of errors)
Line 1: Line 1:
error: no match for ‘operator!=’ in ‘((itk::UnaryFunctorImageFilter<itk::Image<float, 2u>, itk::Image<float, 2u>, itk::GaussianBlurImageFunction<itk::Image<float, 2u>, double> >*)this)->itk::UnaryFunctorImageFilter<itk::Image<float, 2u>, itk::Image<float, 2u>, itk::GaussianBlurImageFunction<itk::Image<float, 2u>, double> >::m_Functor != functor’
error C2248: 'itk::GaussianBlurImageFunction<TInputImage>::~GaussianBlurImageFunction' : cannot access protected member declared in class 'itk::GaussianBlurImageFunction<TInputImage>'


==GaussianBlurImageFunctionFilter.cxx==
==GaussianBlurImageFunctionFilter.cxx==
Line 9: Line 9:
#include "itkImageRegionIterator.h"
#include "itkImageRegionIterator.h"
#include "itkUnaryFunctorImageFilter.h"
#include "itkUnaryFunctorImageFilter.h"
 
int main( int argc, char * argv[] )
int main( int argc, char * argv[] )
{
{
Line 33: Line 33:
   ss >> maxKernelWidth;
   ss >> maxKernelWidth;
   }
   }
 
   typedef itk::Image< float, 2 >            ImageType;
   typedef itk::Image< float, 2 >            ImageType;
   typedef itk::ImageFileReader< ImageType >  ReaderType;
   typedef itk::ImageFileReader< ImageType >  ReaderType;
Line 42: Line 42:
   reader->SetFileName( inputFileName );
   reader->SetFileName( inputFileName );
   reader->Update();
   reader->Update();
 
   /*
   /*
   // This manually creates the output and computes the values at each pixel
   // This manually creates the output and computes the values at each pixel
Line 48: Line 48:
   
   
   ImageType::RegionType region = inputImage->GetBufferedRegion();
   ImageType::RegionType region = inputImage->GetBufferedRegion();
 
   ImageType::Pointer output = ImageType::New();
   ImageType::Pointer output = ImageType::New();
   
   
Line 55: Line 55:
   output->SetSpacing( inputImage->GetSpacing() );
   output->SetSpacing( inputImage->GetSpacing() );
   output->Allocate();
   output->Allocate();
 
   ConstIteratorType it( inputImage, region );
   ConstIteratorType it( inputImage, region );
   IteratorType out( output, region );
   IteratorType out( output, region );
 
   it.GoToBegin();
   it.GoToBegin();
   out.GoToBegin();
   out.GoToBegin();
Line 73: Line 73:
   // SetFunctor seems to need an actual object (not a pointer), but we can't create one like this:
   // SetFunctor seems to need an actual object (not a pointer), but we can't create one like this:
   //GaussianBlurImageFunctionType gaussianFunction;
   //GaussianBlurImageFunctionType gaussianFunction;
 
   GaussianBlurImageFunctionType::Pointer gaussianFunction = GaussianBlurImageFunctionType::New();
   GaussianBlurImageFunctionType::Pointer gaussianFunction = GaussianBlurImageFunctionType::New();
   //gaussianFunction->SetInputImage( reader->GetOutput() ); // Do we need to do this since we are going to do unaryFunctor->SetInput?
   //gaussianFunction->SetInputImage( reader->GetOutput() ); // Do we need to do this since we are going to do unaryFunctor->SetInput?
  GaussianBlurImageFunctionType::ErrorArrayType setError;
 
  setError.Fill( 0.01 );
  gaussianFunction->SetMaximumError( setError );
  gaussianFunction->SetSigma( sigma );
  gaussianFunction->SetMaximumKernelWidth( maxKernelWidth );
   
   typedef itk::UnaryFunctorImageFilter<ImageType,ImageType,
   typedef itk::UnaryFunctorImageFilter<ImageType,ImageType,
                                   GaussianBlurImageFunctionType> FilterType;
                                   GaussianBlurImageFunctionType> FilterType;
   FilterType::Pointer filter = FilterType::New();
   FilterType::Pointer filter = FilterType::New();
   filter->SetInput(reader->GetOutput());
   filter->SetInput(reader->GetOutput());
   filter->SetFunctor(*gaussianFunction);
 
  GaussianBlurImageFunctionType::ErrorArrayType setError;
  setError.Fill( 0.01 );
  filter->GetFunctor().SetMaximumError( setError );
   filter->GetFunctor().SetSigma( sigma );
  filter->GetFunctor().SetMaximumKernelWidth( maxKernelWidth );
 
   filter->Update();
   filter->Update();
 
   typedef itk::ImageFileWriter < ImageType > WriterType;
   typedef itk::ImageFileWriter < ImageType > WriterType;
   WriterType::Pointer writer = WriterType::New();
   WriterType::Pointer writer = WriterType::New();
Line 97: Line 99:
   return EXIT_SUCCESS;
   return EXIT_SUCCESS;
}
}
</source>
</source>




{{ITKCMakeLists|GaussianBlurImageFunctionFilter}}
{{ITKCMakeLists|GaussianBlurImageFunctionFilter}}

Revision as of 08:13, 13 July 2011

error C2248: 'itk::GaussianBlurImageFunction<TInputImage>::~GaussianBlurImageFunction' : cannot access protected member declared in class 'itk::GaussianBlurImageFunction<TInputImage>'

GaussianBlurImageFunctionFilter.cxx

<source lang="cpp">

  1. include "itkGaussianBlurImageFunction.h"
  2. include "itkImage.h"
  3. include "itkImageFileReader.h"
  4. include "itkImageFileWriter.h"
  5. include "itkImageRegionIterator.h"
  6. 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>


CMakeLists.txt

<syntaxhighlight lang="cmake"> cmake_minimum_required(VERSION 3.9.5)

project(GaussianBlurImageFunctionFilter)

find_package(ITK REQUIRED) include(${ITK_USE_FILE}) if (ITKVtkGlue_LOADED)

 find_package(VTK REQUIRED)
 include(${VTK_USE_FILE})

endif()

add_executable(GaussianBlurImageFunctionFilter MACOSX_BUNDLE GaussianBlurImageFunctionFilter.cxx)

if( "${ITK_VERSION_MAJOR}" LESS 4 )

 target_link_libraries(GaussianBlurImageFunctionFilter ITKReview ${ITK_LIBRARIES})

else( "${ITK_VERSION_MAJOR}" LESS 4 )

 target_link_libraries(GaussianBlurImageFunctionFilter ${ITK_LIBRARIES})

endif( "${ITK_VERSION_MAJOR}" LESS 4 )

</syntaxhighlight>

Download and Build GaussianBlurImageFunctionFilter

Click here to download GaussianBlurImageFunctionFilter and its CMakeLists.txt file. Once the tarball GaussianBlurImageFunctionFilter.tar has been downloaded and extracted,

cd GaussianBlurImageFunctionFilter/build
  • If ITK is installed:
cmake ..
  • If ITK is not installed but compiled on your system, you will need to specify the path to your ITK build:
cmake -DITK_DIR:PATH=/home/me/itk_build ..

Build the project:

make

and run it:

./GaussianBlurImageFunctionFilter

WINDOWS USERS PLEASE NOTE: Be sure to add the ITK bin directory to your path. This will resolve the ITK dll's at run time.

Building All of the Examples

Many of the examples in the ITK Wiki Examples Collection require VTK. You can build all of the the examples by following these instructions. If you are a new VTK user, you may want to try the Superbuild which will build a proper ITK and VTK.

ItkVtkGlue

ITK >= 4

For examples that use QuickView (which depends on VTK), you must have built ITK with Module_ITKVtkGlue=ON.

ITK < 4

Some of the ITK Examples require VTK to display the images. If you download the entire ITK Wiki Examples Collection, the ItkVtkGlue directory will be included and configured. If you wish to just build a few examples, then you will need to download ItkVtkGlue and build it. When you run cmake it will ask you to specify the location of the ItkVtkGlue binary directory.