ITK/Examples/SimpleOperations/RequestedRegion: Difference between revisions

From KitwarePublic
< ITK‎ | Examples
Jump to navigationJump to search
No edit summary
(Deprecated content that is moved to sphinx)
 
Line 1: Line 1:
The key of using SetRequestedRegion to tell a filter to only operate on a specified ImageRegion is to call SetRequestedRegion on the filters GetOutput(). That is, to tell the DerivativeImageFilter to only operate on a small region, you must do:
{{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.
}}


derivativeFilter->GetOutput()->SetRequestedRegion(smallRegion);
[https://itk.org/ITKExamples[ITK Sphinx Examples]]
derivativeFilter->Update();
 
==RequestedRegion.cxx==
<source lang="cpp">
#include "itkImage.h"
#include "itkRandomImageSource.h"
#include "itkDerivativeImageFilter.h"
 
int main(int, char *[])
{
  typedef itk::Image<float, 2> ImageType;
 
  itk::Size<2> smallSize;
  smallSize.Fill(10);
 
  itk::Index<2> index;
  index.Fill(0);
 
  itk::ImageRegion<2> region(index, smallSize);
 
  itk::Size<2> bigSize;
  bigSize.Fill(10000);
 
  itk::RandomImageSource<ImageType>::Pointer randomImageSource = itk::RandomImageSource<ImageType>::New();
  randomImageSource->SetNumberOfThreads(1); // to produce non-random results
  randomImageSource->SetSize(bigSize);
  randomImageSource->GetOutput()->SetRequestedRegion(smallSize);
  randomImageSource->Update();
 
  std::cout << "Created random image." << std::endl;
 
  typedef itk::DerivativeImageFilter<ImageType, ImageType >  DerivativeImageFilterType;
  DerivativeImageFilterType::Pointer derivativeFilter = DerivativeImageFilterType::New();
  derivativeFilter->SetInput( randomImageSource->GetOutput() );
  derivativeFilter->SetDirection(0); // "x" axis
  derivativeFilter->GetOutput()->SetRequestedRegion(smallSize);
  derivativeFilter->Update();
 
  std::cout << "Computed derivative." << std::endl;
 
  return EXIT_SUCCESS;
}
 
</source>
 
{{ITKCMakeLists|{{SUBPAGENAME}}}}

Latest revision as of 14:25, 4 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.

[ITK Sphinx Examples]