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