21 #ifndef otbMatrixImageFilter_hxx
22 #define otbMatrixImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
34 template <
class TInputImage,
class TOutputImage,
class TMatrix>
39 template <
class TInputImage,
class TOutputImage,
class TMatrix>
43 Superclass::GenerateOutputInformation();
47 if (this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.cols())
49 itkExceptionMacro(
"Invalid Matrix size. Number of columns must be the same as the image number of channels.");
52 if (m_Matrix.rows() == 0)
54 itkExceptionMacro(
"Invalid Matrix size. Number of rows can't be null.");
56 this->GetOutput()->SetNumberOfComponentsPerPixel(m_Matrix.rows());
59 if (!m_MatrixByVector)
61 if (this->GetInput()->GetNumberOfComponentsPerPixel() != m_Matrix.rows())
63 itkExceptionMacro(
"Invalid Matrix size. Number of rows must be the same as the image number of channels.");
66 if (m_Matrix.cols() == 0)
68 itkExceptionMacro(
"Invalid Matrix size. Number of columns can't be null.");
70 this->GetOutput()->SetNumberOfComponentsPerPixel(m_Matrix.cols());
74 template <
class TInputImage,
class TOutputImage,
class TMatrix>
78 typename OutputImageType::Pointer outputPtr = this->GetOutput();
79 typename InputImageType::ConstPointer inputPtr = this->GetInput();
81 typename itk::ImageRegionConstIterator<InputImageType> inIt(inputPtr, outputRegionForThread);
82 itk::ImageRegionIterator<OutputImageType> outIt(outputPtr, outputRegionForThread);
86 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
91 const unsigned int inSize = m_MatrixByVector ? m_Matrix.cols() : m_Matrix.rows();
92 const unsigned int outSize = m_MatrixByVector ? m_Matrix.rows() : m_Matrix.cols();
97 while (!outIt.IsAtEnd())
101 outPix.SetSize(outSize);
103 for (
unsigned int i = 0; i < inSize; ++i)
108 outVect = m_MatrixByVector ? m_Matrix * inVect : inVect * m_Matrix;
110 for (
unsigned int i = 0; i < outSize; ++i)
118 progress.CompletedPixel();
126 template <
class TInputImage,
class TOutputImage,
class TMatrix>
129 Superclass::PrintSelf(os, indent);
130 os << indent <<
"Matrix: " << m_Matrix << std::endl;
131 os << indent <<
"MatrixByVector: " << m_MatrixByVector << std::endl;