ITK/Examples/Morphology/BinaryPruningImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==BinaryPruningImageFilter.cxx==
{{warning|1=The media wiki content on this page is no longer maintainedThe 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 "itkBinaryPruningImageFilter.h"
#include "itkImageFileReader.h"
#include "itkBinaryBallStructuringElement.h"
#include "itkImageFileWriter.h"
 
#include "QuickView.h"
 
template <typename TImage>
void CreateImage(TImage* const image);
 
int main(int argc, char *argv[])
{
//  std::cerr << "Usage: " << std::endl;
//  std::cerr << argv[0] << " InputImageFile OutputImageFile [iteration]" << std::endl;
 
  typedef itk::Image<unsigned char, 2> ImageType;
  ImageType::Pointer image;
 
  unsigned int iteration = 1;
 
  if(argc < 3)
    {
    image = ImageType::New();
    CreateImage(image.GetPointer());
    }
  else
  {
    typedef itk::ImageFileReader<ImageType> ReaderType;
    ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName(argv[1]);
    image = reader->GetOutput();
    std::stringstream ssIteration(argv[2]);
  }
 
  typedef itk::BinaryPruningImageFilter <ImageType, ImageType >
          BinaryPruningImageFilterType;
  BinaryPruningImageFilterType::Pointer pruneFilter
          = BinaryPruningImageFilterType::New();
  pruneFilter->SetInput(image);
  pruneFilter->SetIteration(iteration);
  pruneFilter->GetOutput();
 
  QuickView viewer;
  viewer.AddImage(image.GetPointer());
  viewer.AddImage(pruneFilter->GetOutput());
  viewer.Visualize();
   
  return EXIT_SUCCESS;
}
 
template <typename TImage>
void CreateImage(TImage* const image)
{
  // This function creates a 2D image consisting of a black background,
  // a large square of a non-zero pixel value, and a single "erroneous" pixel
  // near the square.
   typename TImage::IndexType corner = {{0,0}};
 
  typename TImage::SizeType size = {{200,200}};
 
  typename TImage::RegionType region(corner, size);
 
  image->SetRegions(region);
  image->Allocate();
 
  // Make a square
  for(unsigned int r = 40; r < 100; r++)
    {
    for(unsigned int c = 40; c < 100; c++)
      {
      typename TImage::IndexType pixelIndex = {{r,c}};
      image->SetPixel(pixelIndex, 50);
      }
    }
 
  typename TImage::IndexType pixelIndex = {{102, 102}};
 
  image->SetPixel(pixelIndex, 50);
}
 
</source>
 
{{ITKCMakeLists|BinaryPruningImageFilter}}

Latest revision as of 17:59, 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.