ITK/Examples/ImageProcessing/ApproximateSignedDistanceMapImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==ApproximateSignedDistanceMapImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkImageFileWriter.h" #include "itkBinomialBlurImageFilter.h" #include "itkRes...")
 
(Deprecated content that is moved to sphinx)
 
(4 intermediate revisions by one other user not shown)
Line 1: Line 1:
==ApproximateSignedDistanceMapImageFilter.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 "itkImageFileWriter.h"
#include "itkBinomialBlurImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkApproximateSignedDistanceMapImageFilter.h"
 
typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
typedef itk::Image<float, 2>  FloatImageType;
static void CreateImage(UnsignedCharImageType::Pointer image);
 
int main(int argc, char * argv[])
{
  UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
  CreateImage(image);
 
  typedef  itk::ApproximateSignedDistanceMapImageFilter< UnsignedCharImageType, FloatImageType  > ApproximateSignedDistanceMapImageFilterType;
  ApproximateSignedDistanceMapImageFilterType::Pointer approximateSignedDistanceMapImageFilter = ApproximateSignedDistanceMapImageFilterType::New();
  approximateSignedDistanceMapImageFilter->SetInput(image);
  approximateSignedDistanceMapImageFilter->SetInsideValue(255);
  approximateSignedDistanceMapImageFilter->SetOutsideValue(0);
  approximateSignedDistanceMapImageFilter->Update();
 
  typedef itk::RescaleIntensityImageFilter< FloatImageType, UnsignedCharImageType > RescaleFilterType;
  RescaleFilterType::Pointer rescaleFilter = RescaleFilterType::New();
  rescaleFilter->SetInput(approximateSignedDistanceMapImageFilter->GetOutput());
  rescaleFilter->SetOutputMinimum(0);
  rescaleFilter->SetOutputMaximum(255);
  rescaleFilter->Update();
 
  typedef  itk::ImageFileWriter< UnsignedCharImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("output.png");
  writer->SetInput(rescaleFilter->GetOutput());
  writer->Update();
 
  return EXIT_SUCCESS;
}
 
 
void CreateImage(UnsignedCharImageType::Pointer image)
{
  // Create an image
  itk::Index<2> start;
  start.Fill(0);
  itk::Size<2> size;
  size.Fill(100);
   itk::ImageRegion<2> region(start, size);
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
  // Create a line of white pixels
  for(unsigned int i = 40; i < 60; ++i)
    {
    itk::Index<2> pixel;
    pixel.Fill(i);
    image->SetPixel(pixel, 255);
    }
 
  typedef  itk::ImageFileWriter< UnsignedCharImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("input.png");
  writer->SetInput(image);
  writer->Update();
}
 
</source>
 
{{ITKCMakeLists|ApproximateSignedDistanceMapImageFilter}}

Latest revision as of 14:31, 5 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.