Q3D-Calibration/include/clip.h

64 lines
1.8 KiB
C
Raw Normal View History

2022-07-04 23:52:05 +08:00
#pragma once
#ifndef clip_h
#define clip_h
#include "utils.h"
2022-07-04 23:52:05 +08:00
#include <Eigen/Dense>
2022-07-04 23:52:05 +08:00
class SigmaClip {
private:
int maxiters = 5;
double sigma = 3, minValue = INF, maxValue = -INF;
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr;
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr;
2022-07-04 23:52:05 +08:00
public:
SigmaClip(double sigma = 3, int maxiters = 5,
double (*cenF)(std::vector<Eigen::Vector2d> data) = nullptr,
double (*stdF)(std::vector<Eigen::Vector2d> data) = nullptr);
~SigmaClip() {};
std::vector<Eigen::Vector2d> clip(std::vector<Eigen::Vector2d> data);
std::vector<Eigen::Vector2d> clipN(std::vector<Eigen::Vector2d> data);
2022-07-04 23:52:05 +08:00
private:
void computeBound(std::vector<Eigen::Vector2d> data);
2022-07-04 23:52:05 +08:00
};
SigmaClip::SigmaClip(double sigma_, int maxiters_,
double (*cenF_)(std::vector<Eigen::Vector2d> data),
double (*stdF_)(std::vector<Eigen::Vector2d> data)) {
sigma = sigma_;
maxiters = maxiters_;
cenF = cenF_ == nullptr ? dataAvg2D : cenF_;
stdF = stdF_ == nullptr ? dataStd2D : stdF_;
2022-07-04 23:52:05 +08:00
}
void SigmaClip::computeBound(std::vector<Eigen::Vector2d> data) {
double std = (*stdF)(data);
double mean = (*cenF)(data);
2022-07-04 23:52:05 +08:00
minValue = mean - (std * sigma);
maxValue = mean + (std * sigma);
}
std::vector<Eigen::Vector2d> SigmaClip::clip(std::vector<Eigen::Vector2d> data) {
std::vector<Eigen::Vector2d>::iterator itor;
minValue = INF, maxValue = -INF;
for (int k = 1; k <= maxiters; k++) {
computeBound(data);
for (itor = data.begin(); itor != data.end();) {
if ((*itor)(0) < minValue || (*itor)(0) > maxValue)
data.erase(itor);
else
itor++;
}
2022-07-04 23:52:05 +08:00
}
return data;
2022-07-04 23:52:05 +08:00
}
#endif