Multiresolution Pyramid From Image#
Synopsis#
Construct a multiresolution pyramid from an image.
Results#
Output:
Writing output_0.png
Writing output_1.png
Writing output_2.png
Writing output_3.png
Code#
C++#
#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkRecursiveMultiResolutionPyramidImageFilter.h"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(UnsignedCharImageType::Pointer image);
int
main()
{
auto image = UnsignedCharImageType::New();
CreateImage(image);
using FloatImageType = itk::Image<float, 2>;
unsigned int numberOfLevels = 4;
using RecursiveMultiResolutionPyramidImageFilterType =
itk::RecursiveMultiResolutionPyramidImageFilter<UnsignedCharImageType, FloatImageType>;
RecursiveMultiResolutionPyramidImageFilterType::Pointer recursiveMultiResolutionPyramidImageFilter =
RecursiveMultiResolutionPyramidImageFilterType::New();
recursiveMultiResolutionPyramidImageFilter->SetInput(image);
recursiveMultiResolutionPyramidImageFilter->SetNumberOfLevels(numberOfLevels);
recursiveMultiResolutionPyramidImageFilter->Update();
// This outputs the levels (0 is the lowest resolution)
for (unsigned int i = 0; i < numberOfLevels; ++i)
{
// Scale so we can write to a PNG
using RescaleFilterType = itk::RescaleIntensityImageFilter<FloatImageType, UnsignedCharImageType>;
auto rescaleFilter = RescaleFilterType::New();
rescaleFilter->SetInput(recursiveMultiResolutionPyramidImageFilter->GetOutput(i));
rescaleFilter->SetOutputMinimum(0);
rescaleFilter->SetOutputMaximum(255);
rescaleFilter->Update();
std::stringstream ss;
ss << "output_" << i << ".png";
std::cout << "Writing " << ss.str() << std::endl;
itk::WriteImage(rescaleFilter->GetOutput(), ss.str());
}
return EXIT_SUCCESS;
}
void
CreateImage(UnsignedCharImageType::Pointer image)
{
// Create a black image with a white region
UnsignedCharImageType::IndexType start;
start.Fill(0);
UnsignedCharImageType::SizeType size;
size.Fill(200);
UnsignedCharImageType::RegionType region(start, size);
image->SetRegions(region);
image->Allocate();
image->FillBuffer(0);
// Make a square
for (unsigned int r = 20; r < 80; ++r)
{
for (unsigned int c = 30; c < 100; ++c)
{
UnsignedCharImageType::IndexType pixelIndex;
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 255);
}
}
}
Classes demonstrated#
-
template<typename TInputImage, typename TOutputImage>
class RecursiveMultiResolutionPyramidImageFilter : public itk::MultiResolutionPyramidImageFilter<TInputImage, TOutputImage> Creates a multi-resolution pyramid using a recursive implementation.
RecursiveMultiResolutionPyramidImageFilter creates an image pryamid according to a user defined multi-resolution schedule.
If a schedule is downward divisible, a fast recursive implementation is used to generate the output images. If the schedule is not downward divisible the superclass (MultiResolutionPyramidImageFilter) implementation is used instead. A schedule is downward divisible if at every level, the shrink factors are divisible by the shrink factors at the next level for the same dimension.
See documentation of MultiResolutionPyramidImageFilter for information on how to specify a multi-resolution schedule.
Note that unlike the MultiResolutionPyramidImageFilter, RecursiveMultiResolutionPyramidImageFilter will not smooth the output at the finest level if the shrink factors are all one and the schedule is downward divisible.
This class is templated over the input image type and the output image type.
This filter uses multithreaded filters to perform the smoothing and downsampling.
This filter supports streaming.
- See
MultiResolutionPyramidImageFilter
- ITK Sphinx Examples: