Transform Magnitude of Vector Valued Image Pixels#

Synopsis#

Apply a transformation to the magnitude of vector valued image pixels.

Results#

input image

Input image.#

output.png

output.png#

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkVectorRescaleIntensityImageFilter.h"
#include "itkCastImageFilter.h"

int
main(int argc, char * argv[])
{
  if (argc < 3)
  {
    std::cerr << "Required: input output" << std::endl;
    return EXIT_FAILURE;
  }

  std::string inputFileName = argv[1];
  std::string outputFileName = argv[2];

  using FloatImageType = itk::Image<itk::CovariantVector<float, 3>, 2>;
  using UnsignedCharImageType = itk::Image<itk::CovariantVector<unsigned char, 3>, 2>;

  const auto input = itk::ReadImage<FloatImageType>(inputFileName);

  using VectorRescaleFilterType = itk::VectorRescaleIntensityImageFilter<FloatImageType, UnsignedCharImageType>;
  auto rescaleFilter = VectorRescaleFilterType::New();
  rescaleFilter->SetInput(input);
  rescaleFilter->SetOutputMaximumMagnitude(255);
  rescaleFilter->Update();

  itk::WriteImage(rescaleFilter->GetOutput(), outputFileName);

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage = TInputImage>
class VectorRescaleIntensityImageFilter : public itk::UnaryFunctorImageFilter<TInputImage, TOutputImage, Functor::VectorMagnitudeLinearTransform<TInputImage::PixelType, TOutputImage::PixelType>>

Applies a linear transformation to the magnitude of pixel vectors in a vector Image.

VectorRescaleIntensityImageFilter applies pixel-wise a linear transformation to the intensity values of input image pixels. The linear transformation is defined by the user in terms of the maximum magnitude value of the vectors in the pixels that the output image should have.

All computations are performed in the precision of the input pixel’s RealType. Before assigning the computed value to the output pixel.

See

RescaleIntensityImageFilter

ITK Sphinx Examples:

See itk::VectorRescaleIntensityImageFilter for additional documentation.