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