1.原理介绍
StatisticalOutlierRemoval滤波器主要可以用来剔除离群点,或者测量误差导致的粗差点。
滤波思想为:对每一个点的邻域进行一个统计分析,计算它到所有临近点的平均距离。假设得到的结果是一个高斯分布,其形状是由均值和标准差决定,那么平均距离在标准范围(由全局距离平均值和方差定义)之外的点,可以被定义为离群点并从数据中去除。
2.源码剖析
1 | // The arrays to be used |
第一步:计算每个点到所有K邻域点的平均距离。
1 | //First pass: Compute the mean distances for all points with respect to their k nearest neighbors |
第二步:计算整个点集距离容器的平均值和标准差
1 | //Estimate the mean and the standard deviation of the distance vector |
第三步:依次将距离阈值与每个点的distances[iii]比较 ,超出阈值的点被标记为离群点,并将其移除。
1 | // Second pass: Classify the points on the computed distance threshold |
3.示例代码
1 |
|
4.示例代码结果
参考
《点云库PCL学习教程》