Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[filters] Improve performance of median filter by using nth_element #4360

Merged
merged 1 commit into from
Aug 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions filters/include/pcl/filters/impl/median_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ pcl::MedianFilter<PointT>::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;
Expand Down