Multiple Inputs of Different Type#

Synopsis#

Write a filter with multiple inputs of different types.

Results#

Warning

Fix Errors Example contains errors needed to be fixed for proper output.

Code#

C++#

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkCovariantVector.h"

#include "ImageFilterMultipleInputsDifferentType.h"

int
main()
{
  // Setup types
  using VectorImageType = itk::Image<itk::CovariantVector<unsigned char, 3>, 2>;
  using ScalarImageType = itk::Image<unsigned char, 2>;
  using FilterType = itk::ImageFilterMultipleInputsDifferentType<VectorImageType, ScalarImageType>;

  const auto input = itk::ReadImage<VectorImageType>("Test.jpg");

  // Create and the filter
  auto filter = FilterType::New();
  filter->SetInput(reader->GetOutput());
  filter->Update();

  itk::WriteImage(filter->GetOutput(), "TestOutput.jpg");

  return EXIT_SUCCESS;
}

Classes demonstrated#

template<typename TInputImage, typename TOutputImage>
class ImageToImageFilter : public itk::ImageSource<TOutputImage>, private itk::ImageToImageFilterCommon

Base class for filters that take an image as input and produce an image as output.

ImageToImageFilter is the base class for all process objects that output image data and require image data as input. Specifically, this class defines the SetInput() method for defining the input to a filter.

This class provides the infrastructure for supporting multithreaded processing of images. If a filter provides an implementation of GenerateData(), the image processing will run in a single thread and the implementation is responsible for allocating its output data. If a filter provides an implementation of ThreadedGenerateData() instead, the image will be divided into a number of work units, a number of threads will be spawned, and ThreadedGenerateData() will be called in each thread. Here, the output memory will be allocated by this superclass prior to calling ThreadedGenerateData().

ImageToImageFilter provides an implementation of GenerateInputRequestedRegion(). The base assumption to this point in the hierarchy is that a process object would ask for the largest possible region on input in order to produce any output. Imaging filters, however, can usually answer this question more precisely. The default implementation of GenerateInputRequestedRegion() in this class is to request an input that matches the size of the requested output. If a filter requires more input (say a filter that uses neighborhood information) or less input (for instance a magnify filter), then these filters will have to provide another implementation of this method. By convention, such implementations should call the Superclass’ method first.

All inputs to ImageToImageFilter (if there is more than one) are checked in the VerifyInputInformation method to verify that they occupy the same physical space. If the input images are in the same physical space, then the location of each voxel is identical, and the filter can operate voxel-by-voxel in index space. Some filters registration filters, for example will violate this precondition, in which case they should redefine VerifyInputInformation to relax or eliminate this requirement.

Access methods Set/GetCoordinateTolerance and Set/GetDirectionTolerance are provided for cases where the default spatial-congruency tolerances are too fine, and images that are almost in the same space should be regard as being in the same space. This has come up, for example when comparing different on-disk image formats with differing digits of precision in the position, spacing, and orientation.

The default tolerance is govern by the GlobalDefaultCoordinateTolerance and the GlobalDefaultDirectionTolerance properties, defaulting to 1.0e-6. The default tolerance for spatial comparison is then scaled by the voxelSpacing for coordinates (i.e. the coordinates must be the same to within one part per million). For the direction cosines the values must be within the current absolute tolerance.

ITK Sphinx Examples:

