ITK  5.0.0
Insight Segmentation and Registration Toolkit
WikiExamples/ImageProcessing/AbsImageFilter.cxx
#include "itkImage.h"
#include "QuickView.h"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
using FloatImageType = itk::Image<float, 2>;
static void CreateImage(FloatImageType::Pointer image);
int main(int, char *[])
{
FloatImageType::Pointer image = FloatImageType::New();
CreateImage(image);
// Take the absolute value of the image
AbsImageFilterType::Pointer absFilter
= AbsImageFilterType::New ();
absFilter->SetInput(image);
QuickView viewer;
viewer.AddImage<FloatImageType>(image);
viewer.AddImage<FloatImageType>(absFilter->GetOutput());
viewer.Visualize();
return EXIT_SUCCESS;
}
void CreateImage(FloatImageType::Pointer image)
{
// Create an image with negative values
start[0] = 0;
start[1] = 0;
size[0] = 200;
size[1] = 300;
region.SetSize(size);
region.SetIndex(start);
image->SetRegions(region);
image->Allocate();
itk::ImageRegionIterator<FloatImageType> imageIterator(image,region);
while(!imageIterator.IsAtEnd())
{
imageIterator.Set(imageIterator.GetIndex()[0] - imageIterator.GetIndex()[1]);
++imageIterator;
}
}