ITK/Examples/ImageProcessing/ZeroCrossingImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
==ZeroCrossingImageFilter.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 "itkZeroCrossingImageFilter.h"
 
typedef itk::Image<float, 2> FloatImageType;
 
static void CreateImage(FloatImageType::Pointer image);
 
int main(int argc, char *argv[])
{
  typedef itk::Image<unsigned char, 2>  UnsignedCharImageType;
 
  FloatImageType::Pointer image = FloatImageType::New();
  CreateImage(image);
 
  typedef itk::ZeroCrossingImageFilter< FloatImageType, UnsignedCharImageType  > ZeroCrossingImageFilterType;
  ZeroCrossingImageFilterType::Pointer zeroCrossingImageFilter = ZeroCrossingImageFilterType::New();
  zeroCrossingImageFilter->SetInput(image);
  zeroCrossingImageFilter->SetBackgroundValue(0);
  zeroCrossingImageFilter->SetForegroundValue(255);
  zeroCrossingImageFilter->Update();
   
  typedef  itk::ImageFileWriter< UnsignedCharImageType  > WriterType;
  WriterType::Pointer writer = WriterType::New();
  writer->SetFileName("output.png");
  writer->SetInput(zeroCrossingImageFilter->GetOutput());
  writer->Update();
 
  return 0;
}
 
void CreateImage(FloatImageType::Pointer 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(-1);
 
  // Make half of the image negative
  for(unsigned int i = 0; i < 100; ++i)
    {
    for(unsigned int j = 0; j < 50; ++j)
      {
      itk::Index<2> index;
      index[0] = i;
      index[1] = j;
      image->SetPixel(index, 1);
      }
    }
}
 
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

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