42 #include <pcl/filters/median_filter.h>
43 #include <pcl/common/point_tests.h>
45 template <
typename Po
intT>
void
48 if (!input_->isOrganized ())
50 PCL_ERROR (
"[pcl::MedianFilter] Input cloud needs to be organized\n");
57 int height =
static_cast<int> (output.
height);
58 int width =
static_cast<int> (output.
width);
59 for (
int y = 0; y < height; ++y)
60 for (
int x = 0; x < width; ++x)
63 std::vector<float> vals;
64 vals.reserve (window_size_ * window_size_);
66 for (
int y_dev = -window_size_/2; y_dev <= window_size_/2; ++y_dev)
67 for (
int x_dev = -window_size_/2; x_dev <= window_size_/2; ++x_dev)
69 if (x + x_dev >= 0 && x + x_dev < width &&
70 y + y_dev >= 0 && y + y_dev < height &&
72 vals.push_back ((*input_)(x+x_dev, y+y_dev).z);
79 auto middle_it = vals.begin () + vals.size () / 2;
80 std::nth_element (vals.begin (), middle_it, vals.end ());
81 float new_depth = *middle_it;
83 if (std::abs (new_depth - (*input_)(x, y).z) < max_allowed_movement_)
84 output (x, y).z = new_depth;
86 output (x, y).z = (*input_)(x, y).z +
87 max_allowed_movement_ * (new_depth - (*input_)(x, y).z) / std::abs (new_depth - (*input_)(x, y).z);
PointCloud represents the base class in PCL for storing collections of 3D points.
std::uint32_t width
The point cloud width (if organized as an image-structure).
std::uint32_t height
The point cloud height (if organized as an image-structure).
void copyPointCloud(const pcl::PointCloud< PointInT > &cloud_in, pcl::PointCloud< PointOutT > &cloud_out)
Copy all the fields from a given point cloud into a new point cloud.
bool isFinite(const PointT &pt)
Tests if the 3D components of a point are all finite param[in] pt point to be tested return true if f...