Point Cloud Library (PCL)  1.7.0
bilateral.h
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Point Cloud Library (PCL) - www.pointclouds.org
5  * Copyright (c) 2010-2011, Willow Garage, Inc.
6  *
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  *
13  * * Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  * * Redistributions in binary form must reproduce the above
16  * copyright notice, this list of conditions and the following
17  * disclaimer in the documentation and/or other materials provided
18  * with the distribution.
19  * * Neither the name of the copyright holder(s) nor the names of its
20  * contributors may be used to endorse or promote products derived
21  * from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
26  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
27  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
28  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
29  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
33  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34  * POSSIBILITY OF SUCH DAMAGE.
35  *
36  * $Id$
37  *
38  */
39 
40 #ifndef PCL_FILTERS_BILATERAL_H_
41 #define PCL_FILTERS_BILATERAL_H_
42 
43 #include <pcl/filters/filter.h>
44 #include <pcl/search/pcl_search.h>
45 
46 namespace pcl
47 {
48  /** \brief A bilateral filter implementation for point cloud data. Uses the intensity data channel.
49  * \note For more information please see
50  * <b>C. Tomasi and R. Manduchi. Bilateral Filtering for Gray and Color Images.
51  * In Proceedings of the IEEE International Conference on Computer Vision,
52  * 1998.</b>
53  * \author Luca Penasa
54  * \ingroup filters
55  */
56  template<typename PointT>
57  class BilateralFilter : public Filter<PointT>
58  {
61  typedef typename Filter<PointT>::PointCloud PointCloud;
62  typedef typename pcl::search::Search<PointT>::Ptr KdTreePtr;
63 
64  public:
65 
66  typedef boost::shared_ptr< BilateralFilter<PointT> > Ptr;
67  typedef boost::shared_ptr< const BilateralFilter<PointT> > ConstPtr;
68 
69 
70  /** \brief Constructor.
71  * Sets sigma_s_ to 0 and sigma_r_ to MAXDBL
72  */
73  BilateralFilter () : sigma_s_ (0),
74  sigma_r_ (std::numeric_limits<double>::max ()),
75  tree_ ()
76  {
77  }
78 
79 
80  /** \brief Filter the input data and store the results into output
81  * \param[out] output the resultant point cloud message
82  */
83  void
84  applyFilter (PointCloud &output);
85 
86  /** \brief Compute the intensity average for a single point
87  * \param[in] pid the point index to compute the weight for
88  * \param[in] indices the set of nearest neighor indices
89  * \param[in] distances the set of nearest neighbor distances
90  * \return the intensity average at a given point index
91  */
92  double
93  computePointWeight (const int pid, const std::vector<int> &indices, const std::vector<float> &distances);
94 
95  /** \brief Set the half size of the Gaussian bilateral filter window.
96  * \param[in] sigma_s the half size of the Gaussian bilateral filter window to use
97  */
98  inline void
99  setHalfSize (const double sigma_s)
100  { sigma_s_ = sigma_s; }
101 
102  /** \brief Get the half size of the Gaussian bilateral filter window as set by the user. */
103  inline double
104  getHalfSize () const
105  { return (sigma_s_); }
106 
107  /** \brief Set the standard deviation parameter
108  * \param[in] sigma_r the new standard deviation parameter
109  */
110  inline void
111  setStdDev (const double sigma_r)
112  { sigma_r_ = sigma_r;}
113 
114  /** \brief Get the value of the current standard deviation parameter of the bilateral filter. */
115  inline double
116  getStdDev () const
117  { return (sigma_r_); }
118 
119  /** \brief Provide a pointer to the search object.
120  * \param[in] tree a pointer to the spatial search object.
121  */
122  inline void
123  setSearchMethod (const KdTreePtr &tree)
124  { tree_ = tree; }
125 
126  private:
127 
128  /** \brief The bilateral filter Gaussian distance kernel.
129  * \param[in] x the spatial distance (distance or intensity)
130  * \param[in] sigma standard deviation
131  */
132  inline double
133  kernel (double x, double sigma)
134  { return (exp (- (x*x)/(2*sigma*sigma))); }
135 
136  /** \brief The half size of the Gaussian bilateral filter window (e.g., spatial extents in Euclidean). */
137  double sigma_s_;
138  /** \brief The standard deviation of the bilateral filter (e.g., standard deviation in intensity). */
139  double sigma_r_;
140 
141  /** \brief A pointer to the spatial search object. */
142  KdTreePtr tree_;
143  };
144 }
145 
146 #ifdef PCL_NO_PRECOMPILE
147 #include <pcl/filters/impl/bilateral.hpp>
148 #endif
149 
150 #endif // PCL_FILTERS_BILATERAL_H_