ITK/Examples/Morphology/BinaryMorphologicalClosingImageFilter: Difference between revisions
From KitwarePublic
Jump to navigationJump to search
Arnaudgelas (talk | contribs) (Created page with "==BinaryMorphologicalOpeningImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkBinaryMorphologicalClosingImageFilter.h" #include "itkImageFileReader.h" #inc...") |
Arnaudgelas (talk | contribs) |
||
Line 12: | Line 12: | ||
{ | { | ||
std::cerr << "Usage: " << std::endl; | std::cerr << "Usage: " << std::endl; | ||
std::cerr << argv[0] << " InputImageFile [radius]" << std::endl; | std::cerr << argv[0] << " InputImageFile OutputImageFile [radius]" << std::endl; | ||
return EXIT_FAILURE; | return EXIT_FAILURE; | ||
} | } |
Revision as of 16:21, 15 December 2011
BinaryMorphologicalOpeningImageFilter.cxx
<source lang="cpp">
- include "itkImage.h"
- include "itkBinaryMorphologicalClosingImageFilter.h"
- include "itkImageFileReader.h"
- include "itkBinaryBallStructuringElement.h"
- include "itkImageFileWriter.h"
int main(int argc, char *argv[]) {
if(argc < 3) { std::cerr << "Usage: " << std::endl; std::cerr << argv[0] << " InputImageFile OutputImageFile [radius]" << std::endl; return EXIT_FAILURE; }
unsigned int radius = 2; if (argc > 3) { radius = atoi(argv[3]); }
const unsigned Dimension = 3; typedef unsigned char PixelType; typedef itk::Image< PixelType, Dimension > ImageType; typedef itk::ImageFileReader<ImageType> ReaderType; ReaderType::Pointer reader = ReaderType::New(); reader->SetFileName(argv[1]); reader->Update();
typedef itk::BinaryBallStructuringElement< PixelType, Dimension > StructuringElementType; StructuringElementType structuringElement; structuringElement.SetRadius(radius); structuringElement.CreateStructuringElement();
typedef itk::BinaryMorphologicalClosingImageFilter <ImageType, ImageType, StructuringElementType> BinaryMorphologicalClosingImageFilterType;
BinaryMorphologicalClosingImageFilterType::Pointer dilateFilter = BinaryMorphologicalClosingImageFilterType::New(); dilateFilter->SetInput(reader->GetOutput()); dilateFilter->SetKernel(structuringElement);
typedef itk::ImageFileWriter< ImageType > WriterType; WriterType::Pointer writer = WriterType::New(); writer->SetInput( dilateFilter->GetOutput() ); writer->SetFileName( argv[2] ); writer->Update();
return EXIT_SUCCESS;
}
</source>
CMakeLists.txt
<syntaxhighlight lang="cmake"> cmake_minimum_required(VERSION 2.6)
project(BinaryMorphologicalClosingImageFilter)
find_package(ITK REQUIRED) include(${ITK_USE_FILE})
add_executable(BinaryMorphologicalClosingImageFilter BinaryMorphologicalClosingImageFilter.cxx) target_link_libraries(BinaryMorphologicalClosingImageFilter ${ITK_LIBRARIES})
</syntaxhighlight>