Point Cloud Library (PCL)  1.14.1-dev
median_filter.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  * $Id$
37  *
38  */
39 
40 #pragma once
41 
42 #include <pcl/filters/filter.h>
43 
44 namespace pcl
45 {
46  /** \brief Implementation of the median filter.
47  * The median filter is one of the simplest and wide-spread image processing filters. It is known to perform well
48  * with "shot"/impulse noise (some individual pixels having extreme values), it does not reduce contrast across steps
49  * in the function (as compared to filters based on averaging), and it is robust to outliers. Furthermore, it is
50  * simple to implement and efficient, as it requires a single pass over the image. It consists of a moving window of
51  * fixed size that replaces the pixel in the center with the median inside the window.
52  *
53  * \note This algorithm filters only the depth (z-component) of _organized_ and untransformed (i.e., in camera coordinates)
54  * point clouds. An error will be outputted if an unorganized cloud is given to the class instance.
55  *
56  * \author Alexandru E. Ichim
57  * \ingroup filters
58  */
59  template <typename PointT>
60  class MedianFilter : public pcl::Filter<PointT>
61  {
64 
65  public:
66  /** \brief Empty constructor. */
67  MedianFilter () = default;
68 
69  /** \brief Set the window size of the filter.
70  * \param[in] window_size the new window size
71  */
72  inline void
73  setWindowSize (int window_size)
74  { window_size_ = window_size; }
75 
76  /** \brief Get the window size of the filter.
77  * \returns the window size of the filter
78  */
79  inline int
80  getWindowSize () const
81  { return window_size_; }
82 
83  /** \brief Set the largest value one dexel is allowed to move
84  * \param[in] max_allowed_movement maximum value a dexel is allowed to move during filtering
85  */
86  inline void
87  setMaxAllowedMovement (float max_allowed_movement)
88  { max_allowed_movement_ = max_allowed_movement; }
89 
90  /** \brief Get the maximum distance one point is allowed to move along the z-axis.
91  * \returns the maximum distance a dexel is allowed to move
92  */
93  inline float
95  { return max_allowed_movement_; }
96 
97  /** \brief Filter the input data and store the results into output.
98  * \param[out] output the result point cloud
99  */
100  void
101  applyFilter (PointCloud &output) override;
102 
103  protected:
104  int window_size_{5};
105  float max_allowed_movement_{std::numeric_limits<float>::max ()};
106  };
107 }
108 
109 #ifdef PCL_NO_PRECOMPILE
110 #include <pcl/filters/impl/median_filter.hpp>
111 #else
112 #define PCL_INSTANTIATE_MedianFilter(T) template class PCL_EXPORTS pcl::MedianFilter<T>;
113 #endif
Filter represents the base filter class.
Definition: filter.h:81
Implementation of the median filter.
Definition: median_filter.h:61
int getWindowSize() const
Get the window size of the filter.
Definition: median_filter.h:80
void setMaxAllowedMovement(float max_allowed_movement)
Set the largest value one dexel is allowed to move.
Definition: median_filter.h:87
void applyFilter(PointCloud &output) override
Filter the input data and store the results into output.
float getMaxAllowedMovement() const
Get the maximum distance one point is allowed to move along the z-axis.
Definition: median_filter.h:94
MedianFilter()=default
Empty constructor.
void setWindowSize(int window_size)
Set the window size of the filter.
Definition: median_filter.h:73
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173