Point Cloud Library (PCL)  1.9.1
edge.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  *
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  */
37 
38 #ifndef PCL_2D_EDGE_H
39 #define PCL_2D_EDGE_H
40 
41 #include <pcl/pcl_base.h>
42 #include <pcl/2d/convolution.h>
43 #include <pcl/2d/kernel.h>
44 
45 namespace pcl
46 {
47  template <typename PointInT, typename PointOutT>
48  class Edge
49  {
50  private:
51  typedef typename pcl::PointCloud<PointInT> PointCloudIn;
52  typedef typename PointCloudIn::Ptr PointCloudInPtr;
53 
54  PointCloudInPtr input_;
55  pcl::Convolution<PointInT> convolution_;
56  kernel<PointInT> kernel_;
57 
58  /** \brief This function performs edge tracing for Canny Edge detector.
59  *
60  * \param[in] rowOffset row offset for direction in which the edge is to be traced
61  * \param[in] colOffset column offset for direction in which the edge is to be traced
62  * \param[in] row row location of the edge point
63  * \param[in] col column location of the edge point
64  * \param[out] maxima point cloud containing the edge information in the magnitude channel
65  */
66  inline void
67  cannyTraceEdge (int rowOffset, int colOffset, int row, int col,
69 
70  /** \brief This function discretizes the edge directions in steps of 22.5 degrees.
71  * \param thet point cloud containing the edge information in the direction channel
72  */
73  void
74  discretizeAngles (pcl::PointCloud<PointOutT> &thet);
75 
76  /** \brief This function suppresses the edges which don't form a local maximum
77  * in the edge direction.
78  * \param[in] edges point cloud containing all the edges
79  * \param[out] maxima point cloud containing the non-max suppressed edges
80  * \param[in] tLow
81  */
82  void
83  suppressNonMaxima (const pcl::PointCloud<PointXYZIEdge> &edges,
84  pcl::PointCloud<pcl::PointXYZI> &maxima, float tLow);
85 
86  public:
87  typedef boost::shared_ptr<Edge> Ptr;
88  typedef boost::shared_ptr<const Edge> ConstPtr;
89 
91  {
99  };
100 
102  {
111  };
112 
113  private:
114  OUTPUT_TYPE output_type_;
115  DETECTOR_KERNEL_TYPE detector_kernel_type_;
116  bool non_maximal_suppression_;
117  bool hysteresis_thresholding_;
118 
119  float hysteresis_threshold_low_;
120  float hysteresis_threshold_high_;
121  float non_max_suppression_radius_x_;
122  float non_max_suppression_radius_y_;
123 
124  public:
125  Edge () :
126  output_type_ (OUTPUT_X),
127  detector_kernel_type_ (SOBEL),
128  non_maximal_suppression_ (false),
129  hysteresis_thresholding_ (false),
130  hysteresis_threshold_low_ (20),
131  hysteresis_threshold_high_ (80),
132  non_max_suppression_radius_x_ (3),
133  non_max_suppression_radius_y_ (3)
134  {
135  }
136 
137  /** \brief Set the output type.
138  * \param[in] output_type the output type
139  */
140  void
142  {
143  output_type_ = output_type;
144  }
145 
146  void
147  setHysteresisThresholdLow (float threshold)
148  {
149  hysteresis_threshold_low_ = threshold;
150  }
151 
152  void
153  setHysteresisThresholdHigh (float threshold)
154  {
155  hysteresis_threshold_high_ = threshold;
156  }
157 
158  /**
159  * \param[in] input_x
160  * \param[in] input_y
161  * \param[out] output
162  */
163  void
165  const pcl::PointCloud<PointInT> &input_y,
167 
168 
169  /** \brief Perform Canny edge detection with two separated input images for
170  * horizontal and vertical derivatives.
171  * All edges of magnitude above t_high are always classified as edges. All edges
172  * below t_low are discarded. Edge values between t_low and t_high are classified
173  * as edges only if they are connected to edges having magnitude > t_high and are
174  * located in a direction perpendicular to that strong edge.
175  *
176  * \param[in] input_x Input point cloud passed by reference for the first derivative in the horizontal direction
177  * \param[in] input_y Input point cloud passed by reference for the first derivative in the vertical direction
178  * \param[out] output Output point cloud passed by reference
179  */
180  void
181  canny (const pcl::PointCloud<PointInT> &input_x,
182  const pcl::PointCloud<PointInT> &input_y,
184 
185  /** \brief This is a convenience function which performs edge detection based on
186  * the variable detector_kernel_type_
187  * \param[out] output
188  */
189  void
191 
192  /** \brief All edges of magnitude above t_high are always classified as edges.
193  * All edges below t_low are discarded.
194  * Edge values between t_low and t_high are classified as edges only if they are
195  * connected to edges having magnitude > t_high and are located in a direction
196  * perpendicular to that strong edge.
197  * \param[out] output Output point cloud passed by reference
198  */
199  void
201 
202  /** \brief Uses the Sobel kernel for edge detection.
203  * This function does NOT include a smoothing step.
204  * The image should be smoothed before using this function to reduce noise.
205  * \param[out] output Output point cloud passed by reference
206  */
207  void
209 
210  /** \brief Uses the Prewitt kernel for edge detection.
211  * This function does NOT include a smoothing step.
212  * The image should be smoothed before using this function to reduce noise.
213  * \param[out] output Output point cloud passed by reference
214  */
215  void
217 
218  /** \brief Uses the Roberts kernel for edge detection.
219  * This function does NOT include a smoothing step.
220  * The image should be smoothed before using this function to reduce noise.
221  * \param[out] output Output point cloud passed by reference
222  */
223  void
225 
226  /** \brief Uses the LoG kernel for edge detection.
227  * Zero crossings of the Laplacian operator applied on an image indicate edges.
228  * Gaussian kernel is used to smoothen the image prior to the Laplacian.
229  * This is because Laplacian uses the second order derivative of the image and hence, is very sensitive to noise.
230  * The implementation is not two-step but rather applies the LoG kernel directly.
231  *
232  * \param[in] kernel_sigma variance of the LoG kernel used.
233  * \param[in] kernel_size a LoG kernel of dimensions kernel_size x kernel_size is used.
234  * \param[out] output Output point cloud passed by reference.
235  */
236  void
237  detectEdgeLoG (const float kernel_sigma, const float kernel_size,
239 
240  /** \brief Computes the image derivatives in X direction using the kernel kernel::derivativeYCentralKernel.
241  * This function does NOT include a smoothing step.
242  * The image should be smoothed before using this function to reduce noise.
243  * \param[out] output Output point cloud passed by reference
244  */
245  void
247 
248  /** \brief Computes the image derivatives in Y direction using the kernel kernel::derivativeYCentralKernel.
249  * This function does NOT include a smoothing step.
250  * The image should be smoothed before using this function to reduce noise.
251  * \param[out] output Output point cloud passed by reference
252  */
253  void
255 
256  /** \brief Computes the image derivatives in X direction using the kernel kernel::derivativeYForwardKernel.
257  * This function does NOT include a smoothing step.
258  * The image should be smoothed before using this function to reduce noise.
259  * \param[out] output Output point cloud passed by reference
260  */
261  void
263 
264  /** \brief Computes the image derivatives in Y direction using the kernel kernel::derivativeYForwardKernel.
265  * This function does NOT include a smoothing step.
266  * The image should be smoothed before using this function to reduce noise.
267  * \param[out] output Output point cloud passed by reference
268  */
269  void
271 
272  /** \brief Computes the image derivatives in X direction using the kernel kernel::derivativeXBackwardKernel.
273  * This function does NOT include a smoothing step.
274  * The image should be smoothed before using this function to reduce noise.
275  * \param output Output point cloud passed by reference
276  */
277  void
279 
280  /** \brief Computes the image derivatives in Y direction using the kernel kernel::derivativeYBackwardKernel.
281  * This function does NOT include a smoothing step.
282  * The image should be smoothed before using this function to reduce noise.
283  * \param[out] output Output point cloud passed by reference
284  */
285  void
287 
288  /** \brief Override function to implement the pcl::Filter interface
289  */
290  void
292 
293  /** \brief Set the input point cloud pointer
294  * \param[in] input pointer to input point cloud
295  */
296  void
297  setInputCloud (PointCloudInPtr input)
298  {
299  input_ = input;
300  }
301 
302  EIGEN_MAKE_ALIGNED_OPERATOR_NEW
303  };
304 }
305 #include <pcl/2d/impl/edge.hpp>
306 
307 #endif // PCL_2D_EDGE_H
308 
DETECTOR_KERNEL_TYPE
Definition: edge.h:101
boost::shared_ptr< const Edge > ConstPtr
Definition: edge.h:88
void computeDerivativeYBackward(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in Y direction using the kernel kernel::derivativeYBackwardKernel.
boost::shared_ptr< Edge > Ptr
Definition: edge.h:87
This file defines compatibility wrappers for low level I/O functions.
Definition: convolution.h:45
void setOutputType(OUTPUT_TYPE output_type)
Set the output type.
Definition: edge.h:141
void setHysteresisThresholdHigh(float threshold)
Definition: edge.h:153
Definition: edge.h:48
void applyFilter(pcl::PointCloud< PointOutT > &)
Override function to implement the pcl::Filter interface.
Definition: edge.h:291
OUTPUT_TYPE
Definition: edge.h:90
boost::shared_ptr< PointCloud< PointInT > > Ptr
Definition: point_cloud.h:428
void sobelMagnitudeDirection(const pcl::PointCloud< PointInT > &input_x, const pcl::PointCloud< PointInT > &input_y, pcl::PointCloud< PointOutT > &output)
Definition: edge.hpp:91
void setInputCloud(PointCloudInPtr input)
Set the input point cloud pointer.
Definition: edge.h:297
void computeDerivativeXBackward(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in X direction using the kernel kernel::derivativeXBackwardKernel.
void computeDerivativeXForward(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in X direction using the kernel kernel::derivativeYForwardKernel.
void computeDerivativeYForward(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in Y direction using the kernel kernel::derivativeYForwardKernel.
void detectEdgePrewitt(pcl::PointCloud< PointOutT > &output)
Uses the Prewitt kernel for edge detection.
Definition: edge.hpp:133
void setHysteresisThresholdLow(float threshold)
Definition: edge.h:147
void detectEdge(pcl::PointCloud< PointOutT > &output)
This is a convenience function which performs edge detection based on the variable detector_kernel_ty...
void canny(const pcl::PointCloud< PointInT > &input_x, const pcl::PointCloud< PointInT > &input_y, pcl::PointCloud< PointOutT > &output)
Perform Canny edge detection with two separated input images for horizontal and vertical derivatives.
Definition: edge.hpp:403
void detectEdgeSobel(pcl::PointCloud< PointOutT > &output)
Uses the Sobel kernel for edge detection.
Definition: edge.hpp:47
void detectEdgeLoG(const float kernel_sigma, const float kernel_size, pcl::PointCloud< PointOutT > &output)
Uses the LoG kernel for edge detection.
Definition: edge.hpp:479
void computeDerivativeYCentral(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in Y direction using the kernel kernel::derivativeYCentralKernel.
void computeDerivativeXCentral(pcl::PointCloud< PointOutT > &output)
Computes the image derivatives in X direction using the kernel kernel::derivativeYCentralKernel.
void detectEdgeCanny(pcl::PointCloud< PointOutT > &output)
All edges of magnitude above t_high are always classified as edges.
Definition: edge.hpp:329
void detectEdgeRoberts(pcl::PointCloud< PointOutT > &output)
Uses the Roberts kernel for edge detection.
Definition: edge.hpp:172
Edge()
Definition: edge.h:125