-
Notifications
You must be signed in to change notification settings - Fork 282
/
Local Color Correction.cpp
37 lines (37 loc) · 1.13 KB
/
Local Color Correction.cpp
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
Mat LCC(const Mat &src){
int rows = src.rows;
int cols = src.cols;
int **I;
I = new int *[rows];
for(int i = 0; i < rows; i++){
I[i] = new int [cols];
}
int **inv_I;
inv_I = new int *[rows];
for(int i = 0; i < rows; i++){
inv_I[i] = new int [cols];
}
Mat Mast(rows, cols, CV_8UC1);
for(int i = 0; i < rows; i++){
uchar *data = Mast.ptr<uchar>(i);
for(int j = 0; j < cols; j++){
I[i][j] = (src.at<Vec3b>(i, j)[0] + src.at<Vec3b>(i, j)[1] + src.at<Vec3b>(i, j)[1]) / 3.0;
inv_I[i][j] = 255;
*data = inv_I[i][j] - I[i][j];
data++;
}
}
GaussianBlur(Mast, Mast, Size(41, 41), BORDER_DEFAULT);
Mat dst(rows, cols, CV_8UC3);
for(int i = 0; i < rows; i++){
uchar *data = Mast.ptr<uchar>(i);
for(int j = 0; j < cols; j++){
for(int k = 0; k < 3; k++){
float Exp = pow(2, (128 - data[j]) / 128.0);
int value = int(255 * pow(src.at<Vec3b>(i, j)[k] / 255.0, Exp));
dst.at<Vec3b>(i, j)[k] = value;
}
}
}
return dst;
}