OTB  10.0.0
Orfeo Toolbox
otbSubPixelDisparityImageFilter.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2024 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() const 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:
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
Perform 2D block matching between two images.
Perform sub-pixel disparity estimation from input integer disparities and the image pair that was use...
itk::TranslationTransform< double, 2 > TransformationType
otb::PixelWiseBlockMatchingImageFilter< InputImageType, OutputMetricImageType, OutputDisparityImageType, InputMaskImageType, BlockMatchingFunctorType > BlockMatchingFilterType
SubPixelDisparityImageFilter(const Self &)=delete
itk::ResampleImageFilter< TInputImage, TInputImage, double > ResamplerFilterType
const BlockMatchingFunctorType & GetFunctor() const
itk::ImageToImageFilter< TInputImage, TDisparityImage > Superclass
itk::ConstNeighborhoodIterator< TInputImage > ConstNeighborhoodIteratorType
OutputDisparityImageType::PixelType DisparityPixelType
void operator=(const Self &)=delete
itk::SmartPointer< const Self > ConstPointer
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.