ITK  5.4.0
Insight Toolkit
SphinxExamples/src/Registration/Common/MultiresolutionPyramidFromImage/Code.cxx
/*=========================================================================
*
* Copyright NumFOCUS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0.txt
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*=========================================================================*/
#include "itkImage.h"
using UnsignedCharImageType = itk::Image<unsigned char, 2>;
static void
CreateImage(UnsignedCharImageType::Pointer image);
int
main()
{
CreateImage(image);
using FloatImageType = itk::Image<float, 2>;
unsigned int numberOfLevels = 4;
using RecursiveMultiResolutionPyramidImageFilterType =
RecursiveMultiResolutionPyramidImageFilterType::Pointer recursiveMultiResolutionPyramidImageFilter =
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
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
{
// Create a black image with a white region
start.Fill(0);
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)
{
pixelIndex[0] = r;
pixelIndex[1] = c;
image->SetPixel(pixelIndex, 255);
}
}
}
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::GTest::TypedefsAndConstructors::Dimension2::SizeType
ImageBaseType::SizeType SizeType
Definition: itkGTestTypedefsAndConstructors.h:49
itkImage.h
itk::Index::Fill
void Fill(IndexValueType value)
Definition: itkIndex.h:274
itk::Size::Fill
void Fill(SizeValueType value)
Definition: itkSize.h:213
itk::RecursiveMultiResolutionPyramidImageFilter
Creates a multi-resolution pyramid using a recursive implementation.
Definition: itkRecursiveMultiResolutionPyramidImageFilter.h:64
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::GTest::TypedefsAndConstructors::Dimension2::RegionType
ImageBaseType::RegionType RegionType
Definition: itkGTestTypedefsAndConstructors.h:54
itkRescaleIntensityImageFilter.h
itkImageFileWriter.h
itkRecursiveMultiResolutionPyramidImageFilter.h
itk::RescaleIntensityImageFilter
Applies a linear transformation to the intensity levels of the input Image.
Definition: itkRescaleIntensityImageFilter.h:133
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()
itk::WriteImage
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
Definition: itkImageFileWriter.h:254