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