forked from yearway/CDE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCDE.h
90 lines (70 loc) · 2.13 KB
/
CDE.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//
// CDE.h
// Channel Division based Enhancement
//
// Created by yearway ([email protected]) on 2/5/15.
//
#ifndef __CDE__
#define __CDE__
#include <iostream>
#include <opencv2/core/core.hpp>
#define __CDE_DEBUG__
typedef unsigned char Intensity;
const Intensity kMaxIntensity = (Intensity)255;
typedef cv::Vec<int, (int)kMaxIntensity+1> CDE_Vec_i;
typedef cv::Vec<float, (int)kMaxIntensity+1> CDE_Vec_f;
class ContrastPair {
public:
ContrastPair() : low_val_(0), high_val_(0) {};
ContrastPair(Intensity v1, Intensity v2) {
low_val_ = std::min(v1, v2);
high_val_ = std::max(v1, v2);
};
~ContrastPair() {};
inline CDE_Vec_i getVector() const {
CDE_Vec_i vec = CDE_Vec_i::all(0);
for (uint k = low_val_; k <= high_val_; k++)
vec[k] = 1;
return vec;
};
inline Intensity getLow() const {
return low_val_;
};
inline Intensity getHigh() const {
return high_val_ ;
};
private:
Intensity low_val_, high_val_;
};
// Contrast Division based Enhancement
// Parameters
// - thresh: threshold for the contrast pairs. (Default 10)
// - weight: controls how much of the transformation is used, rest comes from identity. Bigger values gives brighter results.
// - sigmas: [drk mdl sat] sigmas values for each channel. (Default [3 1 1/2])
// - bounds: [d s] thresholds for the different regions. (Default [1/3 2/3])
class CDE {
public:
static const ContrastPair noneContrast;
CDE() :
thresh_(10),
weight_(.8f),
sigmas_(cv::Vec3f(3.f, 1.f, .5f)),
bounds_(cv::Vec2f(1.f/3, 2.f/3))
{};
CDE(int thresh, int val, int step, float weight_t, cv::Vec3f sigmas, cv::Vec2f bounds) :
thresh_(thresh),
weight_(weight_t),
sigmas_(sigmas),
bounds_(bounds)
{};
void enhance(const cv::Mat &in_img, cv::Mat &out_img);
private:
int thresh_;
float weight_;
cv::Vec3f sigmas_;
cv::Vec2f bounds_;
inline bool isEdgeContrastPair(const ContrastPair *p) {
return static_cast<int>(p->getHigh() - p->getLow()) >= thresh_;
};
};
#endif /* defined(__CDE__) */