ITK/Examples/ImageProcessing/ExtractImageFilter: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
(Unused argc/argv)
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
==ExtractImageFilter.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 releasesIn many cases, the examples on this page no longer conform to the best practices for modern ITK versions.
<source lang="cpp">
}}
// This is different from CropImageFilter only in the way
// that the region to crop is specified.
#include "itkImage.h"
#include <itkImageFileReader.h>
#include <itkExtractImageFilter.h>
 
int main(int, char *[])
{
  typedef itk::Image<unsigned char, 2> ImageType;
 
  ImageType::IndexType start;
  start.Fill(0);
 
  ImageType::SizeType size;
  size.Fill(10);
 
   ImageType::RegionType region(start, size);
 
  ImageType::Pointer image = ImageType::New();
  image->SetRegions(region);
  image->Allocate();
  image->FillBuffer(5);
 
  std::cout << "Image largest region: " << image->GetLargestPossibleRegion() << std::endl;
 
  ImageType::IndexType desiredStart;
  desiredStart.Fill(3);
 
  ImageType::SizeType desiredSize;
  desiredSize.Fill(4);
 
  ImageType::RegionType desiredRegion(desiredStart, desiredSize);
 
  std::cout << "desiredRegion: " << desiredRegion << std::endl;
 
  typedef itk::ExtractImageFilter< ImageType, ImageType > FilterType;
  FilterType::Pointer filter = FilterType::New();
  filter->SetExtractionRegion(desiredRegion);
  filter->SetInput(image);
#if ITK_VERSION_MAJOR >= 4
  filter->SetDirectionCollapseToIdentity(); // This is required.
#endif
  filter->Update();
 
  ImageType::Pointer output = filter->GetOutput();
  output->DisconnectPipeline();
  output->FillBuffer(2);
 
  itk::Index<2> index;
  index.Fill(5);
 
  std::cout << "new largest region: " << output->GetLargestPossibleRegion() << std::endl;
  std::cout << "new: " << (int)output->GetPixel(index) << std::endl;
  std::cout << "Original: " << (int)image->GetPixel(index) << std::endl;
 
  return EXIT_SUCCESS;
}
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 19:20, 5 June 2019

Warning: 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.