ITK/Examples/Morphology/BinaryMorphologicalClosingImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==BinaryMorphologicalOpeningImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkBinaryMorphologicalClosingImageFilter.h" #include "itkImageFileReader.h" #inc...")
 
(Deprecated content that is moved to sphinx)
 
(9 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==BinaryMorphologicalOpeningImageFilter.cxx==
{{warning|1=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 releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.}}
<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 [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==
{{#tag:syntaxhighlight
|
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})
 
|lang=cmake}}

Latest revision as of 18:54, 6 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.