ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Core/ImageFunction/ComputeMedianOfImageAtPixel/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkImage.h"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
void
CreateImage(UnsignedCharImageType::Pointer image);
int
main(int, char *[])
{
UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
CreateImage(image);
using MedianImageFunctionType = itk::MedianImageFunction<UnsignedCharImageType>;
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();
}
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:66
itk::Size< 2 >
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:69
itkMedianImageFunction.h
itkImage.h
itkImageRegionIterator.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:270
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:211
itk::ImageRegionIterator
A multi-dimensional iterator templated over image type that walks a region of pixels.
Definition: itkImageRegionIterator.h:80
itk::ImageFileWriter
Writes image data to a single file.
Definition: itkImageFileWriter.h:88
itkImageFileWriter.h
itk::MedianImageFunction
Calculate the median value in the neighborhood of a pixel.
Definition: itkMedianImageFunction.h:49
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86