OTB  9.0.0
Orfeo Toolbox
otbSubPixelDisparityImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbSubPixelDisparityImageFilter_h
22 #define otbSubPixelDisparityImageFilter_h
23 
25 
26 #include "itkTranslationTransform.h"
27 #include "itkResampleImageFilter.h"
28 
29 namespace otb
30 {
31 
65 template <class TInputImage, class TOutputMetricImage, class TDisparityImage = TOutputMetricImage, class TMaskImage = otb::Image<unsigned char>,
66  class TBlockMatchingFunctor = Functor::SSDBlockMatching<TInputImage, TOutputMetricImage>>
67 class ITK_EXPORT SubPixelDisparityImageFilter : public itk::ImageToImageFilter<TInputImage, TDisparityImage>
68 {
69 public:
72  typedef itk::ImageToImageFilter<TInputImage, TDisparityImage> Superclass;
73  typedef itk::SmartPointer<Self> Pointer;
74  typedef itk::SmartPointer<const Self> ConstPointer;
75 
77  itkNewMacro(Self);
78 
80  itkTypeMacro(SubPixelDisparityImageFilter, ImageToImageFilter);
81 
83  typedef TInputImage InputImageType;
84  typedef TOutputMetricImage OutputMetricImageType;
85  typedef TDisparityImage OutputDisparityImageType;
86  typedef TMaskImage InputMaskImageType;
87  typedef TBlockMatchingFunctor BlockMatchingFunctorType;
88 
89  typedef typename InputImageType::SizeType SizeType;
90  typedef typename InputImageType::IndexType IndexType;
91  typedef typename InputImageType::RegionType RegionType;
92  typedef typename InputImageType::SpacingType SpacingType;
93  typedef typename InputImageType::PointType PointType;
94 
95  typedef typename TOutputMetricImage::ValueType MetricValueType;
96 
97  typedef typename OutputDisparityImageType::PixelType DisparityPixelType;
98 
99  typedef itk::ConstNeighborhoodIterator<TInputImage> ConstNeighborhoodIteratorType;
100 
101  typedef itk::ResampleImageFilter<TInputImage, TInputImage, double> ResamplerFilterType;
102  typedef itk::TranslationTransform<double, 2> TransformationType;
105 
106  itkStaticConstMacro(PARABOLIC, int, 0);
107  itkStaticConstMacro(TRIANGULAR, int, 1);
108  itkStaticConstMacro(DICHOTOMY, int, 2);
109 
111  void SetLeftInput(const TInputImage* image);
112 
114  void SetRightInput(const TInputImage* image);
115 
117  void SetHorizontalDisparityInput(const TDisparityImage* hfield);
118 
120  void SetVerticalDisparityInput(const TDisparityImage* vfield);
121 
123  void SetMetricInput(const TOutputMetricImage* image);
124 
126  const TDisparityImage* GetHorizontalDisparityInput() const;
127  const TDisparityImage* GetVerticalDisparityInput() const;
129 
131  void SetLeftMaskInput(const TMaskImage* image);
132 
134  void SetRightMaskInput(const TMaskImage* image);
135 
137  const TInputImage* GetLeftInput() const;
138  const TInputImage* GetRightInput() const;
139  const TMaskImage* GetLeftMaskInput() const;
140  const TMaskImage* GetRightMaskInput() const;
142 
144  const TOutputMetricImage* GetMetricOutput() const;
145  TOutputMetricImage* GetMetricOutput();
147 
149  const TDisparityImage* GetHorizontalDisparityOutput() const;
150  TDisparityImage* GetHorizontalDisparityOutput();
152 
154  const TDisparityImage* GetVerticalDisparityOutput() const;
155  TDisparityImage* GetVerticalDisparityOutput();
157 
159  void SetRadius(unsigned int radius)
160  {
161  m_Radius.Fill(radius);
162  }
163 
165  itkSetMacro(Radius, SizeType);
166  itkGetConstReferenceMacro(Radius, SizeType);
168 
170  itkSetMacro(MinimumHorizontalDisparity, int);
171  itkGetConstReferenceMacro(MinimumHorizontalDisparity, int);
173 
175  itkSetMacro(MaximumHorizontalDisparity, int);
176  itkGetConstReferenceMacro(MaximumHorizontalDisparity, int);
178 
180  itkSetMacro(MinimumVerticalDisparity, int);
181  itkGetConstReferenceMacro(MinimumVerticalDisparity, int);
183 
185  itkSetMacro(MaximumVerticalDisparity, int);
186  itkGetConstReferenceMacro(MaximumVerticalDisparity, int);
188 
189  itkSetMacro(Minimize, bool);
190  itkGetConstReferenceMacro(Minimize, bool);
191  itkBooleanMacro(Minimize);
192 
195  {
196  return m_Functor;
197  }
198 
201  {
202  return m_Functor;
203  }
204 
206  itkSetMacro(RefineMethod, int);
207  itkGetMacro(RefineMethod, int);
209 
210  void SetInputsFromBlockMatchingFilter(const BlockMatchingFilterType* filter);
211 
212 protected:
215 
217  ~SubPixelDisparityImageFilter() override;
218 
224  void VerifyInputInformation() override;
225 
227  void GenerateOutputInformation() override;
228 
230  void GenerateInputRequestedRegion() override;
231 
233  void BeforeThreadedGenerateData() override;
234 
236  void ThreadedGenerateData(const RegionType& outputRegionForThread, itk::ThreadIdType threadId) override;
237 
239  void AfterThreadedGenerateData() override;
240 
241 private:
242  SubPixelDisparityImageFilter(const Self&) = delete;
243  void operator=(const Self&) = delete;
244 
246  void ParabolicRefinement(const RegionType& outputRegionForThread, itk::ThreadIdType threadId);
247 
249  void TriangularRefinement(const RegionType& outputRegionForThread, itk::ThreadIdType threadId);
250 
252  void DichotomyRefinement(const RegionType& outputRegionForThread, itk::ThreadIdType threadId);
253 
256 
259 
262 
265 
268 
271 
274 
277 
279  std::vector<double> m_WrongExtrema;
280 
282  unsigned int m_Step;
283 
286 };
287 } // end namespace otb
288 
289 #ifndef OTB_MANUAL_INSTANTIATION
291 #endif
292 
293 #endif
otb::SubPixelDisparityImageFilter::Self
SubPixelDisparityImageFilter Self
Definition: otbSubPixelDisparityImageFilter.h:71
otb::SubPixelDisparityImageFilter::IndexType
InputImageType::IndexType IndexType
Definition: otbSubPixelDisparityImageFilter.h:90
otbSubPixelDisparityImageFilter.hxx
otb::SubPixelDisparityImageFilter::m_Minimize
bool m_Minimize
Definition: otbSubPixelDisparityImageFilter.h:270
otb::SubPixelDisparityImageFilter::SizeType
InputImageType::SizeType SizeType
Definition: otbSubPixelDisparityImageFilter.h:89
otb::SubPixelDisparityImageFilter::ResamplerFilterType
itk::ResampleImageFilter< TInputImage, TInputImage, double > ResamplerFilterType
Definition: otbSubPixelDisparityImageFilter.h:101
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::SubPixelDisparityImageFilter::ConstNeighborhoodIteratorType
itk::ConstNeighborhoodIterator< TInputImage > ConstNeighborhoodIteratorType
Definition: otbSubPixelDisparityImageFilter.h:99
otb::SubPixelDisparityImageFilter::m_WrongExtrema
std::vector< double > m_WrongExtrema
Definition: otbSubPixelDisparityImageFilter.h:279
otb::SubPixelDisparityImageFilter::BlockMatchingFilterType
otb::PixelWiseBlockMatchingImageFilter< InputImageType, OutputMetricImageType, OutputDisparityImageType, InputMaskImageType, BlockMatchingFunctorType > BlockMatchingFilterType
Definition: otbSubPixelDisparityImageFilter.h:104
otb::SubPixelDisparityImageFilter::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbSubPixelDisparityImageFilter.h:73
otb::SubPixelDisparityImageFilter::m_Step
unsigned int m_Step
Definition: otbSubPixelDisparityImageFilter.h:282
otb::SubPixelDisparityImageFilter::m_Functor
BlockMatchingFunctorType m_Functor
Definition: otbSubPixelDisparityImageFilter.h:273
otb::SubPixelDisparityImageFilter::DisparityPixelType
OutputDisparityImageType::PixelType DisparityPixelType
Definition: otbSubPixelDisparityImageFilter.h:97
otb::SubPixelDisparityImageFilter::InputMaskImageType
TMaskImage InputMaskImageType
Definition: otbSubPixelDisparityImageFilter.h:86
otb::SubPixelDisparityImageFilter::m_RefineMethod
int m_RefineMethod
Definition: otbSubPixelDisparityImageFilter.h:276
otb::SubPixelDisparityImageFilter::OutputDisparityImageType
TDisparityImage OutputDisparityImageType
Definition: otbSubPixelDisparityImageFilter.h:85
otbPixelWiseBlockMatchingImageFilter.h
otb::SubPixelDisparityImageFilter::m_MaximumHorizontalDisparity
int m_MaximumHorizontalDisparity
Definition: otbSubPixelDisparityImageFilter.h:261
otb::SubPixelDisparityImageFilter::BlockMatchingFunctorType
TBlockMatchingFunctor BlockMatchingFunctorType
Definition: otbSubPixelDisparityImageFilter.h:87
otb::SubPixelDisparityImageFilter::m_MinimumVerticalDisparity
int m_MinimumVerticalDisparity
Definition: otbSubPixelDisparityImageFilter.h:264
otb::SubPixelDisparityImageFilter::m_MinimumHorizontalDisparity
int m_MinimumHorizontalDisparity
Definition: otbSubPixelDisparityImageFilter.h:258
otb::PixelWiseBlockMatchingImageFilter
Perform 2D block matching between two images.
Definition: otbPixelWiseBlockMatchingImageFilter.h:298
otb::SubPixelDisparityImageFilter::InputImageType
TInputImage InputImageType
Definition: otbSubPixelDisparityImageFilter.h:80
otb::SubPixelDisparityImageFilter::GetFunctor
const BlockMatchingFunctorType & GetFunctor() const
Definition: otbSubPixelDisparityImageFilter.h:200
otb::SubPixelDisparityImageFilter::RegionType
InputImageType::RegionType RegionType
Definition: otbSubPixelDisparityImageFilter.h:91
otb::SubPixelDisparityImageFilter::m_MaximumVerticalDisparity
int m_MaximumVerticalDisparity
Definition: otbSubPixelDisparityImageFilter.h:267
otb::SubPixelDisparityImageFilter::GetFunctor
BlockMatchingFunctorType & GetFunctor()
Definition: otbSubPixelDisparityImageFilter.h:194
otb::SubPixelDisparityImageFilter::OutputMetricImageType
TOutputMetricImage OutputMetricImageType
Definition: otbSubPixelDisparityImageFilter.h:84
otb::SubPixelDisparityImageFilter::PointType
InputImageType::PointType PointType
Definition: otbSubPixelDisparityImageFilter.h:93
otb::SubPixelDisparityImageFilter::ConstPointer
itk::SmartPointer< const Self > ConstPointer
Definition: otbSubPixelDisparityImageFilter.h:74
otb::SubPixelDisparityImageFilter
Perform sub-pixel disparity estimation from input integer disparities and the image pair that was use...
Definition: otbSubPixelDisparityImageFilter.h:67
otb::SubPixelDisparityImageFilter::SetRadius
void SetRadius(unsigned int radius)
Definition: otbSubPixelDisparityImageFilter.h:159
otb::SubPixelDisparityImageFilter::SpacingType
InputImageType::SpacingType SpacingType
Definition: otbSubPixelDisparityImageFilter.h:92
otb::SubPixelDisparityImageFilter::TransformationType
itk::TranslationTransform< double, 2 > TransformationType
Definition: otbSubPixelDisparityImageFilter.h:102
otb::SubPixelDisparityImageFilter::m_GridIndex
IndexType m_GridIndex
Definition: otbSubPixelDisparityImageFilter.h:285
otb::SubPixelDisparityImageFilter::Superclass
itk::ImageToImageFilter< TInputImage, TDisparityImage > Superclass
Definition: otbSubPixelDisparityImageFilter.h:72
otb::SubPixelDisparityImageFilter::MetricValueType
TOutputMetricImage::ValueType MetricValueType
Definition: otbSubPixelDisparityImageFilter.h:95
otb::SubPixelDisparityImageFilter::m_Radius
SizeType m_Radius
Definition: otbSubPixelDisparityImageFilter.h:255