Multiply Two Images#
Synopsis#
Multiply two images
Results#
Code#
C++#
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkMultiplyImageFilter.h"
int
main(int argc, char * argv[])
{
if (argc != 4)
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0];
std::cerr << " <InputFileName 1> <InputFileName 2> <OutputFileName>";
std::cerr << std::endl;
return EXIT_FAILURE;
}
const char * inputFileName1 = argv[1];
const char * inputFileName2 = argv[2];
const char * outputFileName = argv[3];
constexpr unsigned int Dimension = 2;
using InputPixelType = unsigned char;
using InputImageType = itk::Image<InputPixelType, Dimension>;
const auto input1 = itk::ReadImage<InputImageType>(inputFileName1);
const auto input2 = itk::ReadImage<InputImageType>(inputFileName2);
using OutputPixelType = unsigned int;
using OutputImageType = itk::Image<OutputPixelType, Dimension>;
using FilterType = itk::MultiplyImageFilter<InputImageType, InputImageType, OutputImageType>;
auto filter = FilterType::New();
filter->SetInput1(input1);
filter->SetInput2(input2);
try
{
itk::WriteImage(filter->GetOutput(), outputFileName);
}
catch (const itk::ExceptionObject & error)
{
std::cerr << "Error: " << error << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Classes demonstrated#
-
template<typename TInputImage1, typename TInputImage2 = TInputImage1, typename TOutputImage = TInputImage1>
class MultiplyImageFilter : public itk::BinaryGeneratorImageFilter<TInputImage1, TInputImage2, TOutputImage> Pixel-wise multiplication of two images.
This class is templated over the types of the two input images and the type of the output image. Numeric conversions (castings) are done by the C++ defaults.
- ITK Sphinx Examples: