Optimized Belief Propagation (CPU and GPU)
DisparityMap.h
Go to the documentation of this file.
1 /*
2 Copyright (C) 2024 Scott Grauer-Gray
3 
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
8 
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13 
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18 
28 #ifndef DISPARITYMAP_H_
29 #define DISPARITYMAP_H_
30 
31 #include <algorithm>
32 #include <string>
33 #include <ranges>
34 #include "BpImage.h"
36 
43 template<class T>
44 requires std::is_arithmetic_v<T>
45 class DisparityMap : public BpImage<T> {
46 public:
47  DisparityMap() : BpImage<T>() {}
48 
49  explicit DisparityMap(
50  const std::array<unsigned int, 2>& width_height) :
51  BpImage<T>(width_height) {}
52 
53  explicit DisparityMap(
54  const std::array<unsigned int, 2>& width_height,
55  const T* input_disparity_map_vals,
56  unsigned int disparity_map_vals_scale = 1) :
57  BpImage<T>(width_height, input_disparity_map_vals)
58  {
59  std::ranges::copy(input_disparity_map_vals,
60  input_disparity_map_vals + this->TotalPixels(),
61  this->pixels_.get());
62 
63  if (disparity_map_vals_scale > 1u) {
64  RemoveScaleFromDisparity_vals(disparity_map_vals_scale);
65  }
66  }
67 
68  explicit DisparityMap(
69  const std::string& file_path_disparity_map,
70  unsigned int disparity_map_vals_scale = 1) :
71  BpImage<T>(file_path_disparity_map)
72  {
73  if (disparity_map_vals_scale > 1) {
74  RemoveScaleFromDisparity_vals(disparity_map_vals_scale);
75  }
76  }
77 
79  const DisparityMap& disparity_map_to_compare,
80  const beliefprop::DisparityMapEvaluationParams& evaluation_parameters) const;
81 
82  void SaveDisparityMap(
83  const std::string& disparity_map_file_path,
84  unsigned int scale_factor = 1) const;
85 
86 private:
87  void RemoveScaleFromDisparity_vals(unsigned int disparity_map_vals_scale)
88  {
89  if (disparity_map_vals_scale > 1) {
90  //divide each disparity value by disparity_map_vals_scale
91  std::ranges::transform(
92  this->pixels_.get(),
93  this->pixels_.get() + this->TotalPixels(),
94  this->pixels_.get(),
95  [disparity_map_vals_scale](const auto& disp_val) {
96  return (disp_val / disparity_map_vals_scale); });
97  }
98  }
99 };
100 
101 #endif /* DISPARITYMAP_H_ */
Declares class to define images that are used in bp processing.
Declares class to store disparity map evaluation results.
Class to define images that are used in bp processing.
Definition: BpImage.h:56
std::unique_ptr< T[]> pixels_
Definition: BpImage.h:118
unsigned int TotalPixels() const
Definition: BpImage.h:130
Class to store disparity map evaluation results. Specifically comparison between two disparity maps s...
Child class of BpImage to define disparity map image that is output from bp processing.
Definition: DisparityMap.h:45
DisparityMap(const std::array< unsigned int, 2 > &width_height, const T *input_disparity_map_vals, unsigned int disparity_map_vals_scale=1)
Definition: DisparityMap.h:53
DisparityMapEvaluation OutputComparison(const DisparityMap &disparity_map_to_compare, const beliefprop::DisparityMapEvaluationParams &evaluation_parameters) const
DisparityMap(const std::array< unsigned int, 2 > &width_height)
Definition: DisparityMap.h:49
DisparityMap(const std::string &file_path_disparity_map, unsigned int disparity_map_vals_scale=1)
Definition: DisparityMap.h:68
void SaveDisparityMap(const std::string &disparity_map_file_path, unsigned int scale_factor=1) const
Struct to store parameters for evaluation of disparity map from stereo processing.