diff options
author | JinweiClarkChao <[email protected]> | 2015-08-24 10:15:00 +0800 |
---|---|---|
committer | JinweiClarkChao <[email protected]> | 2015-08-24 10:15:00 +0800 |
commit | 17fbf4355747b1ceb9caca120aec9830a44621cf (patch) | |
tree | 6ec188fe59b0ae8c65a812765ef8f621ecf87ec3 /DCP/darkchannel.cpp | |
download | Dehaze-17fbf4355747b1ceb9caca120aec9830a44621cf.tar.gz |
init
Diffstat (limited to 'DCP/darkchannel.cpp')
-rw-r--r-- | DCP/darkchannel.cpp | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/DCP/darkchannel.cpp b/DCP/darkchannel.cpp new file mode 100644 index 0000000..a6cd530 --- /dev/null +++ b/DCP/darkchannel.cpp | |||
@@ -0,0 +1,51 @@ | |||
1 | #include "dcp_core.h" | ||
2 | |||
3 | static inline int minbgr(int b, int g, int r) | ||
4 | { | ||
5 | b = b > g ? g : b; | ||
6 | b = b > r ? r : b; | ||
7 | return b; | ||
8 | } | ||
9 | |||
10 | void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius) | ||
11 | { | ||
12 | int height = input->height; | ||
13 | int width = input->width; | ||
14 | int widthstep = input->widthStep; | ||
15 | int gwidthstep = darkchannel->widthStep; | ||
16 | int nch = input->nChannels; | ||
17 | |||
18 | int st_row, ed_row; | ||
19 | int st_col, ed_col; | ||
20 | |||
21 | for (int i = 1; i <= height; i++) | ||
22 | { | ||
23 | for (int j = 1; j <= width; j++) | ||
24 | { | ||
25 | st_row = i - radius, ed_row = i + radius; | ||
26 | st_col = j - radius, ed_col = j + radius; | ||
27 | |||
28 | if (st_row <= 0) | ||
29 | st_row = 1; | ||
30 | if (ed_row > height) | ||
31 | ed_row = height; | ||
32 | if (st_col <= 0) | ||
33 | st_col = 1; | ||
34 | if (ed_col > width) | ||
35 | ed_col = width; | ||
36 | |||
37 | int min = 0; | ||
38 | int tmp[3]; | ||
39 | for (int m = st_row; m <= ed_row; m++) | ||
40 | { | ||
41 | for (int n = st_col; n <= ed_col; n++) | ||
42 | { | ||
43 | for (int k = 0; k < 3; k++) | ||
44 | tmp[k] = *(uchar *)(input->imageData + (i - 1) * widthstep + (j - 1) * nch + k); | ||
45 | min = minbgr(tmp[0], tmp[1], tmp[2]); | ||
46 | } | ||
47 | } | ||
48 | *(uchar *)(darkchannel->imageData + (i - 1) * gwidthstep + (j - 1)) = min; | ||
49 | } | ||
50 | } | ||
51 | } | ||