ITK/Examples/WishList/Operators/AllOperators: Difference between revisions
Daviddoria (talk | contribs) (Created page with "Crashes trying to output the kernel elements (shouldn't there be a PrintKernel type function for this?). GetNameOfClass isn't defined. ==AllOperators.cxx== <source lang="cpp"> #...") |
(Wrong CMakeLists) |
||
Line 70: | Line 70: | ||
</source> | </source> | ||
{{ | {{ITKCMakeLists|AntiAliasBinaryImageFilter|}} |
Revision as of 19:39, 27 November 2012
Crashes trying to output the kernel elements (shouldn't there be a PrintKernel type function for this?). GetNameOfClass isn't defined.
AllOperators.cxx
<source lang="cpp">
- include <itkNeighborhoodOperator.h>
- include <itkDerivativeOperator.h>
- include <itkForwardDifferenceOperator.h>
- include <itkGaussianDerivativeOperator.h>
- include <itkGaussianOperator.h>
- include <itkImageKernelOperator.h>
- include <itkLaplacianOperator.h>
- include <itkSobelOperator.h>
- include <itkAnnulusOperator.h>
- include <itkBackwardDifferenceOperator.h>
- include <vector>
int main(int, char*[]) {
typedef itk::DerivativeOperator<float, 2> DerivativeOperatorType; typedef itk::ForwardDifferenceOperator<float, 2> ForwardDifferenceOperatorType; typedef itk::GaussianDerivativeOperator<float, 2> GaussianDerivativeOperatorType; typedef itk::GaussianOperator<float, 2> GaussianOperatorType; typedef itk::ImageKernelOperator<float, 2> ImageKernelOperatorType; typedef itk::LaplacianOperator<float, 2> LaplacianOperatorType; typedef itk::SobelOperator<float, 2> SobelOperatorType; typedef itk::AnnulusOperator<float, 2> AnnulusOperatorType; typedef itk::BackwardDifferenceOperator<float, 2> BackwardDifferenceOperatorType;
std::vector<itk::NeighborhoodOperator<float, 2>*> operators; operators.push_back(new DerivativeOperatorType); operators.push_back(new ForwardDifferenceOperatorType); operators.push_back(new GaussianDerivativeOperatorType); operators.push_back(new GaussianOperatorType); operators.push_back(new ImageKernelOperatorType); operators.push_back(new LaplacianOperatorType); operators.push_back(new SobelOperatorType); operators.push_back(new AnnulusOperatorType); operators.push_back(new BackwardDifferenceOperatorType);
itk::Size<2> radius; radius.Fill(1); for(unsigned int operatorId = 0; operatorId < operators.size(); operatorId++) { operators[operatorId]->SetDirection(0); // Create the operator for the X axis derivative operators[operatorId]->CreateToRadius(radius); //std::cout << *(operators[operatorId]) << std::endl; //operators[operatorId]->Print(std::cout); //std::cout << operators[operatorId]->GetNameOfClass() << std::endl; for(int i = -operators[operatorId]->GetSize()[0]/2; i <= operators[operatorId]->GetSize()[0]/2; i++) { for(int j = -operators[operatorId]->GetSize()[1]/2; j <= operators[operatorId]->GetSize()[1]/2; j++) { itk::Offset<2> offset; offset[0] = i; offset[1] = j; unsigned int neighborhoodIndex = operators[operatorId]->GetNeighborhoodIndex(offset); std::cout << operators[operatorId]->GetElement(neighborhoodIndex) << " "; } std::cout << std::endl; } } return EXIT_SUCCESS;
}
</source>
CMakeLists.txt
<syntaxhighlight lang="cmake"> cmake_minimum_required(VERSION 3.9.5)
project(AntiAliasBinaryImageFilter)
find_package(ITK REQUIRED) include(${ITK_USE_FILE}) if (ITKVtkGlue_LOADED)
find_package(VTK REQUIRED) include(${VTK_USE_FILE})
endif()
add_executable(AntiAliasBinaryImageFilter MACOSX_BUNDLE AntiAliasBinaryImageFilter.cxx)
if( "${ITK_VERSION_MAJOR}" LESS 4 )
target_link_libraries(AntiAliasBinaryImageFilter ITKReview ${ITK_LIBRARIES})
else( "${ITK_VERSION_MAJOR}" LESS 4 )
target_link_libraries(AntiAliasBinaryImageFilter ${ITK_LIBRARIES})
endif( "${ITK_VERSION_MAJOR}" LESS 4 )
</syntaxhighlight>
Download and Build AntiAliasBinaryImageFilter
Click here to download AntiAliasBinaryImageFilter and its CMakeLists.txt file. Once the tarball AntiAliasBinaryImageFilter.tar has been downloaded and extracted,
cd AntiAliasBinaryImageFilter/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:
./AntiAliasBinaryImageFilter
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.