Point Cloud Library (PCL) 1.13.0
gaussian.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/point_cloud.h>
43
44#include <Eigen/Core> // for VectorXf
45
46#include <functional>
47
48namespace pcl
49{
50 /** Class GaussianKernel assembles all the method for computing,
51 * convolving, smoothing, gradients computing an image using
52 * a gaussian kernel. The image is stored in point cloud elements
53 * intensity member or rgb or...
54 * \author Nizar Sallem
55 * \ingroup common
56 */
58 {
59 public:
60
61 static const unsigned MAX_KERNEL_WIDTH = 71;
62 /** Computes the gaussian kernel and dervative assiociated to sigma.
63 * The kernel and derivative width are adjusted according.
64 * \param[in] sigma
65 * \param[out] kernel the computed gaussian kernel
66 * \param[in] kernel_width the desired kernel width upper bond
67 * \throws pcl::KernelWidthTooSmallException
68 */
69 void
70 compute (float sigma,
71 Eigen::VectorXf &kernel,
72 unsigned kernel_width = MAX_KERNEL_WIDTH) const;
73
74 /** Computes the gaussian kernel and dervative assiociated to sigma.
75 * The kernel and derivative width are adjusted according.
76 * \param[in] sigma
77 * \param[out] kernel the computed gaussian kernel
78 * \param[out] derivative the computed kernel derivative
79 * \param[in] kernel_width the desired kernel width upper bond
80 * \throws pcl::KernelWidthTooSmallException
81 */
82 void
83 compute (float sigma,
84 Eigen::VectorXf &kernel,
85 Eigen::VectorXf &derivative,
86 unsigned kernel_width = MAX_KERNEL_WIDTH) const;
87
88 /** Convolve a float image rows by a given kernel.
89 * \param[in] kernel convolution kernel
90 * \param[in] input the image to convolve
91 * \param[out] output the convolved image
92 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
93 * output.cols () < input.cols () then output is resized to input sizes.
94 */
95 void
97 const Eigen::VectorXf &kernel,
98 pcl::PointCloud<float> &output) const;
99
100 /** Convolve a float image rows by a given kernel.
101 * \param[in] input the image to convolve
102 * \param[in] field_accessor a field accessor
103 * \param[in] kernel convolution kernel
104 * \param[out] output the convolved image
105 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
106 * output.cols () < input.cols () then output is resized to input sizes.
107 */
108 template <typename PointT> void
109 convolveRows (const pcl::PointCloud<PointT> &input,
110 std::function <float (const PointT& p)> field_accessor,
111 const Eigen::VectorXf &kernel,
112 pcl::PointCloud<float> &output) const;
113
114 /** Convolve a float image columns by a given kernel.
115 * \param[in] input the image to convolve
116 * \param[in] kernel convolution kernel
117 * \param[out] output the convolved image
118 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
119 * output.cols () < input.cols () then output is resized to input sizes.
120 */
121 void
123 const Eigen::VectorXf &kernel,
124 pcl::PointCloud<float> &output) const;
125
126 /** Convolve a float image columns by a given kernel.
127 * \param[in] input the image to convolve
128 * \param[in] field_accessor a field accessor
129 * \param[in] kernel convolution kernel
130 * \param[out] output the convolved image
131 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
132 * output.cols () < input.cols () then output is resized to input sizes.
133 */
134 template <typename PointT> void
135 convolveCols (const pcl::PointCloud<PointT> &input,
136 std::function <float (const PointT& p)> field_accessor,
137 const Eigen::VectorXf &kernel,
138 pcl::PointCloud<float> &output) const;
139
140 /** Convolve a float image in the 2 directions
141 * \param[in] horiz_kernel kernel for convolving rows
142 * \param[in] vert_kernel kernel for convolving columns
143 * \param[in] input image to convolve
144 * \param[out] output the convolved image
145 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
146 * output.cols () < input.cols () then output is resized to input sizes.
147 */
148 inline void
150 const Eigen::VectorXf &horiz_kernel,
151 const Eigen::VectorXf &vert_kernel,
152 pcl::PointCloud<float> &output) const
153 {
154 std::cout << ">>> convolve cpp" << std::endl;
155 pcl::PointCloud<float> tmp (input.width, input.height) ;
156 convolveRows (input, horiz_kernel, tmp);
157 convolveCols (tmp, vert_kernel, output);
158 std::cout << "<<< convolve cpp" << std::endl;
159 }
160
161 /** Convolve a float image in the 2 directions
162 * \param[in] input image to convolve
163 * \param[in] field_accessor a field accessor
164 * \param[in] horiz_kernel kernel for convolving rows
165 * \param[in] vert_kernel kernel for convolving columns
166 * \param[out] output the convolved image
167 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
168 * output.cols () < input.cols () then output is resized to input sizes.
169 */
170 template <typename PointT> inline void
172 std::function <float (const PointT& p)> field_accessor,
173 const Eigen::VectorXf &horiz_kernel,
174 const Eigen::VectorXf &vert_kernel,
175 pcl::PointCloud<float> &output) const
176 {
177 std::cout << ">>> convolve hpp" << std::endl;
178 pcl::PointCloud<float> tmp (input.width, input.height);
179 convolveRows<PointT>(input, field_accessor, horiz_kernel, tmp);
180 convolveCols(tmp, vert_kernel, output);
181 std::cout << "<<< convolve hpp" << std::endl;
182 }
183
184 /** Computes float image gradients using a gaussian kernel and gaussian kernel
185 * derivative.
186 * \param[in] input image to compute gardients for
187 * \param[in] gaussian_kernel the gaussian kernel to be used
188 * \param[in] gaussian_kernel_derivative the associated derivative
189 * \param[out] grad_x gradient along X direction
190 * \param[out] grad_y gradient along Y direction
191 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
192 * output.cols () < input.cols () then output is resized to input sizes.
193 */
194 inline void
196 const Eigen::VectorXf &gaussian_kernel,
197 const Eigen::VectorXf &gaussian_kernel_derivative,
199 pcl::PointCloud<float> &grad_y) const
200 {
201 convolve (input, gaussian_kernel_derivative, gaussian_kernel, grad_x);
202 convolve (input, gaussian_kernel, gaussian_kernel_derivative, grad_y);
203 }
204
205 /** Computes float image gradients using a gaussian kernel and gaussian kernel
206 * derivative.
207 * \param[in] input image to compute gardients for
208 * \param[in] field_accessor a field accessor
209 * \param[in] gaussian_kernel the gaussian kernel to be used
210 * \param[in] gaussian_kernel_derivative the associated derivative
211 * \param[out] grad_x gradient along X direction
212 * \param[out] grad_y gradient along Y direction
213 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
214 * output.cols () < input.cols () then output is resized to input sizes.
215 */
216 template <typename PointT> inline void
218 std::function <float (const PointT& p)> field_accessor,
219 const Eigen::VectorXf &gaussian_kernel,
220 const Eigen::VectorXf &gaussian_kernel_derivative,
222 pcl::PointCloud<float> &grad_y) const
223 {
224 convolve<PointT> (input, field_accessor, gaussian_kernel_derivative, gaussian_kernel, grad_x);
225 convolve<PointT> (input, field_accessor, gaussian_kernel, gaussian_kernel_derivative, grad_y);
226 }
227
228 /** Smooth image using a gaussian kernel.
229 * \param[in] input image
230 * \param[in] gaussian_kernel the gaussian kernel to be used
231 * \param[out] output the smoothed image
232 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
233 * output.cols () < input.cols () then output is resized to input sizes.
234 */
235 inline void
237 const Eigen::VectorXf &gaussian_kernel,
238 pcl::PointCloud<float> &output) const
239 {
240 convolve (input, gaussian_kernel, gaussian_kernel, output);
241 }
242
243 /** Smooth image using a gaussian kernel.
244 * \param[in] input image
245 * \param[in] field_accessor a field accessor
246 * \param[in] gaussian_kernel the gaussian kernel to be used
247 * \param[out] output the smoothed image
248 * \note if output doesn't fit in input i.e. output.rows () < input.rows () or
249 * output.cols () < input.cols () then output is resized to input sizes.
250 */
251 template <typename PointT> inline void
253 std::function <float (const PointT& p)> field_accessor,
254 const Eigen::VectorXf &gaussian_kernel,
255 pcl::PointCloud<float> &output) const
256 {
257 convolve<PointT> (input, field_accessor, gaussian_kernel, gaussian_kernel, output);
258 }
259 };
260}
261
262#include <pcl/common/impl/gaussian.hpp>
Class GaussianKernel assembles all the method for computing, convolving, smoothing,...
Definition: gaussian.h:58
void computeGradients(const pcl::PointCloud< PointT > &input, std::function< float(const PointT &p)> field_accessor, const Eigen::VectorXf &gaussian_kernel, const Eigen::VectorXf &gaussian_kernel_derivative, pcl::PointCloud< float > &grad_x, pcl::PointCloud< float > &grad_y) const
Computes float image gradients using a gaussian kernel and gaussian kernel derivative.
Definition: gaussian.h:217
void convolveCols(const pcl::PointCloud< float > &input, const Eigen::VectorXf &kernel, pcl::PointCloud< float > &output) const
Convolve a float image columns by a given kernel.
void compute(float sigma, Eigen::VectorXf &kernel, unsigned kernel_width=MAX_KERNEL_WIDTH) const
Computes the gaussian kernel and dervative assiociated to sigma.
void smooth(const pcl::PointCloud< PointT > &input, std::function< float(const PointT &p)> field_accessor, const Eigen::VectorXf &gaussian_kernel, pcl::PointCloud< float > &output) const
Smooth image using a gaussian kernel.
Definition: gaussian.h:252
void convolve(const pcl::PointCloud< float > &input, const Eigen::VectorXf &horiz_kernel, const Eigen::VectorXf &vert_kernel, pcl::PointCloud< float > &output) const
Convolve a float image in the 2 directions.
Definition: gaussian.h:149
void compute(float sigma, Eigen::VectorXf &kernel, Eigen::VectorXf &derivative, unsigned kernel_width=MAX_KERNEL_WIDTH) const
Computes the gaussian kernel and dervative assiociated to sigma.
void convolve(const pcl::PointCloud< PointT > &input, std::function< float(const PointT &p)> field_accessor, const Eigen::VectorXf &horiz_kernel, const Eigen::VectorXf &vert_kernel, pcl::PointCloud< float > &output) const
Convolve a float image in the 2 directions.
Definition: gaussian.h:171
void smooth(const pcl::PointCloud< float > &input, const Eigen::VectorXf &gaussian_kernel, pcl::PointCloud< float > &output) const
Smooth image using a gaussian kernel.
Definition: gaussian.h:236
void convolveRows(const pcl::PointCloud< float > &input, const Eigen::VectorXf &kernel, pcl::PointCloud< float > &output) const
Convolve a float image rows by a given kernel.
void computeGradients(const pcl::PointCloud< float > &input, const Eigen::VectorXf &gaussian_kernel, const Eigen::VectorXf &gaussian_kernel_derivative, pcl::PointCloud< float > &grad_x, pcl::PointCloud< float > &grad_y) const
Computes float image gradients using a gaussian kernel and gaussian kernel derivative.
Definition: gaussian.h:195
std::uint32_t width
The point cloud width (if organized as an image-structure).
Definition: point_cloud.h:398
std::uint32_t height
The point cloud height (if organized as an image-structure).
Definition: point_cloud.h:400
#define PCL_EXPORTS
Definition: pcl_macros.h:323
A point structure representing Euclidean xyz coordinates, and the RGB color.