Point Cloud Library (PCL)  1.14.0-dev
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  /** \brief Constructor.
69  * Sets sigma_s_ to 0 and sigma_r_ to MAXDBL
70  */
71  BilateralFilter () : tree_ ()
72  {
73  }
74  /** \brief Compute the intensity average for a single point
75  * \param[in] pid the point index to compute the weight for
76  * \param[in] indices the set of nearest neighbor indices
77  * \param[in] distances the set of nearest neighbor distances
78  * \return the intensity average at a given point index
79  */
80  double
81  computePointWeight (const int pid, const Indices &indices, const std::vector<float> &distances);
82 
83  /** \brief Set the half size of the Gaussian bilateral filter window.
84  * \param[in] sigma_s the half size of the Gaussian bilateral filter window to use
85  */
86  inline void
87  setHalfSize (const double sigma_s)
88  { sigma_s_ = sigma_s; }
89 
90  /** \brief Get the half size of the Gaussian bilateral filter window as set by the user. */
91  inline double
92  getHalfSize () const
93  { return (sigma_s_); }
94 
95  /** \brief Set the standard deviation parameter
96  * \param[in] sigma_r the new standard deviation parameter
97  */
98  inline void
99  setStdDev (const double sigma_r)
100  { sigma_r_ = sigma_r;}
101 
102  /** \brief Get the value of the current standard deviation parameter of the bilateral filter. */
103  inline double
104  getStdDev () const
105  { return (sigma_r_); }
106 
107  /** \brief Provide a pointer to the search object.
108  * \param[in] tree a pointer to the spatial search object.
109  */
110  inline void
111  setSearchMethod (const KdTreePtr &tree)
112  { tree_ = tree; }
113 
114  protected:
115  /** \brief Filter the input data and store the results into output
116  * \param[out] output the resultant point cloud message
117  */
118  void
119  applyFilter (PointCloud &output) override;
120 
121  private:
122  /** \brief The bilateral filter Gaussian distance kernel.
123  * \param[in] x the spatial distance (distance or intensity)
124  * \param[in] sigma standard deviation
125  */
126  inline double
127  kernel (double x, double sigma)
128  { return (std::exp (- (x*x)/(2*sigma*sigma))); }
129 
130  /** \brief The half size of the Gaussian bilateral filter window (e.g., spatial extents in Euclidean). */
131  double sigma_s_{0.0};
132  /** \brief The standard deviation of the bilateral filter (e.g., standard deviation in intensity). */
133  double sigma_r_{std::numeric_limits<double>::max ()};
134 
135  /** \brief A pointer to the spatial search object. */
136  KdTreePtr tree_;
137  };
138 }
139 
140 #ifdef PCL_NO_PRECOMPILE
141 #include <pcl/filters/impl/bilateral.hpp>
142 #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:111
double getStdDev() const
Get the value of the current standard deviation parameter of the bilateral filter.
Definition: bilateral.h:104
shared_ptr< const BilateralFilter< PointT > > ConstPtr
Definition: bilateral.h:66
BilateralFilter()
Constructor.
Definition: bilateral.h:71
double getHalfSize() const
Get the half size of the Gaussian bilateral filter window as set by the user.
Definition: bilateral.h:92
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:99
void setHalfSize(const double sigma_s)
Set the half size of the Gaussian bilateral filter window.
Definition: bilateral.h:87
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