From 17fbf4355747b1ceb9caca120aec9830a44621cf Mon Sep 17 00:00:00 2001 From: JinweiClarkChao Date: Mon, 24 Aug 2015 10:15:00 +0800 Subject: init --- .gitignore | 202 ++++++++++++++++++++++++++++++++++++++++++++++++ DCP.sln | 22 ++++++ DCP/DCP.vcxproj | 107 +++++++++++++++++++++++++ DCP/DCP.vcxproj.filters | 48 ++++++++++++ DCP/airlight.cpp | 97 +++++++++++++++++++++++ DCP/darkchannel.cpp | 51 ++++++++++++ DCP/dcp.cpp | 18 +++++ DCP/dcp.h | 8 ++ DCP/dcp_core.h | 9 +++ DCP/guidedfilter.cpp | 195 ++++++++++++++++++++++++++++++++++++++++++++++ DCP/packages.config | 4 + DCP/recover.cpp | 36 +++++++++ DCP/transmission.cpp | 51 ++++++++++++ 13 files changed, 848 insertions(+) create mode 100644 .gitignore create mode 100644 DCP.sln create mode 100644 DCP/DCP.vcxproj create mode 100644 DCP/DCP.vcxproj.filters create mode 100644 DCP/airlight.cpp create mode 100644 DCP/darkchannel.cpp create mode 100644 DCP/dcp.cpp create mode 100644 DCP/dcp.h create mode 100644 DCP/dcp_core.h create mode 100644 DCP/guidedfilter.cpp create mode 100644 DCP/packages.config create mode 100644 DCP/recover.cpp create mode 100644 DCP/transmission.cpp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1a38ed --- /dev/null +++ b/.gitignore @@ -0,0 +1,202 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +*.jpeg +*.jpg +*.bmp +*.png + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# User-specific files (MonoDevelop/Xamarin Studio) +*.userprefs + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Visual Studo 2015 cache/options directory +.vs/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +# NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +# TODO: Comment the next line if you want to checkin your web deploy settings +# but database connection strings (with potential passwords) will be unencrypted +*.pubxml +*.publishproj + +# NuGet Packages +*.nupkg +# The packages folder can be ignored because of Package Restore +**/packages/* +# except build/, which is used as an MSBuild target. +!**/packages/build/ +# Uncomment if necessary however generally it will be regenerated when needed +#!**/packages/repositories.config + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +*.[Cc]ache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ +bower_components/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# Node.js Tools for Visual Studio +.ntvs_analysis.dat + +# Visual Studio 6 build log +*.plg + +# Visual Studio 6 workspace options file +*.opt + diff --git a/DCP.sln b/DCP.sln new file mode 100644 index 0000000..e23dbd2 --- /dev/null +++ b/DCP.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.40629.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DCP", "DCP\DCP.vcxproj", "{1543533F-481B-40EC-BEFC-90E46456A5F8}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Win32 = Debug|Win32 + Release|Win32 = Release|Win32 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.ActiveCfg = Debug|Win32 + {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.Build.0 = Debug|Win32 + {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.ActiveCfg = Release|Win32 + {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.Build.0 = Release|Win32 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/DCP/DCP.vcxproj b/DCP/DCP.vcxproj new file mode 100644 index 0000000..eba571d --- /dev/null +++ b/DCP/DCP.vcxproj @@ -0,0 +1,107 @@ + + + + + + Debug + Win32 + + + Release + Win32 + + + + {1543533F-481B-40EC-BEFC-90E46456A5F8} + Win32Proj + DCP + + + + Application + true + v120 + Unicode + + + Application + false + v120 + true + Unicode + + + + + + + + + + + + f521f52d + + + true + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions) + + + Console + true + true + true + + + + + + + + + + + + + + + + + + + + + + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + + + \ No newline at end of file diff --git a/DCP/DCP.vcxproj.filters b/DCP/DCP.vcxproj.filters new file mode 100644 index 0000000..b301b89 --- /dev/null +++ b/DCP/DCP.vcxproj.filters @@ -0,0 +1,48 @@ + + + + + {4FC737F1-C7A5-4376-A066-2A32D752A2FF} + cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx + + + {93995380-89BD-4b04-88EB-625FBE52EBFB} + h;hh;hpp;hxx;hm;inl;inc;xsd + + + {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} + rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms + + + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + Source Files + + + + + + + + Header Files + + + Header Files + + + \ No newline at end of file diff --git a/DCP/airlight.cpp b/DCP/airlight.cpp new file mode 100644 index 0000000..c6df18f --- /dev/null +++ b/DCP/airlight.cpp @@ -0,0 +1,97 @@ +#include "dcp_core.h" + +void Estimate_A(IplImage *DarkChannel, IplImage *InputImage, struct Max_Pixel_Selector *MaxPixel, double A[]) +{ + double num = height * width * 0.001; + double num1per = num * 0.01; //num1per is the number of 1 percent of top 0.1 pixels + //k is the index of the color channel + int k = 0; + int patchsize; + int dark_i, dark_j; + uchar Max = 0; + + IplImage *mask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); + cvZero(mask); + + int e = 0, i, j; + for (i = 1; i <= height; i++) + { + for (j = 1; j <= width; j++) + { + MaxPixel[e].Pixel = *(uchar *)(DarkChannel->imageData + (i - 1) * gwidthstep + (j - 1)); + MaxPixel[e].i = i; + MaxPixel[e].j = j; + e++; + } + } + sort(MaxPixel, MaxPixel + e, comp1); + + for (i = 0; i < num; i++) + { + dark_i = MaxPixel[i].i; + dark_j = MaxPixel[i].j; + *(uchar *)(mask->imageData + (dark_i - 1) * gwidthstep + (dark_j - 1)) = 255; + //Ö»Óе±mask±ê¼ÇΪ255Ö®ºó£¬²Å˵Ã÷¸Ã¿éÇøÓòÁÁ¶ÈÖµÊÇÔÚ°µÍ¨µÀµÄÇ°0.1%Ö®ÄÚµÄ + } + + if (num1per < 9) + patchsize = 3; + else + patchsize = sqrt(num1per); + + for (k = 0; k < 3; k++) + { + int e, x, y; + int tmp = (patchsize - 1) / 2; + int st_row, ed_row; + int st_col, ed_col; + + double A_tmp = 0; + double aver = 0; // aver Ϊָ¶¨´óСpatchÄÚInputImageÖµµÄƽ¾ùÖµ + int flag; //flagÓÃÀ´»ñÈ¡maskµÄ±ê¼Ç + + for (i = 1; i <= num; i++) + { + aver = 0; + dark_i = MaxPixel[i].i; + dark_j = MaxPixel[i].j; + + st_row = dark_i - tmp, ed_row = dark_i + tmp; + st_col = dark_j - tmp, ed_col = dark_j + tmp; + + 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; + + e = 0; + for (x = st_row; x <= ed_row; x++) + { + for (y = st_col; y <= ed_col; y++) + { + flag = *(uchar *)(mask->imageData + (x - 1) * gwidthstep + (y - 1)); + if (flag == 0) //δ±»±ê¼Ç˵Ã÷¸Ãµã²»ÔÚÇ°0.1%¶ÔÓ¦µÄÇøÓòÄÚ£¬Ìø¹ý + { + continue; + } + else + { + aver += *(uchar *)(InputImage->imageData + (x - 1) * widthstep + (y - 1) *nch + k); + e++; + } + } + } + aver /= e; + if (A_tmp < aver) + { + A_tmp = aver; + } + } + A[k] = A_tmp / 255.0; + } + cvReleaseImage(&mask); +} \ No newline at end of file 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 @@ +#include "dcp_core.h" + +static inline int minbgr(int b, int g, int r) +{ + b = b > g ? g : b; + b = b > r ? r : b; + return b; +} + +void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius) +{ + int height = input->height; + int width = input->width; + int widthstep = input->widthStep; + int gwidthstep = darkchannel->widthStep; + int nch = input->nChannels; + + int st_row, ed_row; + int st_col, ed_col; + + for (int i = 1; i <= height; i++) + { + for (int j = 1; 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; + + 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]); + } + } + *(uchar *)(darkchannel->imageData + (i - 1) * gwidthstep + (j - 1)) = min; + } + } +} diff --git a/DCP/dcp.cpp b/DCP/dcp.cpp new file mode 100644 index 0000000..df4aad9 --- /dev/null +++ b/DCP/dcp.cpp @@ -0,0 +1,18 @@ +#include "dcp.h" + +void dehaze(IplImage *recover, IplImage *input) +{ + int height = input->height; + int width = input->width; + + IplImage *darkchannel = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); + IplImage *transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); + IplImage *refine_transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); + + int darkchannelradius = MIN(width, height) * 0.02; + + CalcDarkChannel(darkchannel, input, darkchannelradius); + + + +} diff --git a/DCP/dcp.h b/DCP/dcp.h new file mode 100644 index 0000000..00c7e53 --- /dev/null +++ b/DCP/dcp.h @@ -0,0 +1,8 @@ +#ifndef DCP_H +#define DCP_H + +#include "dcp_core.h" + +void dehaze(IplImage *recover, IplImage *input); + +#endif \ No newline at end of file diff --git a/DCP/dcp_core.h b/DCP/dcp_core.h new file mode 100644 index 0000000..3fb8c7c --- /dev/null +++ b/DCP/dcp_core.h @@ -0,0 +1,9 @@ +#ifndef DCP_CORE_H +#define DCP_CORE_H + +#include +#include + +void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius); + +#endif \ No newline at end of file diff --git a/DCP/guidedfilter.cpp b/DCP/guidedfilter.cpp new file mode 100644 index 0000000..46040ad --- /dev/null +++ b/DCP/guidedfilter.cpp @@ -0,0 +1,195 @@ +#include "dcp_core.h" + +#include +#include + +using namespace std; + +void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r) +{ + int height = q->height; + int width = q->width; + int widthstep = II->widthStep; + int gwidthstep = p->widthStep; + int nch = II->nChannels; + + int i, j; + int m, n; + int w; + int e = 0; + int st_row, ed_row; + int st_col, ed_col; + + double sum_Ir, sum_Ig, sum_Ib; + double sum_Ir_square, sum_Ig_square, sum_Ib_square; + double sum_IrIg, sum_IgIb, sum_IrIb; + double sum_PiIr, sum_PiIg, sum_PiIb; + double sum_Pi; + + double A, B, C, D, E, F, G, H, I, J, K, L; + double X, Y, Z; + double ak_r, ak_g, ak_b; + double bk; + double det; + + double tmp_Ir, tmp_Ig, tmp_Ib; + double tmp_p, tmp_q; + + vector v_ak_r; + vector v_ak_g; + vector v_ak_b; + vector v_bk; + + for (i = 1; i <= height; i++) + { + if (i % 10 == 0) + printf("%d\n", i); + + for (j = 1; j <= width; j++) + { + st_row = i - r, ed_row = i + r; + st_col = j - r, ed_col = j + r; + + 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; + + sum_Ir = sum_Ig = sum_Ib = 0; + sum_Ir_square = sum_Ig_square = sum_Ib_square = 0; + sum_IrIg = sum_IgIb = sum_IrIb = 0; + sum_PiIr = sum_PiIg = sum_PiIb = 0; + sum_Pi = 0; + w = 0; + + for (m = st_row; m <= ed_row; m++) + { + for (n = st_col; n <= ed_col; n++) + { + tmp_Ib = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch); + tmp_Ig = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 1); + tmp_Ir = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 2); + + tmp_p = *(uchar *)(p->imageData + (m - 1) * gwidthstep + (n - 1)); + + sum_Ib += tmp_Ib; + sum_Ig += tmp_Ig; + sum_Ir += tmp_Ir; + + sum_Ib_square += tmp_Ib * tmp_Ib; + sum_Ig_square += tmp_Ig * tmp_Ig; + sum_Ir_square += tmp_Ir * tmp_Ir; + + sum_IrIg += tmp_Ir * tmp_Ig; + sum_IgIb += tmp_Ig * tmp_Ib; + sum_IrIb += tmp_Ir * tmp_Ib; + + sum_Pi += tmp_p; + sum_PiIb += tmp_p * tmp_Ib; + sum_PiIg += tmp_p * tmp_Ig; + sum_PiIr += tmp_p * tmp_Ir; + + w++; + } + } + + A = (sum_Ir_square + w * eps) * sum_Ig - sum_Ir * sum_IrIg; + B = sum_IrIg * sum_Ig - sum_Ir * (sum_Ig_square + w * eps); + C = sum_IrIb * sum_Ig - sum_Ir * sum_IgIb; + D = sum_PiIr * sum_Ig - sum_PiIg * sum_Ir; + E = (sum_Ir_square + w * eps) * sum_Ib - sum_IrIb * sum_Ir; + F = sum_IrIg * sum_Ib - sum_IgIb * sum_Ir; + G = sum_IrIb * sum_Ib - (sum_Ib_square + w * eps) * sum_Ir; + H = sum_PiIr * sum_Ib - sum_PiIb * sum_Ir; + I = (sum_Ir_square + w * eps) * w - sum_Ir * sum_Ir; + J = sum_IrIg * w - sum_Ig * sum_Ir; + K = sum_IrIb * w - sum_Ib * sum_Ir; + L = sum_PiIr * w - sum_Pi * sum_Ir; + + det = A * F * K + B * G * I + C * E * J - C * F * I - A * G * J - B * E * K; + X = D * F * K + B * G * L + C * H * J - C * F * L - D * G * J - B * H * K; + Y = A * H * K + D * G * I + C * E * L - C * H * I - D * E * K - A * G * L; + Z = A * F * L + B * H * I + D * J * E - D * F * I - B * E * L - A * H * J; + + ak_r = X / det; + ak_g = Y / det; + ak_b = Z / det; + + bk = (sum_PiIg - sum_IrIg * ak_r - (sum_Ig_square + w * eps) * ak_g - sum_IgIb * ak_b) / sum_Ig; + + tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch); + tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1); + tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2); + + tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk; + + if (tmp_q > 255) + tmp_q = 255; + else if (tmp_q < 0) + tmp_q = 0; + + *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q; + + v_ak_b.push_back(ak_b); + v_ak_g.push_back(ak_g); + v_ak_r.push_back(ak_r); + v_bk.push_back(bk); + } + } + + for (int i = 1; i <= height; i++) + { + for (int j = 1; j <= width; j++) + { + st_row = i - r, ed_row = i + r; + st_col = j - r, ed_col = j + r; + + 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; + + double ak_r, ak_g, ak_b, bk; + ak_r = ak_g = ak_b = bk = 0; + + int number = 0; + for (int m = st_row; m <= ed_row; m++) + { + for (int n = st_col; n <= ed_col; n++) + { + ak_r += v_ak_r[(m - 1) * width + n - 1]; + ak_g += v_ak_g[(m - 1) * width + n - 1]; + ak_b += v_ak_b[(m - 1) * width + n - 1]; + bk += v_bk[(m - 1) * width + n - 1]; + number++; + } + } + + ak_r /= number; + ak_g /= number; + ak_b /= number; + bk /= number; + + tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch); + tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1); + tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2); + + tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk; + + if (tmp_q > 255) + tmp_q = 255; + else if (tmp_q < 0) + tmp_q = 0; + + *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q; + } + } +} diff --git a/DCP/packages.config b/DCP/packages.config new file mode 100644 index 0000000..b2057a2 --- /dev/null +++ b/DCP/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/DCP/recover.cpp b/DCP/recover.cpp new file mode 100644 index 0000000..a99b0f2 --- /dev/null +++ b/DCP/recover.cpp @@ -0,0 +1,36 @@ +#include "dcp_core.h" + +void Recover(IplImage *Result, IplImage *InputImage, double A[]) +{ + double t0 = 0.1; + double t, tmp_res; + + int i, j, k; + int e = 0, number = 0; + double a = 0; + + for (i = 1; i <= height; i++) + { + for (j = 1; j <= width; j++) + { + t = real_trans[e++]; + t /= 255.0; + for (k = 0; k < 3; k++) + { + a = *(uchar *)(InputImage->imageData + (i - 1) * widthstep + (j - 1) * nch + k); + a /= 255; + + tmp_res = ((a - A[k]) / MaxTwo(t, t0)) + A[k]; + + real_recover[number++] = tmp_res; + + if (tmp_res > 1) + tmp_res = 1; + else if (tmp_res < 0) + tmp_res = 0; + + *(uchar *)(Result->imageData + (i - 1) * widthstep + (j - 1) * nch + k) = tmp_res * 255.0; + } + } + } +} \ No newline at end of file diff --git a/DCP/transmission.cpp b/DCP/transmission.cpp new file mode 100644 index 0000000..5bb2ece --- /dev/null +++ b/DCP/transmission.cpp @@ -0,0 +1,51 @@ +#include "dcp_core.h" + +void Estimate_transmission(IplImage *Transmission_maps, IplImage *InputImage, double A[], double heap[], double real_trans[]) +{ + double w = 0.95; + double tmp; + double tran; + int i, j, k; + int e = 0; + + IplImage *tmp_Trans = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3); + + for (k = 0; k < 3; k++) + { + for (i = 1; i <= height; i++) + { + for (j = 1; j <= width; j++) + { + tmp = *(uchar *)(InputImage->imageData + (i - 1) * widthstep + (j - 1) * nch + k); + tmp /= A[k]; + + if (tmp > 255) + tmp = 255; + *(uchar *)(tmp_Trans->imageData + (i - 1) * widthstep + (j - 1) * nch + k) = tmp; + } + } + } + Cal_DarkChannel(Transmission_maps, tmp_Trans, nInteger, heap); + + for (i = 1; i <= height; i++) + { + for (j = 1; j <= width; j++) + { + tran = *(uchar *)(Transmission_maps->imageData + (i - 1) * gwidthstep + (j - 1)); + + tran /= 255.0; + tran = 1 - w * tran; + + real_trans[e++] = tran * 255.0; + + if (tran > 1) + tran = 1; + else if (tran < 0) + tran = 0; + + *(uchar *)(Transmission_maps->imageData + (i - 1) * gwidthstep + (j - 1)) = tran * 255; + } + } + //cvSaveImage("Estimated-Trans.bmp", Transmission_maps); + cvReleaseImage(&tmp_Trans); +} -- cgit v1.2.3