Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
hole-filling-filter.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2018 Intel Corporation. All Rights Reserved
3 // Enhancing the input video frame by filling missing data.
4 #pragma once
5 
6 namespace librealsense
7 {
8  enum holes_filling_types : uint8_t
9  {
14  };
15 
17  {
18  public:
20 
21  protected:
22  void update_configuration(const rs2::frame& f);
23 
25 
26  template<typename T>
27  void apply_hole_filling(void * image_data)
28  {
30  T* data = reinterpret_cast<T*>(image_data);
31 
32  // Select and apply the appropriate hole filling method
33  switch (_hole_filling_mode)
34  {
35  case hf_fill_from_left:
36  holes_fill_left(data, _width, _height, _stride);
37  break;
39  holes_fill_farest(data, _width, _height, _stride);
40  break;
42  holes_fill_nearest(data, _width, _height, _stride);
43  break;
44  default:
46  << "Unsupported hole filling mode: " << _hole_filling_mode << " is out of range.");
47  }
48  }
49 
50  // Implementations of the hole-filling methods
51  template<typename T>
52  inline void holes_fill_left(T* image_data, size_t width, size_t height, size_t stride)
53  {
54  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
55  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
56  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
57 
58  T* p = image_data;
59 
60  for (int j = 0; j < height; ++j)
61  {
62  ++p;
63  for (int i = 1; i < width; ++i)
64  {
65  if (empty(p))
66  *p = *(p - 1);
67  ++p;
68  }
69  }
70  }
71 
72  template<typename T>
73  inline void holes_fill_farest(T* image_data, size_t width, size_t height, size_t stride)
74  {
75  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
76  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
77  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
78 
79  T tmp = 0;
80  T * p = image_data + width;
81  T * q = nullptr;
82  for (int j = 1; j < height - 1; ++j)
83  {
84  ++p;
85  for (int i = 1; i < width; ++i)
86  {
87  if (empty(p))
88  {
89  tmp = *(p - width);
90 
91  q = p - width - 1;
92  if (*q > tmp)
93  tmp = *q;
94 
95  q = p - 1;
96  if (*q > tmp)
97  tmp = *q;
98 
99  q = p + width - 1;
100  if (*q > tmp)
101  tmp = *q;
102 
103  q = p + width;
104  if (*q > tmp)
105  tmp = *q;
106 
107  *p = tmp;
108  }
109 
110  p++;
111  }
112  }
113  }
114 
115  template<typename T>
116  inline void holes_fill_nearest(T* image_data, size_t width, size_t height, size_t stride)
117  {
118  std::function<bool(T*)> fp_oper = [](T* ptr) { return !*((int *)ptr); };
119  std::function<bool(T*)> uint_oper = [](T* ptr) { return !(*ptr); };
120  auto empty = (std::is_floating_point<T>::value) ? fp_oper : uint_oper;
121 
122  T tmp = 0;
123  T * p = image_data + width;
124  T * q = nullptr;
125  for (int j = 1; j < height - 1; ++j)
126  {
127  ++p;
128  for (int i = 1; i < width; ++i)
129  {
130  if (empty(p))
131  {
132  tmp = *(p - width);
133 
134  q = p - width - 1;
135  if (!empty(q) && (*q < tmp))
136  tmp = *q;
137 
138  q = p - 1;
139  if (!empty(q) && (*q < tmp))
140  tmp = *q;
141 
142  q = p + width - 1;
143  if (!empty(q) && (*q < tmp))
144  tmp = *q;
145 
146  q = p + width;
147  if (!empty(q) && (*q < tmp))
148  tmp = *q;
149 
150  *p = tmp;
151  }
152 
153  p++;
154  }
155  }
156  }
157 
158  private:
159 
160  size_t _width, _height, _stride;
161  size_t _bpp;
162  rs2_extension _extension_type; // Strictly Depth/Disparity
163  size_t _current_frm_size_pixels;
164  rs2::stream_profile _source_stream_profile;
165  rs2::stream_profile _target_stream_profile;
166  uint8_t _hole_filling_mode;
167  };
168 }
Definition: hole-filling-filter.h:16
Definition: rs_frame.hpp:21
Definition: rs_frame.hpp:202
Definition: backend.h:380
Definition: synthetic-stream.h:41
Definition: hole-filling-filter.h:12
void update_configuration(const rs2::frame &f)
void holes_fill_nearest(T *image_data, size_t width, size_t height, size_t stride)
Definition: hole-filling-filter.h:116
Definition: algo.h:16
Definition: rs_processing.hpp:13
Definition: hole-filling-filter.h:11
void holes_fill_farest(T *image_data, size_t width, size_t height, size_t stride)
Definition: hole-filling-filter.h:73
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
Definition: types.h:55
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:94
void apply_hole_filling(void *image_data)
Definition: hole-filling-filter.h:27
holes_filling_types
Definition: hole-filling-filter.h:8
Definition: hole-filling-filter.h:10
Definition: hole-filling-filter.h:13
void holes_fill_left(T *image_data, size_t width, size_t height, size_t stride)
Definition: hole-filling-filter.h:52