ITK  4.8.0
Insight Segmentation and Registration Toolkit
WikiExamples/Functions/MedianImageFunction.cxx
#include "itkImage.h"
typedef itk::Image< unsigned char, 2 > UnsignedCharImageType;
void CreateImage(UnsignedCharImageType::Pointer image);
int main( int, char *[] )
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
typedef itk::MedianImageFunction< UnsignedCharImageType > MedianImageFunctionType;
MedianImageFunctionType::Pointer medianImageFunction = MedianImageFunctionType::New();
medianImageFunction->SetInputImage( image );
index.Fill(10);
std::cout << "Median at " << index << " is " << static_cast<int>(medianImageFunction->EvaluateAtIndex(index)) << std::endl;
return EXIT_SUCCESS;
}
void CreateImage(UnsignedCharImageType::Pointer image)
{
start.Fill(0);
size.Fill(100);
itk::ImageRegion<2> region(start,size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
while(!imageIterator.IsAtEnd())
{
if(imageIterator.GetIndex()[0] >= 50 && imageIterator.GetIndex()[1] >= 50 &&
imageIterator.GetIndex()[0] <= 70 && imageIterator.GetIndex()[1] <= 70)
{
imageIterator.Set(255);
}
++imageIterator;
}
WriterType::Pointer writer = WriterType::New();
writer->SetFileName("input.png");
writer->SetInput(image);
writer->Update();
}