ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Transform/ScaleAnImage/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"
int
main(int argc, char * argv[])
{
if (argc < 3)
{
std::cerr << "Usage: " << argv[0] << " inputFile outputFile" << std::endl;
}
using PixelType = unsigned char;
constexpr unsigned int ImageDimension = 2;
auto image = itk::ReadImage<ImageType>(argv[1]);
using MetricValueType = double;
auto scaleTransform = TransformType::New();
scale[0] = 1.5; // newWidth/oldWidth
scale[1] = 1.5;
scaleTransform->SetScale(scale);
center[0] = image->GetLargestPossibleRegion().GetSize()[0] / 2;
center[1] = image->GetLargestPossibleRegion().GetSize()[1] / 2;
scaleTransform->SetCenter(center);
auto resampleFilter = ResampleImageFilterType::New();
resampleFilter->SetTransform(scaleTransform);
resampleFilter->SetInput(image);
resampleFilter->SetSize(image->GetLargestPossibleRegion().GetSize());
resampleFilter->Update();
itk::WriteImage(resampleFilter->GetOutput(), argv[2]);
return EXIT_SUCCESS;
}
itkImageFileReader.h
itkImage.h
itk::ScaleTransform
Scale transformation of a vector space (e.g. space coordinates)
Definition: itkScaleTransform.h:45
itk::FixedArray
Simulate a standard C array with copy semantics.
Definition: itkFixedArray.h:53
itkImageFileWriter.h
itk::ResampleImageFilter
Resample an image via a coordinate transform.
Definition: itkResampleImageFilter.h:90
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()
itkResampleImageFilter.h
itk::WriteImage
ITK_TEMPLATE_EXPORT void WriteImage(TImagePointer &&image, const std::string &filename, bool compress=false)
Definition: itkImageFileWriter.h:256
itkScaleTransform.h