ITK  5.0.0
Insight Segmentation and Registration Toolkit
WikiExamples/ImageProcessing/ClampImageFilter.cxx
#include "itkImage.h"
using FloatImageType = itk::Image<float, 2>;
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
static void CreateImage(FloatImageType* const image);
int main(int argc, char *argv[])
{
FloatImageType::Pointer image;
// No input image argument provided
if(argc < 2)
{
image = FloatImageType::New();
CreateImage(image);
}
else // Input image argument provided
{
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(argv[1]);
reader->Update();
image = reader->GetOutput();
}
ClampFilterType::Pointer clampFilter = ClampFilterType::New();
clampFilter->SetInput(image);
clampFilter->Update();
return EXIT_SUCCESS;
}
void CreateImage(FloatImageType* const image)
{
// Create an image with 2 connected components
FloatImageType::IndexType corner = {{0,0}};
unsigned int NumRows = 200;
unsigned int NumCols = 300;
size[0] = NumRows;
size[1] = NumCols;
FloatImageType::RegionType region(corner, size);
image->SetRegions(region);
image->Allocate();
// Make a square
for(unsigned int r = 40; r < 100; r++)
{
for(unsigned int c = 40; c < 100; c++)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 15);
}
}
}