21 #ifndef otbPixelWiseBlockMatchingImageFilter_h
22 #define otbPixelWiseBlockMatchingImageFilter_h
25 #include "itkImageToImageFilter.h"
26 #include "itkConstNeighborhoodIterator.h"
27 #include "itkImageRegionIterator.h"
46 template <
class TInputImage,
class TOutputMetricImage>
59 for (
unsigned int i = 0; i < a.Size(); ++i)
61 ssd += (a.GetPixel(i) - b.GetPixel(i)) * (a.GetPixel(i) - b.GetPixel(i));
80 template <
class TInputImage,
class TOutputMetricImage>
94 for (
unsigned int i = 0; i < a.Size(); ++i)
96 meana += a.GetPixel(i);
97 meanb += b.GetPixel(i);
103 for (
unsigned int i = 0; i < a.Size(); ++i)
105 ssd += (a.GetPixel(i) / meana - b.GetPixel(i) / meanb) * (a.GetPixel(i) / meana - b.GetPixel(i) / meanb);
124 template <
class TInputImage,
class TOutputMetricImage>
143 double size = a.Size();
145 for (
unsigned int i = 0; i < size; ++i)
147 meanA +=
static_cast<double>(a.GetPixel(i));
148 meanB +=
static_cast<double>(b.GetPixel(i));
155 for (
unsigned int i = 0; i < size; ++i)
157 valueA =
static_cast<double>(a.GetPixel(i));
158 valueB =
static_cast<double>(b.GetPixel(i));
159 cov += (valueA - meanA) * (valueB - meanB);
160 sigmaA += (valueA - meanA) * (valueA - meanA);
161 sigmaB += (valueB - meanB) * (valueB - meanB);
167 sigmaA = std::sqrt(sigmaA);
168 sigmaB = std::sqrt(sigmaB);
170 if (sigmaA > 1e-20 && sigmaB > 1e-20)
172 ncc = std::abs(cov) / (sigmaA * sigmaB);
194 template <
class TInputImage,
class TOutputMetricImage>
223 for (
unsigned int i = 0; i < a.Size(); ++i)
225 score += std::pow(std::abs(
static_cast<double>(a.GetPixel(i) - b.GetPixel(i))),
m_P);
296 template <
class TInputImage,
class TOutputMetricImage,
class TOutputDisparityImage = TOutputMetricImage,
class TMaskImage = otb::Image<
unsigned char>,
297 class TBlockMatchingFunctor = Functor::SSDBlockMatching<TInputImage, TOutputMetricImage>>
303 typedef itk::ImageToImageFilter<TInputImage, TOutputDisparityImage>
Superclass;
320 typedef typename InputImageType::SizeType
SizeType;
333 void SetLeftInput(
const TInputImage* image);
336 void SetRightInput(
const TInputImage* image);
339 void SetLeftMaskInput(
const TMaskImage* image);
342 void SetRightMaskInput(
const TMaskImage* image);
345 const TInputImage* GetLeftInput()
const;
346 const TInputImage* GetRightInput()
const;
347 const TMaskImage* GetLeftMaskInput()
const;
348 const TMaskImage* GetRightMaskInput()
const;
352 const TOutputMetricImage* GetMetricOutput()
const;
353 TOutputMetricImage* GetMetricOutput();
357 const TOutputDisparityImage* GetHorizontalDisparityOutput()
const;
358 TOutputDisparityImage* GetHorizontalDisparityOutput();
362 const TOutputDisparityImage* GetVerticalDisparityOutput()
const;
363 TOutputDisparityImage* GetVerticalDisparityOutput();
370 m_Radius.Fill(radius);
374 itkSetMacro(Radius, SizeType);
375 itkGetConstReferenceMacro(Radius, SizeType);
379 itkSetMacro(MinimumHorizontalDisparity,
int);
380 itkGetConstReferenceMacro(MinimumHorizontalDisparity,
int);
384 itkSetMacro(MaximumHorizontalDisparity,
int);
385 itkGetConstReferenceMacro(MaximumHorizontalDisparity,
int);
389 itkSetMacro(MinimumVerticalDisparity,
int);
390 itkGetConstReferenceMacro(MinimumVerticalDisparity,
int);
394 itkSetMacro(MaximumVerticalDisparity,
int);
395 itkGetConstReferenceMacro(MaximumVerticalDisparity,
int);
398 itkSetMacro(Minimize,
bool);
399 itkGetConstReferenceMacro(Minimize,
bool);
400 itkBooleanMacro(Minimize);
403 itkSetMacro(ExplorationRadius, SizeType);
404 itkGetConstReferenceMacro(ExplorationRadius, SizeType);
408 itkSetMacro(InitHorizontalDisparity,
int);
409 itkGetConstReferenceMacro(InitHorizontalDisparity,
int);
413 itkSetMacro(InitVerticalDisparity,
int);
414 itkGetConstReferenceMacro(InitVerticalDisparity,
int);
430 void SetHorizontalDisparityInput(
const TOutputDisparityImage* hfield);
433 void SetVerticalDisparityInput(
const TOutputDisparityImage* vfield);
436 const TOutputDisparityImage* GetHorizontalDisparityInput()
const;
437 const TOutputDisparityImage* GetVerticalDisparityInput()
const;
441 itkSetMacro(Step,
unsigned int);
442 itkGetMacro(Step,
unsigned int);
446 itkSetMacro(GridIndex, IndexType);
447 itkGetConstReferenceMacro(GridIndex, IndexType);
451 static RegionType ConvertFullToSubsampledRegion(RegionType full,
unsigned int step, IndexType index);
454 static RegionType ConvertSubsampledToFullRegion(RegionType sub,
unsigned int step, IndexType index);
464 void GenerateOutputInformation()
override;
467 void GenerateInputRequestedRegion()
override;
470 void BeforeThreadedGenerateData()
override;
473 void ThreadedGenerateData(
const RegionType& outputRegionForThread, itk::ThreadIdType threadId)
override;
477 void operator =(
const Self&);
521 #ifndef OTB_MANUAL_INSTANTIATION