|
|
(2 intermediate revisions by one other user not shown) |
Line 1: |
Line 1: |
| ==MedianImageFunction.cxx==
| | {{warning|1=The media wiki content on this page is no longer maintained. The examples presented on the https://itk.org/Wiki/* pages likely require ITK version 4.13 or earlier releases. In many cases, the examples on this page no longer conform to the best practices for modern ITK versions. |
| <source lang="cpp">
| | }} |
| #include "itkImage.h"
| |
| #include "itkImageFileWriter.h"
| |
| #include "itkImageRegionIterator.h"
| |
| #include "itkMedianImageFunction.h"
| |
| | |
| typedef itk::Image< unsigned char, 2 > UnsignedCharImageType;
| |
| | |
| void CreateImage(UnsignedCharImageType::Pointer image);
| |
| | |
| int main( int argc, char * argv[] )
| |
| { | |
| UnsignedCharImageType::Pointer image = UnsignedCharImageType::New();
| |
| CreateImage(image);
| |
|
| |
| typedef itk::MedianImageFunction< UnsignedCharImageType > MedianImageFunctionType;
| |
| MedianImageFunctionType::Pointer medianImageFunction = MedianImageFunctionType::New();
| |
| medianImageFunction->SetInputImage( image );
| |
|
| |
| itk::Index<2> index;
| |
| 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)
| |
| {
| |
| itk::Index<2> start;
| |
| start.Fill(0);
| |
|
| |
| itk::Size<2> size;
| |
| size.Fill(100);
| |
| | |
| itk::ImageRegion<2> region(start,size);
| |
|
| |
| image->SetRegions(region);
| |
| image->Allocate();
| |
| image->FillBuffer(0);
| |
|
| |
| itk::ImageRegionIterator<UnsignedCharImageType> imageIterator(image,region);
| |
| | |
| while(!imageIterator.IsAtEnd())
| |
| {
| |
| if(imageIterator.GetIndex()[0] >= 50 && imageIterator.GetIndex()[1] >= 50 &&
| |
| imageIterator.GetIndex()[0] <= 70 && imageIterator.GetIndex()[1] <= 70)
| |
| {
| |
| imageIterator.Set(255);
| |
| }
| |
|
| |
| ++imageIterator;
| |
| }
| |
|
| |
| typedef itk::ImageFileWriter < UnsignedCharImageType > WriterType; | |
| WriterType::Pointer writer = WriterType::New();
| |
| writer->SetFileName("input.png");
| |
| writer->SetInput(image);
| |
| writer->Update();
| |
| }
| |
| | |
| </source>
| |
| | |
| | |
| {{ITKCMakeLists|MedianImageFunction}}
| |