ITK/Examples/ImageProcessing/BinaryThinningImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==BinaryThinningImageFilter.cxx== <source lang="cpp"> #include "itkBinaryThinningImageFilter.h" #include "itkImage.h" #include "itkImageFileWriter.h" #include "itkRescaleIntensit...")
 
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by 2 users not shown)
Line 1: Line 1:
==BinaryThinningImageFilter.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 "itkBinaryThinningImageFilter.h"
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
 
typedef itk::Image<unsigned char, 2> ImageType;
 
static void WriteImage(const ImageType::Pointer image, const std::string& fileName);
static void CreateImage(ImageType::Pointer image);
 
int main(int, char *[])
{
  ImageType::Pointer image = ImageType::New();
  CreateImage(image);
  WriteImage(image, "input.png");
 
  typedef itk::BinaryThinningImageFilter <ImageType, ImageType> BinaryThinningImageFilterType;
  BinaryThinningImageFilterType::Pointer binaryThinningImageFilter = BinaryThinningImageFilterType::New();
  binaryThinningImageFilter->SetInput(image);
  binaryThinningImageFilter->Update();
 
  // Rescale the image so that it can be seen (the output is 0 and 1, we want 0 and 255)
  typedef itk::RescaleIntensityImageFilter< ImageType, ImageType > RescaleType;
  RescaleType::Pointer rescaler = RescaleType::New();
  rescaler->SetInput( binaryThinningImageFilter->GetOutput() );
  rescaler->SetOutputMinimum(0);
  rescaler->SetOutputMaximum(255);
  rescaler->Update();
 
  WriteImage(rescaler->GetOutput(), "output.png");
 
  return EXIT_SUCCESS;
}
 
void CreateImage(ImageType::Pointer image)
{
  // Create an image
  ImageType::IndexType start;
  start.Fill(0);
 
  ImageType::SizeType size;
  size.Fill(100);
 
   ImageType::RegionType region(start,size);
 
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
 
  // Draw a 5 pixel wide line
  for(unsigned int i = 20; i < 80; ++i)
    {
    for(unsigned int j = 50; j < 55; ++j)
      {
      itk::Index<2> index;
      index[0] = i;
      index[1] = j;
      image->SetPixel(index, 255);
      }
    }
}
 
void WriteImage(const ImageType::Pointer image, const std::string& fileName)
{
  typedef  itk::ImageFileWriter< ImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName(fileName);
  writer->SetInput(image);
  writer->Update();
}
 
</source>
 
{{ITKCMakeLists|BinaryThinningImageFilter}}

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