ITK/Examples/Broken/Functions/GaussianBlurImageFunctionFilter: Difference between revisions
Daviddoria (talk | contribs) (Created page with "error: no match for ‘operator!=’ in ‘((itk::UnaryFunctorImageFilter<itk::Image<float, 2u>, itk::Image<float, 2u>, itk::GaussianBlurImageFunction<itk::Image<float, 2u>, doub...") |
m (moved ITK/Examples/Functions/GaussianBlurImageFunctionFilter to ITK/Examples/Broken/Functions/GaussianBlurImageFunctionFilter: This should not be in the examples until it compiles) |
(No difference)
|
Revision as of 04:03, 28 June 2011
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’
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? GaussianBlurImageFunctionType::ErrorArrayType setError; setError.Fill( 0.01 ); gaussianFunction->SetMaximumError( setError ); gaussianFunction->SetSigma( sigma ); gaussianFunction->SetMaximumKernelWidth( maxKernelWidth ); typedef itk::UnaryFunctorImageFilter<ImageType,ImageType, GaussianBlurImageFunctionType> FilterType; FilterType::Pointer filter = FilterType::New(); filter->SetInput(reader->GetOutput()); filter->SetFunctor(*gaussianFunction); 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.