ITK/Examples/ImageProcessing/SquaredDifferenceImageFilter
SquaredDifferenceImageFilter.cxx
<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>