ITK  6.0.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
*
* https://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()
{
CreateImage(image);
using MedianImageFunctionType = itk::MedianImageFunction<UnsignedCharImageType>;
auto 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
{
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;
}
itk::WriteImage(image, "input.png");
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Size< 2 >
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itkMedianImageFunction.h
itkImage.h
itkImageRegionIterator.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:272
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
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:88
New
static Pointer New()
itk::WriteImage
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
Definition: itkImageFileWriter.h:256