21 #ifndef otbSpectralAngleDistanceImageFilter_hxx
22 #define otbSpectralAngleDistanceImageFilter_hxx
25 #include "itkImageRegionIterator.h"
26 #include "itkProgressReporter.h"
35 template <
class TInputImage,
class TOutputImage>
41 template <
class TInputImage,
class TOutputImage>
44 if (this->GetInput()->GetNumberOfComponentsPerPixel() == 1)
46 itkExceptionMacro(<<
"Not valid input image : mono channel image gives a nul output image.");
50 template <
class TInputImage,
class TOutputImage>
52 itk::ThreadIdType threadId)
55 if (m_ReferencePixel.Size() == 0)
57 itkExceptionMacro(<<
"Reference pixel is not set!");
60 InputImageConstPointerType inputPtr = this->GetInput();
61 OutputImagePointerType outputPtr = this->GetOutput();
65 if (m_ReferencePixel.GetSize() != inputPtr->GetNumberOfComponentsPerPixel())
67 itkExceptionMacro(<<
"Reference pixel size (" << m_ReferencePixel.GetSize() <<
" and input image pixel size (" << inputPtr->GetNumberOfComponentsPerPixel()
74 InputImageRegionType inputRegionForThread;
75 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
78 itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, inputRegionForThread);
79 itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
80 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
85 while (!inputIt.IsAtEnd() && !outputIt.IsAtEnd())
88 double scalarProd = 0.0;
89 double normProd = 0.0;
90 double normProd1 = 0.0;
91 double normProd2 = 0.0;
92 InputPixelType pixel = inputIt.Get();
93 for (
unsigned int i = 0; i < pixel.Size(); ++i)
95 scalarProd += pixel[i] * m_ReferencePixel[i];
96 normProd1 += pixel[i] * pixel[i];
97 normProd2 += m_ReferencePixel[i] * m_ReferencePixel[i];
99 normProd = normProd1 * normProd2;
107 dist = std::acos(scalarProd / std::sqrt(normProd));
114 outputIt.Set(
static_cast<OutputPixelType
>(dist));
117 progress.CompletedPixel();