Point Cloud Library (PCL)  1.9.1
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 
42 #ifndef PCL_FILTERS_FAST_BILATERAL_H_
43 #define PCL_FILTERS_FAST_BILATERAL_H_
44 
45 #include <pcl/filters/filter.h>
46 
47 namespace pcl
48 {
49  /** \brief Implementation of a fast bilateral filter for smoothing depth information in organized point clouds
50  * Based on the following paper:
51  * * Sylvain Paris and FrŽdo Durand
52  * "A Fast Approximation of the Bilateral Filter using a Signal Processing Approach"
53  * European Conference on Computer Vision (ECCV'06)
54  *
55  * More details on the webpage: http://people.csail.mit.edu/sparis/bf/
56  */
57  template<typename PointT>
58  class FastBilateralFilter : public Filter<PointT>
59  {
60  protected:
63 
64  public:
65 
66  typedef boost::shared_ptr< FastBilateralFilter<PointT> > Ptr;
67  typedef boost::shared_ptr< const FastBilateralFilter<PointT> > ConstPtr;
68 
69  /** \brief Empty constructor. */
71  : sigma_s_ (15.0f)
72  , sigma_r_ (0.05f)
73  , early_division_ (false)
74  { }
75 
76  /** \brief Empty destructor */
77  virtual ~FastBilateralFilter () {}
78 
79  /** \brief Set the standard deviation of the Gaussian used by the bilateral filter for
80  * the spatial neighborhood/window.
81  * \param[in] sigma_s the size of the Gaussian bilateral filter window to use
82  */
83  inline void
84  setSigmaS (float sigma_s)
85  { sigma_s_ = sigma_s; }
86 
87  /** \brief Get the size of the Gaussian bilateral filter window as set by the user. */
88  inline float
89  getSigmaS () const
90  { return sigma_s_; }
91 
92 
93  /** \brief Set the standard deviation of the Gaussian used to control how much an adjacent
94  * pixel is downweighted because of the intensity difference (depth in our case).
95  * \param[in] sigma_r the standard deviation of the Gaussian for the intensity difference
96  */
97  inline void
98  setSigmaR (float sigma_r)
99  { sigma_r_ = sigma_r; }
100 
101  /** \brief Get the standard deviation of the Gaussian for the intensity difference */
102  inline float
103  getSigmaR () const
104  { return sigma_r_; }
105 
106  /** \brief Filter the input data and store the results into output.
107  * \param[out] output the resultant point cloud
108  */
109  virtual void
110  applyFilter (PointCloud &output);
111 
112  protected:
113  float sigma_s_;
114  float sigma_r_;
116 
117  class Array3D
118  {
119  public:
120  Array3D (const size_t width, const size_t height, const size_t depth)
121  {
122  x_dim_ = width;
123  y_dim_ = height;
124  z_dim_ = depth;
125  v_ = std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > (width*height*depth, Eigen::Vector2f (0.0f, 0.0f));
126  }
127 
128  inline Eigen::Vector2f&
129  operator () (const size_t x, const size_t y, const size_t z)
130  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
131 
132  inline const Eigen::Vector2f&
133  operator () (const size_t x, const size_t y, const size_t z) const
134  { return v_[(x * y_dim_ + y) * z_dim_ + z]; }
135 
136  inline void
137  resize (const size_t width, const size_t height, const size_t depth)
138  {
139  x_dim_ = width;
140  y_dim_ = height;
141  z_dim_ = depth;
142  v_.resize (x_dim_ * y_dim_ * z_dim_);
143  }
144 
145  Eigen::Vector2f
146  trilinear_interpolation (const float x,
147  const float y,
148  const float z);
149 
150  static inline size_t
151  clamp (const size_t min_value,
152  const size_t max_value,
153  const size_t x);
154 
155  inline size_t
156  x_size () const
157  { return x_dim_; }
158 
159  inline size_t
160  y_size () const
161  { return y_dim_; }
162 
163  inline size_t
164  z_size () const
165  { return z_dim_; }
166 
167  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator
168  begin ()
169  { return v_.begin (); }
170 
171  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::iterator
172  end ()
173  { return v_.end (); }
174 
175  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::const_iterator
176  begin () const
177  { return v_.begin (); }
178 
179  inline std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> >::const_iterator
180  end () const
181  { return v_.end (); }
182 
183  private:
184  std::vector<Eigen::Vector2f, Eigen::aligned_allocator<Eigen::Vector2f> > v_;
185  size_t x_dim_, y_dim_, z_dim_;
186  };
187 
188 
189  };
190 }
191 
192 #ifdef PCL_NO_PRECOMPILE
193 #include <pcl/filters/impl/fast_bilateral.hpp>
194 #else
195 #define PCL_INSTANTIATE_FastBilateralFilter(T) template class PCL_EXPORTS pcl::FastBilateralFilter<T>;
196 #endif
197 
198 
199 #endif /* PCL_FILTERS_FAST_BILATERAL_H_ */
Filter< PointT >::PointCloud PointCloud
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
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator begin() const
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
virtual void applyFilter(PointCloud &output)
Filter the input data and store the results into output.
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::iterator end()
std::vector< Eigen::Vector2f, Eigen::aligned_allocator< Eigen::Vector2f > >::const_iterator end() const
Eigen::Vector2f & operator()(const size_t x, const size_t y, const size_t z)
Filter represents the base filter class.
Definition: filter.h:84
virtual ~FastBilateralFilter()
Empty destructor.
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 getSigmaR() const
Get the standard deviation of the Gaussian for the intensity difference.
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)
float getSigmaS() const
Get the size of the Gaussian bilateral filter window as set by the user.