Point Cloud Library (PCL)  1.9.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 FrŽdo 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  typedef boost::shared_ptr< FastBilateralFilter<PointT> > Ptr;
65  typedef boost::shared_ptr< const FastBilateralFilter<PointT> > ConstPtr;
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 size_t width, const size_t height, const 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 size_t x, const size_t y, const size_t z)
128  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
129 
130  inline const Eigen::Vector2f&
131  operator () (const size_t x, const size_t y, const size_t z) const
132  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
133 
134  inline void
135  resize (const size_t width, const size_t height, const 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 size_t
149  clamp (const size_t min_value,
150  const size_t max_value,
151  const size_t x);
152 
153  inline size_t
154  x_size () const
155  { return x_dim_; }
156 
157  inline size_t
158  y_size () const
159  { return y_dim_; }
160 
161  inline 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  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
Filter< PointT >::PointCloud PointCloud
~FastBilateralFilter()
Empty destructor.
Eigen::Vector2f trilinear_interpolation(const float x, const float y, const float z)
FastBilateralFilter()
Empty constructor.
boost::shared_ptr< const FastBilateralFilter< PointT > > ConstPtr
boost::shared_ptr< FastBilateralFilter< PointT > > Ptr
float getSigmaR() const
Get the standard deviation of the Gaussian for the intensity difference.
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:44
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::iterator end()
Eigen::Vector2f & operator()(const size_t x, const size_t y, const size_t z)
Filter represents the base filter class.
Definition: filter.h:83
Array3D(const size_t width, const size_t height, const size_t depth)
void setSigmaS(float sigma_s)
Set the standard deviation of the Gaussian used by the bilateral filter for the spatial neighborhood/...
void resize(const size_t width, const size_t height, const size_t depth)
PointCloud represents the base class in PCL for storing collections of 3D points. ...
float getSigmaS() const
Get the size of the Gaussian bilateral filter window as set by the user.
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator end() const
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::iterator begin()
Implementation of a fast bilateral filter for smoothing depth information in organized point clouds B...
void setSigmaR(float sigma_r)
Set the standard deviation of the Gaussian used to control how much an adjacent pixel is downweighted...
static size_t clamp(const size_t min_value, const size_t max_value, const size_t x)
void applyFilter(PointCloud &output) override
Filter the input data and store the results into output.
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator begin() const