From f07885c1eb4c98dc52704517623b2e7df1ed616d Mon Sep 17 00:00:00 2001 From: JinweiClarkChao Date: Tue, 25 Aug 2015 12:27:20 +0800 Subject: initial complete --- DCP/darkchannel.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) (limited to 'DCP/darkchannel.cpp') 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) int st_row, ed_row; int st_col, ed_col; - for (int i = 1; i <= height; i++) + for (int i = 0; i < height; i++) { - for (int j = 1; j <= width; j++) + for (int j = 0; j < width; j++) { st_row = i - radius, ed_row = i + radius; st_col = j - radius, ed_col = j + radius; - if (st_row <= 0) - st_row = 1; - if (ed_row > height) - ed_row = height; - if (st_col <= 0) - st_col = 1; - if (ed_col > width) - ed_col = width; + if (st_row < 0) + st_row = 0; + if (ed_row >= height) + ed_row = height - 1; + if (st_col < 0) + st_col = 0; + if (ed_col >= width) + ed_col = width - 1; + + int cur = 0; + int min = 300; - int min = 0; - int tmp[3]; for (int m = st_row; m <= ed_row; m++) { for (int n = st_col; n <= ed_col; n++) { for (int k = 0; k < 3; k++) - tmp[k] = *(uchar *)(input->imageData + (i - 1) * widthstep + (j - 1) * nch + k); - min = minbgr(tmp[0], tmp[1], tmp[2]); + { + cur = *(uchar *)(input->imageData + m * widthstep + n * nch + k); + if (cur < min) + min = cur; + } } } - *(uchar *)(darkchannel->imageData + (i - 1) * gwidthstep + (j - 1)) = min; + *(uchar *)(darkchannel->imageData + i * gwidthstep + j) = min; } } } -- cgit v1.2.3