ITK  4.13.0
Insight Segmentation and Registration Toolkit
WikiExamples/ImageProcessing/SquaredDifferenceImageFilter.cxx
#include "itkImage.h"
typedef itk::Image<unsigned char, 2> UnsignedCharImageType;
typedef itk::Image<float, 2> FloatImageType;
static void CreateImage1(UnsignedCharImageType::Pointer image);
static 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)
{
start.Fill(0);
size.Fill(10);
UnsignedCharImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
while(!imageIterator.IsAtEnd())
{
imageIterator.Set(255);
++imageIterator;
}
}
void CreateImage2(UnsignedCharImageType::Pointer image)
{
// Create an image with 2 connected components
start.Fill(0);
size.Fill(10);
UnsignedCharImageType::RegionType region;
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
while(!imageIterator.IsAtEnd())
{
imageIterator.Set(100);
++imageIterator;
}
}