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