Point Cloud Library (PCL) 1.13.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#pragma once
41
42#include <pcl/filters/filter.h>
43
44namespace 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. */
68 : window_size_ (5)
69 , max_allowed_movement_ (std::numeric_limits<float>::max ())
70 { }
71
72 /** \brief Set the window size of the filter.
73 * \param[in] window_size the new window size
74 */
75 inline void
76 setWindowSize (int window_size)
77 { window_size_ = window_size; }
78
79 /** \brief Get the window size of the filter.
80 * \returns the window size of the filter
81 */
82 inline int
84 { return window_size_; }
85
86 /** \brief Set the largest value one dexel is allowed to move
87 * \param[in] max_allowed_movement maximum value a dexel is allowed to move during filtering
88 */
89 inline void
90 setMaxAllowedMovement (float max_allowed_movement)
91 { max_allowed_movement_ = max_allowed_movement; }
92
93 /** \brief Get the maximum distance one point is allowed to move along the z-axis.
94 * \returns the maximum distance a dexel is allowed to move
95 */
96 inline float
98 { return max_allowed_movement_; }
99
100 /** \brief Filter the input data and store the results into output.
101 * \param[out] output the result point cloud
102 */
103 void
104 applyFilter (PointCloud &output) override;
105
106 protected:
109 };
110}
111
112#ifdef PCL_NO_PRECOMPILE
113#include <pcl/filters/impl/median_filter.hpp>
114#else
115#define PCL_INSTANTIATE_MedianFilter(T) template class PCL_EXPORTS pcl::MedianFilter<T>;
116#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:83
void setMaxAllowedMovement(float max_allowed_movement)
Set the largest value one dexel is allowed to move.
Definition: median_filter.h:90
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:97
MedianFilter()
Empty constructor.
Definition: median_filter.h:67
void setWindowSize(int window_size)
Set the window size of the filter.
Definition: median_filter.h:76
PointCloudConstPtr input_
The input point cloud dataset.
Definition: pcl_base.h:147
PointCloud represents the base class in PCL for storing collections of 3D points.
Definition: point_cloud.h:173
A point structure representing Euclidean xyz coordinates, and the RGB color.