ITK/Examples/ImageProcessing/SquaredDifferenceImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Created page with "==SquaredDifferenceImageFilter.cxx== <source lang="cpp"> #include "itkImage.h" #include "itkSquaredDifferenceImageFilter.h" #include "itkImageRegionIterator.h" typedef itk::Imag...")
 
(Deprecated content that is moved to sphinx)
 
(2 intermediate revisions by one other user not shown)
Line 1: Line 1:
==SquaredDifferenceImageFilter.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 "itkSquaredDifferenceImageFilter.h"
#include "itkImageRegionIterator.h"
 
typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
typedef itk::Image<float, 2>  FloatImageType;
 
void CreateImage1(UnsignedCharImageType::Pointer image);
void CreateImage2(UnsignedCharImageType::Pointer image);
 
int main(int, char *[])
{
  UnsignedCharImageType::Pointer image1 = UnsignedCharImageType::New();
  CreateImage1(image1);
 
  UnsignedCharImageType::Pointer image2 = UnsignedCharImageType::New();
  CreateImage2(image2);
 
  typedef itk::SquaredDifferenceImageFilter <UnsignedCharImageType, UnsignedCharImageType,
                                            FloatImageType>
          SquaredDifferenceImageFilterType;
 
  SquaredDifferenceImageFilterType::Pointer squaredDifferenceFilter
          = SquaredDifferenceImageFilterType::New ();
  squaredDifferenceFilter->SetInput1(image1);
  squaredDifferenceFilter->SetInput2(image2);
  squaredDifferenceFilter->Update();
 
  return EXIT_SUCCESS;
}
 
void CreateImage1(UnsignedCharImageType::Pointer image)
{
  UnsignedCharImageType::IndexType start;
  start.Fill(0);
 
  UnsignedCharImageType::SizeType size;
  size.Fill(10);
 
  UnsignedCharImageType::RegionType region;
  region.SetSize(size);
  region.SetIndex(start);
 
  image->SetRegions(region);
  image->Allocate();
 
  itk::ImageRegionIterator<UnsignedCharImageType> imageIterator(image,region);
 
  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(255);
 
    ++imageIterator;
    }
}
 
 
void CreateImage2(UnsignedCharImageType::Pointer image)
{
  // Create an image with 2 connected components
  UnsignedCharImageType::IndexType start;
  start.Fill(0);
 
  UnsignedCharImageType::SizeType size;
  size.Fill(10);
 
   UnsignedCharImageType::RegionType region;
  region.SetSize(size);
  region.SetIndex(start);
 
  image->SetRegions(region);
  image->Allocate();
 
  itk::ImageRegionIterator<UnsignedCharImageType> imageIterator(image,region);
 
  while(!imageIterator.IsAtEnd())
    {
    imageIterator.Set(100);
 
    ++imageIterator;
    }
 
}
</source>
 
==CMakeLists.txt==
<source lang="cmake">
cmake_minimum_required(VERSION 2.6)
 
PROJECT(SquaredDifferenceImageFilter)
 
include_directories(/home/doriad/src/ITK/Wrapping/WrapITK/ExternalProjects/ItkVtkGlue/src/)
 
FIND_PACKAGE(VTK REQUIRED)
INCLUDE(${VTK_USE_FILE})
 
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})
 
ADD_EXECUTABLE(SquaredDifferenceImageFilter SquaredDifferenceImageFilter.cxx)
TARGET_LINK_LIBRARIES(SquaredDifferenceImageFilter
vtkHybrid
ITKBasicFilters ITKCommon ITKIO)
</source>

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