Point Cloud Library (PCL)  1.11.1-dev
fast_bilateral.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2012-, Open Perception, Inc.
6  * Copyright (c) 2004, Sylvain Paris and Francois Sillion
7 
8  * All rights reserved.
9 
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  *
14  * * Redistributions of source code must retain the above copyright
15  * notice, this list of conditions and the following disclaimer.
16  * * Redistributions in binary form must reproduce the above
17  * copyright notice, this list of conditions and the following
18  * disclaimer in the documentation and/or other materials provided
19  * with the distribution.
20  * * Neither the name of the copyright holder(s) nor the names of its
21  * contributors may be used to endorse or promote products derived
22  * from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
28  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
29  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
30  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
34  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35  * POSSIBILITY OF SUCH DAMAGE.
36  *
37  * $Id$
38  *
39  */
40 
41 #pragma once
42 
43 #include <pcl/filters/filter.h>
44 
45 namespace pcl
46 {
47  /** \brief Implementation of a fast bilateral filter for smoothing depth information in organized point clouds
48  * Based on the following paper:
49  * * Sylvain Paris and Fredo Durand
50  * "A Fast Approximation of the Bilateral Filter using a Signal Processing Approach"
51  * European Conference on Computer Vision (ECCV'06)
52  *
53  * More details on the webpage: http://people.csail.mit.edu/sparis/bf/
54  */
55  template<typename PointT>
56  class FastBilateralFilter : public Filter<PointT>
57  {
58  protected:
61 
62  public:
63 
64  using Ptr = shared_ptr<FastBilateralFilter<PointT> >;
65  using ConstPtr = shared_ptr<const FastBilateralFilter<PointT> >;
66 
67  /** \brief Empty constructor. */
69  : sigma_s_ (15.0f)
70  , sigma_r_ (0.05f)
71  , early_division_ (false)
72  { }
73 
74  /** \brief Empty destructor */
76 
77  /** \brief Set the standard deviation of the Gaussian used by the bilateral filter for
78  * the spatial neighborhood/window.
79  * \param[in] sigma_s the size of the Gaussian bilateral filter window to use
80  */
81  inline void
82  setSigmaS (float sigma_s)
83  { sigma_s_ = sigma_s; }
84 
85  /** \brief Get the size of the Gaussian bilateral filter window as set by the user. */
86  inline float
87  getSigmaS () const
88  { return sigma_s_; }
89 
90 
91  /** \brief Set the standard deviation of the Gaussian used to control how much an adjacent
92  * pixel is downweighted because of the intensity difference (depth in our case).
93  * \param[in] sigma_r the standard deviation of the Gaussian for the intensity difference
94  */
95  inline void
96  setSigmaR (float sigma_r)
97  { sigma_r_ = sigma_r; }
98 
99  /** \brief Get the standard deviation of the Gaussian for the intensity difference */
100  inline float
101  getSigmaR () const
102  { return sigma_r_; }
103 
104  /** \brief Filter the input data and store the results into output.
105  * \param[out] output the resultant point cloud
106  */
107  void
108  applyFilter (PointCloud &output) override;
109 
110  protected:
111  float sigma_s_;
112  float sigma_r_;
114 
115  class Array3D
116  {
117  public:
118  Array3D (const std::size_t width, const std::size_t height, const std::size_t depth)
119  {
120  x_dim_ = width;
121  y_dim_ = height;
122  z_dim_ = depth;
123  v_ = std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > (width*height*depth, Eigen::Vector2f (0.0f, 0.0f));
124  }
125 
126  inline Eigen::Vector2f&
127  operator () (const std::size_t x, const std::size_t y, const std::size_t z)
128  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
129 
130  inline const Eigen::Vector2f&
131  operator () (const std::size_t x, const std::size_t y, const std::size_t z) const
132  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
133 
134  inline void
135  resize (const std::size_t width, const std::size_t height, const std::size_t depth)
136  {
137  x_dim_ = width;
138  y_dim_ = height;
139  z_dim_ = depth;
140  v_.resize (x_dim_ * y_dim_ * z_dim_);
141  }
142 
143  Eigen::Vector2f
144  trilinear_interpolation (const float x,
145  const float y,
146  const float z);
147 
148  static inline std::size_t
149  clamp (const std::size_t min_value,
150  const std::size_t max_value,
151  const std::size_t x);
152 
153  inline std::size_t
154  x_size () const
155  { return x_dim_; }
156 
157  inline std::size_t
158  y_size () const
159  { return y_dim_; }
160 
161  inline std::size_t
162  z_size () const
163  { return z_dim_; }
164 
165  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator
166  begin ()
167  { return v_.begin (); }
168 
169  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator
170  end ()
171  { return v_.end (); }
172 
173  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::const_iterator
174  begin () const
175  { return v_.begin (); }
176 
177  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::const_iterator
178  end () const
179  { return v_.end (); }
180 
181  private:
182  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > v_;
183  std::size_t x_dim_, y_dim_, z_dim_;
184  };
185 
186 
187  };
188 }
189 
190 #ifdef PCL_NO_PRECOMPILE
191 #include <pcl/filters/impl/fast_bilateral.hpp>
192 #else
193 #define PCL_INSTANTIATE_FastBilateralFilter(T) template class PCL_EXPORTS pcl::FastBilateralFilter<T>;
194 #endif
pcl::FastBilateralFilter::sigma_r_
float sigma_r_
Definition: fast_bilateral.h:112
pcl::FastBilateralFilter
Implementation of a fast bilateral filter for smoothing depth information in organized point clouds B...
Definition: fast_bilateral.h:56
pcl
Definition: convolution.h:46
pcl::FastBilateralFilter::Array3D::x_size
std::size_t x_size() const
Definition: fast_bilateral.h:154
pcl::FastBilateralFilter::Array3D::resize
void resize(const std::size_t width, const std::size_t height, const std::size_t depth)
Definition: fast_bilateral.h:135
pcl::FastBilateralFilter::Array3D::Array3D
Array3D(const std::size_t width, const std::size_t height, const std::size_t depth)
Definition: fast_bilateral.h:118
pcl::FastBilateralFilter::~FastBilateralFilter
~FastBilateralFilter()
Empty destructor.
Definition: fast_bilateral.h:75
pcl::FastBilateralFilter::Array3D::trilinear_interpolation
Eigen::Vector2f trilinear_interpolation(const float x, const float y, const float z)
Definition: fast_bilateral.hpp:187
pcl::FastBilateralFilter::FastBilateralFilter
FastBilateralFilter()
Empty constructor.
Definition: fast_bilateral.h:68
pcl::FastBilateralFilter::Array3D::end
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator end() const
Definition: fast_bilateral.h:178
pcl::FastBilateralFilter::getSigmaS
float getSigmaS() const
Get the size of the Gaussian bilateral filter window as set by the user.
Definition: fast_bilateral.h:87
pcl::PointCloud
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: distances.h:55
pcl::FastBilateralFilter::Array3D::clamp
static std::size_t clamp(const std::size_t min_value, const std::size_t max_value, const std::size_t x)
Definition: fast_bilateral.hpp:170
pcl::FastBilateralFilter::ConstPtr
shared_ptr< const FastBilateralFilter< PointT > > ConstPtr
Definition: fast_bilateral.h:65
pcl::FastBilateralFilter::sigma_s_
float sigma_s_
Definition: fast_bilateral.h:111
pcl::FastBilateralFilter::Array3D::end
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::iterator end()
Definition: fast_bilateral.h:170
pcl::FastBilateralFilter::Array3D::y_size
std::size_t y_size() const
Definition: fast_bilateral.h:158
pcl::FastBilateralFilter::setSigmaS
void setSigmaS(float sigma_s)
Set the standard deviation of the Gaussian used by the bilateral filter for the spatial neighborhood/...
Definition: fast_bilateral.h:82
pcl::FastBilateralFilter::Array3D::z_size
std::size_t z_size() const
Definition: fast_bilateral.h:162
pcl::FastBilateralFilter::Array3D::begin
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator begin() const
Definition: fast_bilateral.h:174
pcl::FastBilateralFilter::setSigmaR
void setSigmaR(float sigma_r)
Set the standard deviation of the Gaussian used to control how much an adjacent pixel is downweighted...
Definition: fast_bilateral.h:96
pcl::FastBilateralFilter::getSigmaR
float getSigmaR() const
Get the standard deviation of the Gaussian for the intensity difference.
Definition: fast_bilateral.h:101
pcl::FastBilateralFilter::Array3D
Definition: fast_bilateral.h:115
pcl::Filter
Filter represents the base filter class.
Definition: filter.h:80
pcl::FastBilateralFilter::Ptr
shared_ptr< FastBilateralFilter< PointT > > Ptr
Definition: fast_bilateral.h:64
pcl::FastBilateralFilter::applyFilter
void applyFilter(PointCloud &output) override
Filter the input data and store the results into output.
Definition: fast_bilateral.hpp:51
pcl::FastBilateralFilter::Array3D::begin
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::iterator begin()
Definition: fast_bilateral.h:166
pcl::FastBilateralFilter::early_division_
bool early_division_
Definition: fast_bilateral.h:113
pcl::FastBilateralFilter::Array3D::operator()
Eigen::Vector2f & operator()(const std::size_t x, const std::size_t y, const std::size_t z)
Definition: fast_bilateral.h:127