Point Cloud Library (PCL)  1.12.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 #pragma once
41 
42 #include <pcl/filters/filter.h>
43 #include <pcl/search/search.h> // for Search
44 
45 namespace pcl
46 {
47  /** \brief A bilateral filter implementation for point cloud data. Uses the intensity data channel.
48  * \note For more information please see
49  * <b>C. Tomasi and R. Manduchi. Bilateral Filtering for Gray and Color Images.
50  * In Proceedings of the IEEE International Conference on Computer Vision,
51  * 1998.</b>
52  * \author Luca Penasa
53  * \ingroup filters
54  */
55  template<typename PointT>
56  class BilateralFilter : public Filter<PointT>
57  {
60  using PointCloud = typename Filter<PointT>::PointCloud;
61  using KdTreePtr = typename pcl::search::Search<PointT>::Ptr;
62 
63  public:
64 
65  using Ptr = shared_ptr<BilateralFilter<PointT> >;
66  using ConstPtr = shared_ptr<const BilateralFilter<PointT> >;
67 
68 
69  /** \brief Constructor.
70  * Sets sigma_s_ to 0 and sigma_r_ to MAXDBL
71  */
72  BilateralFilter () : sigma_s_ (0),
73  sigma_r_ (std::numeric_limits<double>::max ()),
74  tree_ ()
75  {
76  }
77 
78 
79  /** \brief Filter the input data and store the results into output
80  * \param[out] output the resultant point cloud message
81  */
82  void
83  applyFilter (PointCloud &output) override;
84 
85  /** \brief Compute the intensity average for a single point
86  * \param[in] pid the point index to compute the weight for
87  * \param[in] indices the set of nearest neighor indices
88  * \param[in] distances the set of nearest neighbor distances
89  * \return the intensity average at a given point index
90  */
91  double
92  computePointWeight (const int pid, const Indices &indices, const std::vector<float> &distances);
93 
94  /** \brief Set the half size of the Gaussian bilateral filter window.
95  * \param[in] sigma_s the half size of the Gaussian bilateral filter window to use
96  */
97  inline void
98  setHalfSize (const double sigma_s)
99  { sigma_s_ = sigma_s; }
100 
101  /** \brief Get the half size of the Gaussian bilateral filter window as set by the user. */
102  inline double
103  getHalfSize () const
104  { return (sigma_s_); }
105 
106  /** \brief Set the standard deviation parameter
107  * \param[in] sigma_r the new standard deviation parameter
108  */
109  inline void
110  setStdDev (const double sigma_r)
111  { sigma_r_ = sigma_r;}
112 
113  /** \brief Get the value of the current standard deviation parameter of the bilateral filter. */
114  inline double
115  getStdDev () const
116  { return (sigma_r_); }
117 
118  /** \brief Provide a pointer to the search object.
119  * \param[in] tree a pointer to the spatial search object.
120  */
121  inline void
122  setSearchMethod (const KdTreePtr &tree)
123  { tree_ = tree; }
124 
125  private:
126 
127  /** \brief The bilateral filter Gaussian distance kernel.
128  * \param[in] x the spatial distance (distance or intensity)
129  * \param[in] sigma standard deviation
130  */
131  inline double
132  kernel (double x, double sigma)
133  { return (std::exp (- (x*x)/(2*sigma*sigma))); }
134 
135  /** \brief The half size of the Gaussian bilateral filter window (e.g., spatial extents in Euclidean). */
136  double sigma_s_;
137  /** \brief The standard deviation of the bilateral filter (e.g., standard deviation in intensity). */
138  double sigma_r_;
139 
140  /** \brief A pointer to the spatial search object. */
141  KdTreePtr tree_;
142  };
143 }
144 
145 #ifdef PCL_NO_PRECOMPILE
146 #include <pcl/filters/impl/bilateral.hpp>
147 #endif
A bilateral filter implementation for point cloud data.
Definition: bilateral.h:57
shared_ptr< BilateralFilter< PointT > > Ptr
Definition: bilateral.h:65
void setSearchMethod(const KdTreePtr &tree)
Provide a pointer to the search object.
Definition: bilateral.h:122
double getStdDev() const
Get the value of the current standard deviation parameter of the bilateral filter.
Definition: bilateral.h:115
shared_ptr< const BilateralFilter< PointT > > ConstPtr
Definition: bilateral.h:66
BilateralFilter()
Constructor.
Definition: bilateral.h:72
double getHalfSize() const
Get the half size of the Gaussian bilateral filter window as set by the user.
Definition: bilateral.h:103
void applyFilter(PointCloud &output) override
Filter the input data and store the results into output.
Definition: bilateral.hpp:75
void setStdDev(const double sigma_r)
Set the standard deviation parameter.
Definition: bilateral.h:110
void setHalfSize(const double sigma_s)
Set the half size of the Gaussian bilateral filter window.
Definition: bilateral.h:98
double computePointWeight(const int pid, const Indices &indices, const std::vector< float > &distances)
Compute the intensity average for a single point.
Definition: bilateral.hpp:49
Filter represents the base filter class.
Definition: filter.h:81
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
shared_ptr< pcl::search::Search< PointT > > Ptr
Definition: search.h:81
IndicesAllocator<> Indices
Type used for indices in PCL.
Definition: types.h:133