Subclassed by itk::AttributeMorphologyBaseImageFilter< TInputImage, TOutputImage, TAttribute, std::greater< TInputImage::PixelType > >, itk::AttributeMorphologyBaseImageFilter< TInputImage, TOutputImage, TAttribute, std::less< TInputImage::PixelType > >, itk::ConvolutionImageFilterBase< TInputImage, TKernelSource::OutputImageType, TOutputImage >, itk::AccumulateImageFilter< TInputImage, TOutputImage >, itk::ApproximateSignedDistanceMapImageFilter< TInputImage, TOutputImage >, itk::AttributeMorphologyBaseImageFilter< TInputImage, TOutputImage, TAttribute, TFunction >, itk::BilateralImageFilter< TInputImage, TOutputImage >, itk::BinaryImageToLabelMapFilter< TInputImage, TOutputImage >, itk::BinaryImageToShapeLabelMapFilter< TInputImage, TOutputImage >, itk::BinaryImageToStatisticsLabelMapFilter< TInputImage, TFeatureImage, TOutputImage >, itk::BinaryMedianImageFilter< TInputImage, TOutputImage >, itk::BinaryPruningImageFilter< TInputImage, TOutputImage >, itk::BinaryThinningImageFilter< TInputImage, TOutputImage >, itk::BinomialBlurImageFilter< TInputImage, TOutputImage >, itk::BinShrinkImageFilter< TInputImage, TOutputImage >, itk::BoxImageFilter< TInputImage, TOutputImage >, itk::BSplineControlPointImageFilter< TInputImage, TOutputImage >, itk::BSplineDecompositionImageFilter< TInputImage, TOutputImage >, itk::BSplineResampleImageFilterBase< TInputImage, TOutputImage >, itk::CannyEdgeDetectionImageFilter< TInputImage, TOutputImage >, itk::ClosingByReconstructionImageFilter< TInputImage, TOutputImage, TKernel >, itk::CollidingFrontsImageFilter< TInputImage, TOutputImage >, itk::ComposeDisplacementFieldsImageFilter< TInputImage, TOutputImage >, itk::ComposeImageFilter< TInputImage, TOutputImage >, itk::ConfidenceConnectedImageFilter< TInputImage, TOutputImage >, itk::ConnectedComponentImageFilter< TInputImage, TOutputImage, TMaskImage >, itk::ConnectedThresholdImageFilter< TInputImage, TOutputImage >, itk::ConvolutionImageFilterBase< TInputImage, TKernelImage, TOutputImage >, itk::CyclicShiftImageFilter< TInputImage, TOutputImage >, itk::DanielssonDistanceMapImageFilter< TInputImage, TOutputImage, TVoronoiImage >, itk::DerivativeImageFilter< TInputImage, TOutputImage >, itk::DirectFourierReconstructionImageToImageFilter< TInputImage, TOutputImage >, itk::DiscreteGaussianDerivativeImageFilter< TInputImage, TOutputImage >, itk::DiscreteGaussianImageFilter< TInputImage, TOutputImage >, itk::DisplacementFieldJacobianDeterminantFilter< TInputImage, TRealType, TOutputImage >, itk::DisplacementFieldToBSplineImageFilter< TInputImage, TInputPointSet, TOutputImage >, itk::DoubleThresholdImageFilter< TInputImage, TOutputImage >, itk::ExpandImageFilter< TInputImage, TOutputImage >, itk::ExponentialDisplacementFieldImageFilter< TInputImage, TOutputImage >, itk::FastChamferDistanceImageFilter< TInputImage, TOutputImage >, itk::ForwardFFTImageFilter< TInputImage, TOutputImage >, itk::GradientMagnitudeImageFilter< TInputImage, TOutputImage >, itk::GradientRecursiveGaussianImageFilter< TInputImage, TOutputImage >, itk::GradientVectorFlowImageFilter< TInputImage, TOutputImage, TInternalPixel >, itk::GrayscaleConnectedClosingImageFilter< TInputImage, TOutputImage >, itk::GrayscaleConnectedOpeningImageFilter< TInputImage, TOutputImage >, itk::GrayscaleFillholeImageFilter< TInputImage, TOutputImage >, itk::GrayscaleGeodesicDilateImageFilter< TInputImage, TOutputImage >, itk::GrayscaleGeodesicErodeImageFilter< TInputImage, TOutputImage >, itk::GrayscaleGrindPeakImageFilter< TInputImage, TOutputImage >, itk::HalfHermitianToRealInverseFFTImageFilter< TInputImage, TOutputImage >, itk::HardConnectedComponentImageFilter< TInputImage, TOutputImage >, itk::HConcaveImageFilter< TInputImage, TOutputImage >, itk::HConvexImageFilter< TInputImage, TOutputImage >, itk::HessianRecursiveGaussianImageFilter< TInputImage, TOutputImage >, itk::HessianToObjectnessMeasureImageFilter< TInputImage, TOutputImage >, itk::HistogramMatchingImageFilter< TInputImage, TOutputImage, THistogramMeasurement >, itk::HistogramThresholdImageFilter< TInputImage, TOutputImage, TMaskImage >, itk::HMaximaImageFilter< TInputImage, TOutputImage >, itk::HMinimaImageFilter< TInputImage, TOutputImage >, itk::ImageAndPathToImageFilter< TInputImage, TInputPath, TOutputImage >, itk::ImageShapeModelEstimatorBase< TInputImage, TOutputImage >, itk::InPlaceImageFilter< TInputImage, TOutputImage >, itk::InterpolateImageFilter< TInputImage, TOutputImage >, itk::InterpolateImagePointsFilter< TInputImage, TOutputImage, TCoordType, InterpolatorType >, itk::InverseDisplacementFieldImageFilter< TInputImage, TOutputImage >, itk::InverseFFTImageFilter< TInputImage, TOutputImage >, itk::InvertDisplacementFieldImageFilter< TInputImage, TOutputImage >, itk::IsoContourDistanceImageFilter< TInputImage, TOutputImage >, itk::IsolatedConnectedImageFilter< TInputImage, TOutputImage >, itk::IsolatedWatershedImageFilter< TInputImage, TOutputImage >, itk::IterativeInverseDisplacementFieldImageFilter< TInputImage, TOutputImage >, itk::JoinSeriesImageFilter< TInputImage, TOutputImage >, itk::KappaSigmaThresholdImageFilter< TInputImage, TMaskImage, TOutputImage >, itk::LabelImageToLabelMapFilter< TInputImage, TOutputImage >, itk::LabelImageToShapeLabelMapFilter< TInputImage, TOutputImage >, itk::LabelImageToStatisticsLabelMapFilter< TInputImage, TFeatureImage, TOutputImage >, itk::LabelMapFilter< TInputImage, TOutputImage >, itk::LabelMapToAttributeImageFilter< TInputImage, TOutputImage, TAttributeAccessor >, itk::LabelVotingImageFilter< TInputImage, TOutputImage >, itk::LaplacianImageFilter< TInputImage, TOutputImage >, itk::LaplacianRecursiveGaussianImageFilter< TInputImage, TOutputImage >, itk::LaplacianSharpeningImageFilter< TInputImage, TOutputImage >, itk::LevelSetDomainMapImageFilter< TInputImage, TOutputImage >, itk::MaskedFFTNormalizedCorrelationImageFilter< TInputImage, TOutputImage, TMaskImage >, itk::MorphologicalWatershedImageFilter< TInputImage, TOutputImage >, itk::MRIBiasFieldCorrectionFilter< TInputImage, TOutputImage, TMaskImage >, itk::MultiLabelSTAPLEImageFilter< TInputImage, TOutputImage, TWeights >, itk::MultiResolutionPyramidImageFilter< TInputImage, TOutputImage >, itk::MultiScaleHessianBasedMeasureImageFilter< TInputImage, THessianImage, TOutputImage >, itk::N4BiasFieldCorrectionImageFilter< TInputImage, TMaskImage, TOutputImage >, itk::NeighborhoodConnectedImageFilter< TInputImage, TOutputImage >, itk::NeighborhoodOperatorImageFilter< TInputImage, TOutputImage, TOperatorValueType >, itk::NormalizeImageFilter< TInputImage, TOutputImage >, itk::NormalizeToConstantImageFilter< TInputImage, TOutputImage >, itk::ObjectMorphologyImageFilter< TInputImage, TOutputImage, TKernel >, itk::OpeningByReconstructionImageFilter< TInputImage, TOutputImage, TKernel >, itk::OrientImageFilter< TInputImage, TOutputImage >, itk::OtsuMultipleThresholdsImageFilter< TInputImage, TOutputImage >, itk::PadImageFilterBase< TInputImage, TOutputImage >, itk::PatchBasedDenoisingBaseImageFilter< TInputImage, TOutputImage >, itk::PolylineMask2DImageFilter< TInputImage, TPolyline, TOutputImage >, itk::PolylineMaskImageFilter< TInputImage, TPolyline, TVector, TOutputImage >, itk::ProjectionImageFilter< TInputImage, TOutputImage, TAccumulator >, itk::RealToHalfHermitianForwardFFTImageFilter< TInputImage, TOutputImage >, itk::ReconstructionImageFilter< TInputImage, TOutputImage, TCompare >, itk::RegionalMaximaImageFilter< TInputImage, TOutputImage >, itk::RegionalMinimaImageFilter< TInputImage, TOutputImage >, itk::RegionGrowImageFilter< TInputImage, TOutputImage >, itk::RegionOfInterestImageFilter< TInputImage, TOutputImage >, itk::ResampleImageFilter< TInputImage, TOutputImage, TInterpolatorPrecisionType, TTransformPrecisionType >, itk::RobustAutomaticThresholdImageFilter< TInputImage, TGradientImage, TOutputImage >, itk::ScalarImageKmeansImageFilter< TInputImage, TOutputImage >, itk::ScalarToRGBColormapImageFilter< TInputImage, TOutputImage >, itk::ShiftScaleImageFilter< TInputImage, TOutputImage >, itk::ShrinkImageFilter< TInputImage, TOutputImage >, itk::SignedDanielssonDistanceMapImageFilter< TInputImage, TOutputImage, TVoronoiImage >, itk::SignedMaurerDistanceMapImageFilter< TInputImage, TOutputImage >, itk::SliceBySliceImageFilter< TInputImage, TOutputImage, TInputFilter, TOutputFilter, TInternalInputImage, TInternalOutputImage >, itk::SliceImageFilter< TInputImage, TOutputImage >, itk::SLICImageFilter< TInputImage, TOutputImage, TDistancePixel >, itk::SobelEdgeDetectionImageFilter< TInputImage, TOutputImage >, itk::SpatialFunctionImageEvaluatorFilter< TSpatialFunction, TInputImage, TOutputImage >, itk::STAPLEImageFilter< TInputImage, TOutputImage >, itk::Statistics::ImageClassifierFilter< TSample, TInputImage, TOutputImage >, itk::StochasticFractalDimensionImageFilter< TInputImage, TMaskImage, TOutputImage >, itk::StreamingImageFilter< TInputImage, TOutputImage >, itk::Testing::ComparisonImageFilter< TInputImage, TOutputImage >, itk::ThresholdMaximumConnectedComponentsImageFilter< TInputImage, TOutputImage >, itk::TileImageFilter< TInputImage, TOutputImage >, itk::TobogganImageFilter< TInputImage, TOutputImage >, itk::UnsharpMaskImageFilter< TInputImage, TOutputImage, TInternalPrecision >, itk::ValuedRegionalExtremaImageFilter< TInputImage, TOutputImage, TFunction1, TFunction2 >, itk::VectorConfidenceConnectedImageFilter< TInputImage, TOutputImage >, itk::VectorGradientMagnitudeImageFilter< TInputImage, TRealType, TOutputImage >, itk::VectorNeighborhoodOperatorImageFilter< TInputImage, TOutputImage >, itk::VoronoiSegmentationImageFilterBase< TInputImage, TOutputImage, TBinaryPriorImage >, itk::VotingBinaryImageFilter< TInputImage, TOutputImage >, itk::WarpImageFilter< TInputImage, TOutputImage, TDisplacementField >, itk::WarpVectorImageFilter< TInputImage, TOutputImage, TDisplacementField >, itk::ZeroCrossingBasedEdgeDetectionImageFilter< TInputImage, TOutputImage >, itk::ZeroCrossingImageFilter< TInputImage, TOutputImage >, itk::MaskedFFTNormalizedCorrelationImageFilter< TInputImage, TOutputImage >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Function::BinaryThresholdAccumulator< TInputImage::PixelType, TOutputImage::PixelType > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::BinaryAccumulator< TInputImage::PixelType, TOutputImage::PixelType > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::MaximumAccumulator< TInputImage::PixelType > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::MeanAccumulator< TInputImage::PixelType, TAccumulate > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::MedianAccumulator< TInputImage::PixelType > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::MinimumAccumulator< TInputImage::PixelType > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::StandardDeviationAccumulator< TInputImage::PixelType, TAccumulate > >, itk::ProjectionImageFilter< TInputImage, TOutputImage, Functor::SumAccumulator< TInputImage::PixelType, TOutputImage::PixelType > >, itk::ReconstructionImageFilter< TInputImage, TOutputImage, std::greater< TOutputImage::PixelType > >, itk::ReconstructionImageFilter< TInputImage, TOutputImage, std::less< TOutputImage::PixelType > >, itk::ValuedRegionalExtremaImageFilter< TInputImage, TOutputImage, std::greater< TInputImage::PixelType >, std::greater< TOutputImage::PixelType > >, itk::ValuedRegionalExtremaImageFilter< TInputImage, TOutputImage, std::less< TInputImage::PixelType >, std::less< TOutputImage::PixelType > >, itk::VoronoiSegmentationImageFilterBase< TInputImage, TOutputImage >

See itk::ImageToImageFilter for additional documentation.