Apply a Filter Only to a Specified Image Region#
Synopsis#
To apply a filter to only operate on a specified ImageRegion.
Results#
Output:
Created random image.
Computed derivative.
Code#
C++#
#include "itkImage.h"
#include "itkRandomImageSource.h"
#include "itkDerivativeImageFilter.h"
int
main()
{
using ImageType = itk::Image<float, 2>;
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->SetNumberOfWorkUnits(1); // to produce non-random results
randomImageSource->SetSize(bigSize);
randomImageSource->GetOutput()->SetRequestedRegion(smallSize);
randomImageSource->Update();
std::cout << "Created random image." << std::endl;
using DerivativeImageFilterType = itk::DerivativeImageFilter<ImageType, ImageType>;
auto 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;
}
Classes demonstrated#
-
template<typename TInputImage, typename TOutputImage>
class DerivativeImageFilter : public itk::ImageToImageFilter<TInputImage, TOutputImage> Computes the directional derivative of an image. The directional derivative at each pixel location is computed by convolution with a derivative operator of user-specified order.
SetOrder specifies the order of the derivative.
SetDirection specifies the direction of the derivative with respect to the coordinate axes of the image.
- See
Image
- See
Neighborhood
- See
NeighborhoodOperator
- See
NeighborhoodIterator
- ITK Sphinx Examples: