From 8c968e0742352b4a6b66c486494f4ff29af071c7 Mon Sep 17 00:00:00 2001 From: Markus Vieth Date: Thu, 27 Aug 2020 11:46:33 +0200 Subject: [PATCH] Use nth_element in median filter nth_element is faster than partial_sort, and should be used for median finding --- filters/include/pcl/filters/impl/median_filter.hpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/filters/include/pcl/filters/impl/median_filter.hpp b/filters/include/pcl/filters/impl/median_filter.hpp index a29ed545fcc..8f72ab844f5 100644 --- a/filters/include/pcl/filters/impl/median_filter.hpp +++ b/filters/include/pcl/filters/impl/median_filter.hpp @@ -76,8 +76,9 @@ pcl::MedianFilter::applyFilter (PointCloud &output) continue; // The output depth will be the median of all the depths in the window - partial_sort (vals.begin (), vals.begin () + vals.size () / 2 + 1, vals.end ()); - float new_depth = vals[vals.size () / 2]; + auto middle_it = vals.begin () + vals.size () / 2; + std::nth_element (vals.begin (), middle_it, vals.end ()); + float new_depth = *middle_it; // Do not allow points to move more than the set max_allowed_movement_ if (std::abs (new_depth - (*input_)(x, y).z) < max_allowed_movement_) output (x, y).z = new_depth;