-
Notifications
You must be signed in to change notification settings - Fork 13
/
remapping_function.h
71 lines (57 loc) · 1.88 KB
/
remapping_function.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// File Description
// Author: Philip Salvaggio
#ifndef REMAPPING_FUNCTION_H
#define REMAPPING_FUNCTION_H
#include <opencv2/opencv.hpp>
#include <cmath>
class RemappingFunction {
public:
RemappingFunction(double alpha, double beta);
~RemappingFunction();
double alpha() const { return alpha_; }
void set_alpha(double alpha) { alpha_ = alpha; }
double beta() const { return beta_; }
void set_beta(double beta) { beta_ = beta; }
void Evaluate(double value,
double reference,
double sigma_r,
double& output);
void Evaluate(const cv::Vec3d& value,
const cv::Vec3d& reference,
double sigma_r,
cv::Vec3d& output);
template<typename T>
void Evaluate(const cv::Mat& input, cv::Mat& output,
const T& reference, double sigma_r);
private:
double DetailRemap(double delta, double sigma_r);
double EdgeRemap(double delta);
double SmoothStep(double x_min, double x_max, double x);
private:
double alpha_, beta_;
};
inline double RemappingFunction::DetailRemap(double delta, double sigma_r) {
double fraction = delta / sigma_r;
double polynomial = pow(fraction, alpha_);
if (alpha_ < 1) {
const double kNoiseLevel = 0.01;
double blend = SmoothStep(kNoiseLevel,
2 * kNoiseLevel, fraction * sigma_r);
polynomial = blend * polynomial + (1 - blend) * fraction;
}
return polynomial;
}
inline double RemappingFunction::EdgeRemap(double delta) {
return beta_ * delta;
}
template<typename T>
void RemappingFunction::Evaluate(const cv::Mat& input, cv::Mat& output,
const T& reference, double sigma_r) {
output.create(input.rows, input.cols, input.type());
for (int i = 0; i < input.rows; i++) {
for (int j = 0; j < input.cols; j++) {
Evaluate(input.at<T>(i, j), reference, sigma_r, output.at<T>(i, j));
}
}
}
#endif // REMAPPING_FUNCTION_H