diff options
author | JinweiClarkChao <[email protected]> | 2015-08-25 12:27:20 +0800 |
---|---|---|
committer | JinweiClarkChao <[email protected]> | 2015-08-25 16:49:49 +0800 |
commit | f07885c1eb4c98dc52704517623b2e7df1ed616d (patch) | |
tree | acc14792523ff5bbb464882e548b96752c2d6886 /DCP/darkchannel.cpp | |
parent | de74f5fa499b82390bce432251609d18d9ce5fd8 (diff) | |
download | Dehaze-f07885c1eb4c98dc52704517623b2e7df1ed616d.tar.gz |
initial complete
Diffstat (limited to 'DCP/darkchannel.cpp')
-rw-r--r-- | DCP/darkchannel.cpp | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/DCP/darkchannel.cpp b/DCP/darkchannel.cpp index a6cd530..ab5a365 100644 --- a/DCP/darkchannel.cpp +++ b/DCP/darkchannel.cpp | |||
@@ -18,34 +18,38 @@ void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius) | |||
18 | int st_row, ed_row; | 18 | int st_row, ed_row; |
19 | int st_col, ed_col; | 19 | int st_col, ed_col; |
20 | 20 | ||
21 | for (int i = 1; i <= height; i++) | 21 | for (int i = 0; i < height; i++) |
22 | { | 22 | { |
23 | for (int j = 1; j <= width; j++) | 23 | for (int j = 0; j < width; j++) |
24 | { | 24 | { |
25 | st_row = i - radius, ed_row = i + radius; | 25 | st_row = i - radius, ed_row = i + radius; |
26 | st_col = j - radius, ed_col = j + radius; | 26 | st_col = j - radius, ed_col = j + radius; |
27 | 27 | ||
28 | if (st_row <= 0) | 28 | if (st_row < 0) |
29 | st_row = 1; | 29 | st_row = 0; |
30 | if (ed_row > height) | 30 | if (ed_row >= height) |
31 | ed_row = height; | 31 | ed_row = height - 1; |
32 | if (st_col <= 0) | 32 | if (st_col < 0) |
33 | st_col = 1; | 33 | st_col = 0; |
34 | if (ed_col > width) | 34 | if (ed_col >= width) |
35 | ed_col = width; | 35 | ed_col = width - 1; |
36 | |||
37 | int cur = 0; | ||
38 | int min = 300; | ||
36 | 39 | ||
37 | int min = 0; | ||
38 | int tmp[3]; | ||
39 | for (int m = st_row; m <= ed_row; m++) | 40 | for (int m = st_row; m <= ed_row; m++) |
40 | { | 41 | { |
41 | for (int n = st_col; n <= ed_col; n++) | 42 | for (int n = st_col; n <= ed_col; n++) |
42 | { | 43 | { |
43 | for (int k = 0; k < 3; k++) | 44 | for (int k = 0; k < 3; k++) |
44 | tmp[k] = *(uchar *)(input->imageData + (i - 1) * widthstep + (j - 1) * nch + k); | 45 | { |
45 | min = minbgr(tmp[0], tmp[1], tmp[2]); | 46 | cur = *(uchar *)(input->imageData + m * widthstep + n * nch + k); |
47 | if (cur < min) | ||
48 | min = cur; | ||
49 | } | ||
46 | } | 50 | } |
47 | } | 51 | } |
48 | *(uchar *)(darkchannel->imageData + (i - 1) * gwidthstep + (j - 1)) = min; | 52 | *(uchar *)(darkchannel->imageData + i * gwidthstep + j) = min; |
49 | } | 53 | } |
50 | } | 54 | } |
51 | } | 55 | } |