ITK/Examples/EdgesAndGradients/BinaryBoundaries: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Procedures should be static for test driver)
(Deprecated content that is moved to sphinx)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
<div class="floatcenter">[[File:ITK_Examples_Baseline_EdgesAndGradients_TestBinaryBoundaries.png]]</div>
{{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.}}
==BinaryBoundaries.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkInvertIntensityImageFilter.h"
#include "itkBinaryContourImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
 
#include "QuickView.h"
 
typedef itk::Image<unsigned char, 2> ImageType;
 
static void CreateImage(ImageType::Pointer image);
 
int main(int, char *[])
{
  ImageType::Pointer image = ImageType::New();
  CreateImage(image);
 
  typedef itk::BinaryContourImageFilter <ImageType, ImageType >
          binaryContourImageFilterType;
 
  // Outer boundary
  binaryContourImageFilterType::Pointer binaryContourFilter
          = binaryContourImageFilterType::New ();
  binaryContourFilter->SetInput(image);
  binaryContourFilter->SetForegroundValue(0);
  binaryContourFilter->SetBackgroundValue(255);
  binaryContourFilter->Update();
 
  // Invert the result
  typedef itk::InvertIntensityImageFilter <ImageType>
          InvertIntensityImageFilterType;
 
  InvertIntensityImageFilterType::Pointer invertIntensityFilter
          = InvertIntensityImageFilterType::New();
  invertIntensityFilter->SetInput(binaryContourFilter->GetOutput());
  invertIntensityFilter->Update();
 
  ImageType::Pointer outerBoundary = ImageType::New();
  outerBoundary->Graft(invertIntensityFilter->GetOutput());
 
  // Inner boundary
  binaryContourFilter->SetForegroundValue(255);
  binaryContourFilter->SetBackgroundValue(0);
  binaryContourFilter->Update();
 
  QuickView viewer;
  viewer.AddImage(image.GetPointer());
   viewer.AddImage(outerBoundary.GetPointer());
  viewer.AddImage(binaryContourFilter->GetOutput());
  viewer.Visualize();
 
  return EXIT_SUCCESS;
}
 
void CreateImage(ImageType::Pointer image)
{
  ImageType::IndexType start;
  start.Fill(0);
 
  ImageType::SizeType size;
  size.Fill(20);
 
  ImageType::RegionType region(start, size);
 
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(0);
 
  // Make a square
  for(unsigned int r = 5; r < 10; r++)
    {
    for(unsigned int c = 5; c < 10; c++)
      {
      ImageType::IndexType pixelIndex;
      pixelIndex[0] = r;
      pixelIndex[1] = c;
 
      image->SetPixel(pixelIndex, 255);
      }
    }
 
}
</source>
 
==CMakeLists.txt==
<source lang="cmake">
cmake_minimum_required(VERSION 2.6)
 
PROJECT(BinaryBoundaries)
 
include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/)
include_directories(/home/doriad/ITKWikiExamples/ItkVtkGlue)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
 
ADD_EXECUTABLE(BinaryBoundaries BinaryBoundaries.cxx /home/doriad/ITKWikiExamples/ItkVtkGlue/QuickView.cxx)
TARGET_LINK_LIBRARIES(BinaryBoundaries
vtkHybrid
ITKBasicFilters ITKCommon ITKIO)
</source>

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