aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinweiClarkChao <[email protected]>2015-08-24 10:15:00 +0800
committerJinweiClarkChao <[email protected]>2015-08-24 10:15:00 +0800
commit17fbf4355747b1ceb9caca120aec9830a44621cf (patch)
tree6ec188fe59b0ae8c65a812765ef8f621ecf87ec3
downloadDehaze-17fbf4355747b1ceb9caca120aec9830a44621cf.tar.gz
init
-rw-r--r--.gitignore202
-rw-r--r--DCP.sln22
-rw-r--r--DCP/DCP.vcxproj107
-rw-r--r--DCP/DCP.vcxproj.filters48
-rw-r--r--DCP/airlight.cpp97
-rw-r--r--DCP/darkchannel.cpp51
-rw-r--r--DCP/dcp.cpp18
-rw-r--r--DCP/dcp.h8
-rw-r--r--DCP/dcp_core.h9
-rw-r--r--DCP/guidedfilter.cpp195
-rw-r--r--DCP/packages.config4
-rw-r--r--DCP/recover.cpp36
-rw-r--r--DCP/transmission.cpp51
13 files changed, 848 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..c1a38ed
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,202 @@
1## Ignore Visual Studio temporary files, build results, and
2## files generated by popular Visual Studio add-ons.
3
4*.jpeg
5*.jpg
6*.bmp
7*.png
8
9# User-specific files
10*.suo
11*.user
12*.userosscache
13*.sln.docstates
14
15# User-specific files (MonoDevelop/Xamarin Studio)
16*.userprefs
17
18# Build results
19[Dd]ebug/
20[Dd]ebugPublic/
21[Rr]elease/
22[Rr]eleases/
23x64/
24x86/
25build/
26bld/
27[Bb]in/
28[Oo]bj/
29
30# Visual Studo 2015 cache/options directory
31.vs/
32
33# MSTest test Results
34[Tt]est[Rr]esult*/
35[Bb]uild[Ll]og.*
36
37# NUNIT
38*.VisualState.xml
39TestResult.xml
40
41# Build Results of an ATL Project
42[Dd]ebugPS/
43[Rr]eleasePS/
44dlldata.c
45
46*_i.c
47*_p.c
48*_i.h
49*.ilk
50*.meta
51*.obj
52*.pch
53*.pdb
54*.pgc
55*.pgd
56*.rsp
57*.sbr
58*.tlb
59*.tli
60*.tlh
61*.tmp
62*.tmp_proj
63*.log
64*.vspscc
65*.vssscc
66.builds
67*.pidb
68*.svclog
69*.scc
70
71# Chutzpah Test files
72_Chutzpah*
73
74# Visual C++ cache files
75ipch/
76*.aps
77*.ncb
78*.opensdf
79*.sdf
80*.cachefile
81
82# Visual Studio profiler
83*.psess
84*.vsp
85*.vspx
86
87# TFS 2012 Local Workspace
88$tf/
89
90# Guidance Automation Toolkit
91*.gpState
92
93# ReSharper is a .NET coding add-in
94_ReSharper*/
95*.[Rr]e[Ss]harper
96*.DotSettings.user
97
98# JustCode is a .NET coding addin-in
99.JustCode
100
101# TeamCity is a build add-in
102_TeamCity*
103
104# DotCover is a Code Coverage Tool
105*.dotCover
106
107# NCrunch
108_NCrunch_*
109.*crunch*.local.xml
110
111# MightyMoose
112*.mm.*
113AutoTest.Net/
114
115# Web workbench (sass)
116.sass-cache/
117
118# Installshield output folder
119[Ee]xpress/
120
121# DocProject is a documentation generator add-in
122DocProject/buildhelp/
123DocProject/Help/*.HxT
124DocProject/Help/*.HxC
125DocProject/Help/*.hhc
126DocProject/Help/*.hhk
127DocProject/Help/*.hhp
128DocProject/Help/Html2
129DocProject/Help/html
130
131# Click-Once directory
132publish/
133
134# Publish Web Output
135*.[Pp]ublish.xml
136*.azurePubxml
137# TODO: Comment the next line if you want to checkin your web deploy settings
138# but database connection strings (with potential passwords) will be unencrypted
139*.pubxml
140*.publishproj
141
142# NuGet Packages
143*.nupkg
144# The packages folder can be ignored because of Package Restore
145**/packages/*
146# except build/, which is used as an MSBuild target.
147!**/packages/build/
148# Uncomment if necessary however generally it will be regenerated when needed
149#!**/packages/repositories.config
150
151# Windows Azure Build Output
152csx/
153*.build.csdef
154
155# Windows Store app package directory
156AppPackages/
157
158# Others
159*.[Cc]ache
160ClientBin/
161[Ss]tyle[Cc]op.*
162~$*
163*~
164*.dbmdl
165*.dbproj.schemaview
166*.pfx
167*.publishsettings
168node_modules/
169bower_components/
170
171# RIA/Silverlight projects
172Generated_Code/
173
174# Backup & report files from converting an old project file
175# to a newer Visual Studio version. Backup files are not needed,
176# because we have git ;-)
177_UpgradeReport_Files/
178Backup*/
179UpgradeLog*.XML
180UpgradeLog*.htm
181
182# SQL Server files
183*.mdf
184*.ldf
185
186# Business Intelligence projects
187*.rdl.data
188*.bim.layout
189*.bim_*.settings
190
191# Microsoft Fakes
192FakesAssemblies/
193
194# Node.js Tools for Visual Studio
195.ntvs_analysis.dat
196
197# Visual Studio 6 build log
198*.plg
199
200# Visual Studio 6 workspace options file
201*.opt
202
diff --git a/DCP.sln b/DCP.sln
new file mode 100644
index 0000000..e23dbd2
--- /dev/null
+++ b/DCP.sln
@@ -0,0 +1,22 @@
1
2Microsoft Visual Studio Solution File, Format Version 12.00
3# Visual Studio 2013
4VisualStudioVersion = 12.0.40629.0
5MinimumVisualStudioVersion = 10.0.40219.1
6Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "DCP", "DCP\DCP.vcxproj", "{1543533F-481B-40EC-BEFC-90E46456A5F8}"
7EndProject
8Global
9 GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 Debug|Win32 = Debug|Win32
11 Release|Win32 = Release|Win32
12 EndGlobalSection
13 GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.ActiveCfg = Debug|Win32
15 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.Build.0 = Debug|Win32
16 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.ActiveCfg = Release|Win32
17 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.Build.0 = Release|Win32
18 EndGlobalSection
19 GlobalSection(SolutionProperties) = preSolution
20 HideSolutionNode = FALSE
21 EndGlobalSection
22EndGlobal
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 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <Import Project="..\packages\OpenCV.2.4.10\build\native\OpenCV.props" Condition="Exists('..\packages\OpenCV.2.4.10\build\native\OpenCV.props')" />
4 <ItemGroup Label="ProjectConfigurations">
5 <ProjectConfiguration Include="Debug|Win32">
6 <Configuration>Debug</Configuration>
7 <Platform>Win32</Platform>
8 </ProjectConfiguration>
9 <ProjectConfiguration Include="Release|Win32">
10 <Configuration>Release</Configuration>
11 <Platform>Win32</Platform>
12 </ProjectConfiguration>
13 </ItemGroup>
14 <PropertyGroup Label="Globals">
15 <ProjectGuid>{1543533F-481B-40EC-BEFC-90E46456A5F8}</ProjectGuid>
16 <Keyword>Win32Proj</Keyword>
17 <RootNamespace>DCP</RootNamespace>
18 </PropertyGroup>
19 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
20 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
21 <ConfigurationType>Application</ConfigurationType>
22 <UseDebugLibraries>true</UseDebugLibraries>
23 <PlatformToolset>v120</PlatformToolset>
24 <CharacterSet>Unicode</CharacterSet>
25 </PropertyGroup>
26 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
27 <ConfigurationType>Application</ConfigurationType>
28 <UseDebugLibraries>false</UseDebugLibraries>
29 <PlatformToolset>v120</PlatformToolset>
30 <WholeProgramOptimization>true</WholeProgramOptimization>
31 <CharacterSet>Unicode</CharacterSet>
32 </PropertyGroup>
33 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
34 <ImportGroup Label="ExtensionSettings">
35 </ImportGroup>
36 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
37 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
38 </ImportGroup>
39 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
40 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
41 </ImportGroup>
42 <PropertyGroup Label="UserMacros">
43 <NuGetPackageImportStamp>f521f52d</NuGetPackageImportStamp>
44 </PropertyGroup>
45 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
46 <LinkIncremental>true</LinkIncremental>
47 </PropertyGroup>
48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
49 <LinkIncremental>false</LinkIncremental>
50 </PropertyGroup>
51 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
52 <ClCompile>
53 <PrecompiledHeader>
54 </PrecompiledHeader>
55 <WarningLevel>Level3</WarningLevel>
56 <Optimization>Disabled</Optimization>
57 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
58 </ClCompile>
59 <Link>
60 <SubSystem>Console</SubSystem>
61 <GenerateDebugInformation>true</GenerateDebugInformation>
62 </Link>
63 </ItemDefinitionGroup>
64 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65 <ClCompile>
66 <WarningLevel>Level3</WarningLevel>
67 <PrecompiledHeader>
68 </PrecompiledHeader>
69 <Optimization>MaxSpeed</Optimization>
70 <FunctionLevelLinking>true</FunctionLevelLinking>
71 <IntrinsicFunctions>true</IntrinsicFunctions>
72 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
73 </ClCompile>
74 <Link>
75 <SubSystem>Console</SubSystem>
76 <GenerateDebugInformation>true</GenerateDebugInformation>
77 <EnableCOMDATFolding>true</EnableCOMDATFolding>
78 <OptimizeReferences>true</OptimizeReferences>
79 </Link>
80 </ItemDefinitionGroup>
81 <ItemGroup>
82 <ClInclude Include="dcp.h" />
83 <ClInclude Include="dcp_core.h" />
84 </ItemGroup>
85 <ItemGroup>
86 <ClCompile Include="airlight.cpp" />
87 <ClCompile Include="darkchannel.cpp" />
88 <ClCompile Include="dcp.cpp" />
89 <ClCompile Include="guidedfilter.cpp" />
90 <ClCompile Include="recover.cpp" />
91 <ClCompile Include="transmission.cpp" />
92 </ItemGroup>
93 <ItemGroup>
94 <None Include="packages.config" />
95 </ItemGroup>
96 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
97 <ImportGroup Label="ExtensionTargets">
98 <Import Project="..\packages\OpenCV.2.4.10\build\native\OpenCV.targets" Condition="Exists('..\packages\OpenCV.2.4.10\build\native\OpenCV.targets')" />
99 </ImportGroup>
100 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
101 <PropertyGroup>
102 <ErrorText>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}.</ErrorText>
103 </PropertyGroup>
104 <Error Condition="!Exists('..\packages\OpenCV.2.4.10\build\native\OpenCV.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCV.2.4.10\build\native\OpenCV.props'))" />
105 <Error Condition="!Exists('..\packages\OpenCV.2.4.10\build\native\OpenCV.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\OpenCV.2.4.10\build\native\OpenCV.targets'))" />
106 </Target>
107</Project> \ 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 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup>
4 <Filter Include="Source Files">
5 <UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6 <Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7 </Filter>
8 <Filter Include="Header Files">
9 <UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10 <Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11 </Filter>
12 <Filter Include="Resource Files">
13 <UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14 <Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15 </Filter>
16 </ItemGroup>
17 <ItemGroup>
18 <ClCompile Include="dcp.cpp">
19 <Filter>Source Files</Filter>
20 </ClCompile>
21 <ClCompile Include="darkchannel.cpp">
22 <Filter>Source Files</Filter>
23 </ClCompile>
24 <ClCompile Include="airlight.cpp">
25 <Filter>Source Files</Filter>
26 </ClCompile>
27 <ClCompile Include="transmission.cpp">
28 <Filter>Source Files</Filter>
29 </ClCompile>
30 <ClCompile Include="recover.cpp">
31 <Filter>Source Files</Filter>
32 </ClCompile>
33 <ClCompile Include="guidedfilter.cpp">
34 <Filter>Source Files</Filter>
35 </ClCompile>
36 </ItemGroup>
37 <ItemGroup>
38 <None Include="packages.config" />
39 </ItemGroup>
40 <ItemGroup>
41 <ClInclude Include="dcp_core.h">
42 <Filter>Header Files</Filter>
43 </ClInclude>
44 <ClInclude Include="dcp.h">
45 <Filter>Header Files</Filter>
46 </ClInclude>
47 </ItemGroup>
48</Project> \ 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 @@
1#include "dcp_core.h"
2
3void Estimate_A(IplImage *DarkChannel, IplImage *InputImage, struct Max_Pixel_Selector *MaxPixel, double A[])
4{
5 double num = height * width * 0.001;
6 double num1per = num * 0.01; //num1per is the number of 1 percent of top 0.1 pixels
7 //k is the index of the color channel
8 int k = 0;
9 int patchsize;
10 int dark_i, dark_j;
11 uchar Max = 0;
12
13 IplImage *mask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
14 cvZero(mask);
15
16 int e = 0, i, j;
17 for (i = 1; i <= height; i++)
18 {
19 for (j = 1; j <= width; j++)
20 {
21 MaxPixel[e].Pixel = *(uchar *)(DarkChannel->imageData + (i - 1) * gwidthstep + (j - 1));
22 MaxPixel[e].i = i;
23 MaxPixel[e].j = j;
24 e++;
25 }
26 }
27 sort(MaxPixel, MaxPixel + e, comp1);
28
29 for (i = 0; i < num; i++)
30 {
31 dark_i = MaxPixel[i].i;
32 dark_j = MaxPixel[i].j;
33 *(uchar *)(mask->imageData + (dark_i - 1) * gwidthstep + (dark_j - 1)) = 255;
34 //ֻ�е�mask���Ϊ255֮�󣬲�˵���ÿ���������ֵ���ڰ�ͨ����ǰ0.1%֮�ڵ�
35 }
36
37 if (num1per < 9)
38 patchsize = 3;
39 else
40 patchsize = sqrt(num1per);
41
42 for (k = 0; k < 3; k++)
43 {
44 int e, x, y;
45 int tmp = (patchsize - 1) / 2;
46 int st_row, ed_row;
47 int st_col, ed_col;
48
49 double A_tmp = 0;
50 double aver = 0; // aver Ϊָ����Сpatch��InputImageֵ��ƽ��ֵ
51 int flag; //flag������ȡmask�ı��
52
53 for (i = 1; i <= num; i++)
54 {
55 aver = 0;
56 dark_i = MaxPixel[i].i;
57 dark_j = MaxPixel[i].j;
58
59 st_row = dark_i - tmp, ed_row = dark_i + tmp;
60 st_col = dark_j - tmp, ed_col = dark_j + tmp;
61
62 if (st_row <= 0)
63 st_row = 1;
64 if (ed_row>height)
65 ed_row = height;
66 if (st_col <= 0)
67 st_col = 1;
68 if (ed_col>width)
69 ed_col = width;
70
71 e = 0;
72 for (x = st_row; x <= ed_row; x++)
73 {
74 for (y = st_col; y <= ed_col; y++)
75 {
76 flag = *(uchar *)(mask->imageData + (x - 1) * gwidthstep + (y - 1));
77 if (flag == 0) //δ�����˵���õ㲻��ǰ0.1%��Ӧ�������ڣ�����
78 {
79 continue;
80 }
81 else
82 {
83 aver += *(uchar *)(InputImage->imageData + (x - 1) * widthstep + (y - 1) *nch + k);
84 e++;
85 }
86 }
87 }
88 aver /= e;
89 if (A_tmp < aver)
90 {
91 A_tmp = aver;
92 }
93 }
94 A[k] = A_tmp / 255.0;
95 }
96 cvReleaseImage(&mask);
97} \ 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 @@
1#include "dcp_core.h"
2
3static 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
10void 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}
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 @@
1#include "dcp.h"
2
3void dehaze(IplImage *recover, IplImage *input)
4{
5 int height = input->height;
6 int width = input->width;
7
8 IplImage *darkchannel = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
9 IplImage *transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
10 IplImage *refine_transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
11
12 int darkchannelradius = MIN(width, height) * 0.02;
13
14 CalcDarkChannel(darkchannel, input, darkchannelradius);
15
16
17
18}
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 @@
1#ifndef DCP_H
2#define DCP_H
3
4#include "dcp_core.h"
5
6void dehaze(IplImage *recover, IplImage *input);
7
8#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 @@
1#ifndef DCP_CORE_H
2#define DCP_CORE_H
3
4#include <opencv\cv.h>
5#include <opencv\highgui.h>
6
7void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius);
8
9#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 @@
1#include "dcp_core.h"
2
3#include <iostream>
4#include <vector>
5
6using namespace std;
7
8void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r)
9{
10 int height = q->height;
11 int width = q->width;
12 int widthstep = II->widthStep;
13 int gwidthstep = p->widthStep;
14 int nch = II->nChannels;
15
16 int i, j;
17 int m, n;
18 int w;
19 int e = 0;
20 int st_row, ed_row;
21 int st_col, ed_col;
22
23 double sum_Ir, sum_Ig, sum_Ib;
24 double sum_Ir_square, sum_Ig_square, sum_Ib_square;
25 double sum_IrIg, sum_IgIb, sum_IrIb;
26 double sum_PiIr, sum_PiIg, sum_PiIb;
27 double sum_Pi;
28
29 double A, B, C, D, E, F, G, H, I, J, K, L;
30 double X, Y, Z;
31 double ak_r, ak_g, ak_b;
32 double bk;
33 double det;
34
35 double tmp_Ir, tmp_Ig, tmp_Ib;
36 double tmp_p, tmp_q;
37
38 vector<double> v_ak_r;
39 vector<double> v_ak_g;
40 vector<double> v_ak_b;
41 vector<double> v_bk;
42
43 for (i = 1; i <= height; i++)
44 {
45 if (i % 10 == 0)
46 printf("%d\n", i);
47
48 for (j = 1; j <= width; j++)
49 {
50 st_row = i - r, ed_row = i + r;
51 st_col = j - r, ed_col = j + r;
52
53 if (st_row <= 0)
54 st_row = 1;
55 if (ed_row > height)
56 ed_row = height;
57 if (st_col <= 0)
58 st_col = 1;
59 if (ed_col > width)
60 ed_col = width;
61
62 sum_Ir = sum_Ig = sum_Ib = 0;
63 sum_Ir_square = sum_Ig_square = sum_Ib_square = 0;
64 sum_IrIg = sum_IgIb = sum_IrIb = 0;
65 sum_PiIr = sum_PiIg = sum_PiIb = 0;
66 sum_Pi = 0;
67 w = 0;
68
69 for (m = st_row; m <= ed_row; m++)
70 {
71 for (n = st_col; n <= ed_col; n++)
72 {
73 tmp_Ib = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch);
74 tmp_Ig = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 1);
75 tmp_Ir = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 2);
76
77 tmp_p = *(uchar *)(p->imageData + (m - 1) * gwidthstep + (n - 1));
78
79 sum_Ib += tmp_Ib;
80 sum_Ig += tmp_Ig;
81 sum_Ir += tmp_Ir;
82
83 sum_Ib_square += tmp_Ib * tmp_Ib;
84 sum_Ig_square += tmp_Ig * tmp_Ig;
85 sum_Ir_square += tmp_Ir * tmp_Ir;
86
87 sum_IrIg += tmp_Ir * tmp_Ig;
88 sum_IgIb += tmp_Ig * tmp_Ib;
89 sum_IrIb += tmp_Ir * tmp_Ib;
90
91 sum_Pi += tmp_p;
92 sum_PiIb += tmp_p * tmp_Ib;
93 sum_PiIg += tmp_p * tmp_Ig;
94 sum_PiIr += tmp_p * tmp_Ir;
95
96 w++;
97 }
98 }
99
100 A = (sum_Ir_square + w * eps) * sum_Ig - sum_Ir * sum_IrIg;
101 B = sum_IrIg * sum_Ig - sum_Ir * (sum_Ig_square + w * eps);
102 C = sum_IrIb * sum_Ig - sum_Ir * sum_IgIb;
103 D = sum_PiIr * sum_Ig - sum_PiIg * sum_Ir;
104 E = (sum_Ir_square + w * eps) * sum_Ib - sum_IrIb * sum_Ir;
105 F = sum_IrIg * sum_Ib - sum_IgIb * sum_Ir;
106 G = sum_IrIb * sum_Ib - (sum_Ib_square + w * eps) * sum_Ir;
107 H = sum_PiIr * sum_Ib - sum_PiIb * sum_Ir;
108 I = (sum_Ir_square + w * eps) * w - sum_Ir * sum_Ir;
109 J = sum_IrIg * w - sum_Ig * sum_Ir;
110 K = sum_IrIb * w - sum_Ib * sum_Ir;
111 L = sum_PiIr * w - sum_Pi * sum_Ir;
112
113 det = A * F * K + B * G * I + C * E * J - C * F * I - A * G * J - B * E * K;
114 X = D * F * K + B * G * L + C * H * J - C * F * L - D * G * J - B * H * K;
115 Y = A * H * K + D * G * I + C * E * L - C * H * I - D * E * K - A * G * L;
116 Z = A * F * L + B * H * I + D * J * E - D * F * I - B * E * L - A * H * J;
117
118 ak_r = X / det;
119 ak_g = Y / det;
120 ak_b = Z / det;
121
122 bk = (sum_PiIg - sum_IrIg * ak_r - (sum_Ig_square + w * eps) * ak_g - sum_IgIb * ak_b) / sum_Ig;
123
124 tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch);
125 tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1);
126 tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2);
127
128 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
129
130 if (tmp_q > 255)
131 tmp_q = 255;
132 else if (tmp_q < 0)
133 tmp_q = 0;
134
135 *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q;
136
137 v_ak_b.push_back(ak_b);
138 v_ak_g.push_back(ak_g);
139 v_ak_r.push_back(ak_r);
140 v_bk.push_back(bk);
141 }
142 }
143
144 for (int i = 1; i <= height; i++)
145 {
146 for (int j = 1; j <= width; j++)
147 {
148 st_row = i - r, ed_row = i + r;
149 st_col = j - r, ed_col = j + r;
150
151 if (st_row <= 0)
152 st_row = 1;
153 if (ed_row > height)
154 ed_row = height;
155 if (st_col <= 0)
156 st_col = 1;
157 if (ed_col > width)
158 ed_col = width;
159
160 double ak_r, ak_g, ak_b, bk;
161 ak_r = ak_g = ak_b = bk = 0;
162
163 int number = 0;
164 for (int m = st_row; m <= ed_row; m++)
165 {
166 for (int n = st_col; n <= ed_col; n++)
167 {
168 ak_r += v_ak_r[(m - 1) * width + n - 1];
169 ak_g += v_ak_g[(m - 1) * width + n - 1];
170 ak_b += v_ak_b[(m - 1) * width + n - 1];
171 bk += v_bk[(m - 1) * width + n - 1];
172 number++;
173 }
174 }
175
176 ak_r /= number;
177 ak_g /= number;
178 ak_b /= number;
179 bk /= number;
180
181 tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch);
182 tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1);
183 tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2);
184
185 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
186
187 if (tmp_q > 255)
188 tmp_q = 255;
189 else if (tmp_q < 0)
190 tmp_q = 0;
191
192 *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q;
193 }
194 }
195}
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 @@
1<?xml version="1.0" encoding="utf-8"?>
2<packages>
3 <package id="OpenCV" version="2.4.10" targetFramework="Native" />
4</packages> \ 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 @@
1#include "dcp_core.h"
2
3void Recover(IplImage *Result, IplImage *InputImage, double A[])
4{
5 double t0 = 0.1;
6 double t, tmp_res;
7
8 int i, j, k;
9 int e = 0, number = 0;
10 double a = 0;
11
12 for (i = 1; i <= height; i++)
13 {
14 for (j = 1; j <= width; j++)
15 {
16 t = real_trans[e++];
17 t /= 255.0;
18 for (k = 0; k < 3; k++)
19 {
20 a = *(uchar *)(InputImage->imageData + (i - 1) * widthstep + (j - 1) * nch + k);
21 a /= 255;
22
23 tmp_res = ((a - A[k]) / MaxTwo(t, t0)) + A[k];
24
25 real_recover[number++] = tmp_res;
26
27 if (tmp_res > 1)
28 tmp_res = 1;
29 else if (tmp_res < 0)
30 tmp_res = 0;
31
32 *(uchar *)(Result->imageData + (i - 1) * widthstep + (j - 1) * nch + k) = tmp_res * 255.0;
33 }
34 }
35 }
36} \ 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 @@
1#include "dcp_core.h"
2
3void Estimate_transmission(IplImage *Transmission_maps, IplImage *InputImage, double A[], double heap[], double real_trans[])
4{
5 double w = 0.95;
6 double tmp;
7 double tran;
8 int i, j, k;
9 int e = 0;
10
11 IplImage *tmp_Trans = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
12
13 for (k = 0; k < 3; k++)
14 {
15 for (i = 1; i <= height; i++)
16 {
17 for (j = 1; j <= width; j++)
18 {
19 tmp = *(uchar *)(InputImage->imageData + (i - 1) * widthstep + (j - 1) * nch + k);
20 tmp /= A[k];
21
22 if (tmp > 255)
23 tmp = 255;
24 *(uchar *)(tmp_Trans->imageData + (i - 1) * widthstep + (j - 1) * nch + k) = tmp;
25 }
26 }
27 }
28 Cal_DarkChannel(Transmission_maps, tmp_Trans, nInteger, heap);
29
30 for (i = 1; i <= height; i++)
31 {
32 for (j = 1; j <= width; j++)
33 {
34 tran = *(uchar *)(Transmission_maps->imageData + (i - 1) * gwidthstep + (j - 1));
35
36 tran /= 255.0;
37 tran = 1 - w * tran;
38
39 real_trans[e++] = tran * 255.0;
40
41 if (tran > 1)
42 tran = 1;
43 else if (tran < 0)
44 tran = 0;
45
46 *(uchar *)(Transmission_maps->imageData + (i - 1) * gwidthstep + (j - 1)) = tran * 255;
47 }
48 }
49 //cvSaveImage("Estimated-Trans.bmp", Transmission_maps);
50 cvReleaseImage(&tmp_Trans);
51}
Powered by cgit v1.2.3 (git 2.41.0)