Intel® RealSense™ Cross Platform API
Intel Realsense Cross-platform API
temporal-filter.h
Go to the documentation of this file.
1 // License: Apache 2.0. See LICENSE file in root directory.
2 // Copyright(c) 2017 Intel Corporation. All Rights Reserved.
3 
4 #pragma once
5 #include "types.h"
6 
7 namespace librealsense
8 {
9  const size_t PRESISTENCY_LUT_SIZE = 256;
10 
12  {
13  public:
15 
16  protected:
17  void update_configuration(const rs2::frame& f);
18 
20 
21  template<typename T>
22  void temp_jw_smooth(void* frame_data, void * _last_frame_data, uint8_t *history)
23  {
24  static_assert((std::is_arithmetic<T>::value), "temporal filter assumes numeric types");
25 
26  const bool fp = (std::is_floating_point<T>::value);
27 
28  T delta_z = static_cast<T>(_delta_param);
29 
30  auto frame = reinterpret_cast<T*>(frame_data);
31  auto _last_frame = reinterpret_cast<T*>(_last_frame_data);
32 
33  unsigned char mask = 1 << _cur_frame_index;
34 
35  // pass one -- go through image and update all
36  for (size_t i = 0; i < _current_frm_size_pixels; i++)
37  {
38  T cur_val = frame[i];
39  T prev_val = _last_frame[i];
40 
41  if (cur_val)
42  {
43  if (!prev_val)
44  {
45  _last_frame[i] = cur_val;
46  history[i] = mask;
47  }
48  else
49  { // old and new val
50  T diff = static_cast<T>(fabs(cur_val - prev_val));
51 
52  if (diff < delta_z)
53  { // old and new val agree
54  history[i] |= mask;
55  float filtered = _alpha_param * cur_val + _one_minus_alpha * prev_val;
56  T result = static_cast<T>(filtered);
57  frame[i] = result;
58  _last_frame[i] = result;
59  }
60  else
61  {
62  _last_frame[i] = cur_val;
63  history[i] = mask;
64  }
65  }
66  }
67  else
68  { // no cur_val
69  if (prev_val)
70  { // only case we can help
71  unsigned char hist = history[i];
72  unsigned char classification = _persistence_map[hist];
73  if (classification & mask)
74  { // we have had enough samples lately
75  frame[i] = prev_val;
76  }
77  }
78  history[i] &= ~mask;
79  }
80  }
81 
82  _cur_frame_index = (_cur_frame_index + 1) % 8; // at end of cycle
83  }
84 
85  private:
86  void on_set_persistence_control(uint8_t val);
87  void on_set_alpha(float val);
88  void on_set_delta(float val);
89 
90  void recalc_persistence_map();
91  uint8_t _persistence_param;
92 
93  float _alpha_param; // The normalized weight of the current pixel
94  float _one_minus_alpha;
95  uint8_t _delta_param; // A threshold when a filter is invoked
96  size_t _width, _height, _stride;
97  size_t _bpp;
98  rs2_extension _extension_type; // Strictly Depth/Disparity
99  size_t _current_frm_size_pixels;
100  rs2::stream_profile _source_stream_profile;
101  rs2::stream_profile _target_stream_profile;
102  std::vector<uint8_t> _last_frame; // Hold the last frame received for the current profile
103  std::vector<uint8_t> _history; // represents the history over the last 8 frames, 1 bit per frame
104  uint8_t _cur_frame_index;
105  // encodes whether a particular 8 bit history is good enough for all 8 phases of storage
106  std::array<uint8_t, PRESISTENCY_LUT_SIZE> _persistence_map;
107  };
108 }
Definition: rs_frame.hpp:21
Definition: rs_frame.hpp:202
Definition: backend.h:380
Definition: synthetic-stream.h:41
Definition: temporal-filter.h:11
Definition: archive.h:63
Definition: algo.h:16
Definition: rs_processing.hpp:13
void temp_jw_smooth(void *frame_data, void *_last_frame_data, uint8_t *history)
Definition: temporal-filter.h:22
void update_configuration(const rs2::frame &f)
rs2::frame prepare_target_frame(const rs2::frame &f, const rs2::frame_source &source)
rs2_extension
Specifies advanced interfaces (capabilities) objects may implement.
Definition: rs_types.h:94
const size_t PRESISTENCY_LUT_SIZE
Definition: temporal-filter.h:9