21 #ifndef otbMatrixImageFilter_hxx
22 #define otbMatrixImageFilter_hxx
26 #include "itkImageRegionIterator.h"
27 #include "itkProgressReporter.h"
35 template <
class TInputImage,
class TOutputImage,
class TMatrix>
38 this->DynamicMultiThreadingOn();
41 template <
class TInputImage,
class TOutputImage,
class TMatrix>
45 Superclass::GenerateOutputInformation();
49 if (this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.cols())
51 itkExceptionMacro(
"Invalid Matrix size. Number of columns must be the same as the image number of channels.");
54 if (m_Matrix.rows() == 0)
56 itkExceptionMacro(
"Invalid Matrix size. Number of rows can't be null.");
58 this->GetOutput()->SetNumberOfComponentsPerPixel(m_Matrix.rows());
61 if (!m_MatrixByVector)
63 if (this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.rows())
65 itkExceptionMacro(
"Invalid Matrix size. Number of rows must be the same as the image number of channels.");
68 if (m_Matrix.cols() == 0)
70 itkExceptionMacro(
"Invalid Matrix size. Number of columns can't be null.");
72 this->GetOutput()->SetNumberOfComponentsPerPixel(m_Matrix.cols());
76 template <
class TInputImage,
class TOutputImage,
class TMatrix>
80 typename OutputImageType::Pointer outputPtr = this->GetOutput();
81 typename InputImageType::ConstPointer inputPtr = this->GetInput();
83 typename itk::ImageRegionConstIterator<InputImageType> inIt(inputPtr, outputRegionForThread);
84 itk::ImageRegionIterator<OutputImageType> outIt(outputPtr, outputRegionForThread);
89 const unsigned int inSize = m_MatrixByVector ? m_Matrix.cols() : m_Matrix.rows();
90 const unsigned int outSize = m_MatrixByVector ? m_Matrix.rows() : m_Matrix.cols();
95 while (!outIt.IsAtEnd())
99 outPix.SetSize(outSize);
101 for (
unsigned int i = 0; i < inSize; ++i)
106 outVect = m_MatrixByVector ? m_Matrix * inVect : inVect * m_Matrix;
108 for (
unsigned int i = 0; i < outSize; ++i)
123 template <
class TInputImage,
class TOutputImage,
class TMatrix>
126 Superclass::PrintSelf(os, indent);
127 os << indent <<
"Matrix: " << m_Matrix << std::endl;
128 os << indent <<
"MatrixByVector: " << m_MatrixByVector << std::endl;
OutputImageType::PixelType OutputPixelType
vnl_vector< InputRealType > VectorType
InputImageType::PixelType InputPixelType
void GenerateOutputInformation() override
OutputImageType::InternalPixelType OutputInternalPixelType
void DynamicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread) override
void PrintSelf(std::ostream &os, itk::Indent indent) const override
OutputImageType::RegionType OutputImageRegionType
itk::NumericTraits< InputInternalPixelType >::RealType InputRealType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.