aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--DCP.sln6
-rw-r--r--DCP/DCP.vcxproj85
-rw-r--r--DCP/DCP.vcxproj.filters6
-rw-r--r--DCP/airlight.cpp12
-rw-r--r--DCP/dcp.cpp39
-rw-r--r--DCP/dcp_core.h8
-rw-r--r--DCP/guidedfilter.cpp106
-rw-r--r--DCP/packages.config4
-rw-r--r--DCP/recover.cpp11
-rw-r--r--DCP/test.cpp11
-rw-r--r--DCP/transmission.cpp9
-rw-r--r--DCP/utility.h29
12 files changed, 205 insertions, 121 deletions
diff --git a/DCP.sln b/DCP.sln
index e23dbd2..1310c0d 100644
--- a/DCP.sln
+++ b/DCP.sln
@@ -8,13 +8,19 @@ EndProject
8Global 8Global
9 GlobalSection(SolutionConfigurationPlatforms) = preSolution 9 GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 Debug|Win32 = Debug|Win32 10 Debug|Win32 = Debug|Win32
11 Debug|x64 = Debug|x64
11 Release|Win32 = Release|Win32 12 Release|Win32 = Release|Win32
13 Release|x64 = Release|x64
12 EndGlobalSection 14 EndGlobalSection
13 GlobalSection(ProjectConfigurationPlatforms) = postSolution 15 GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.ActiveCfg = Debug|Win32 16 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.ActiveCfg = Debug|Win32
15 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.Build.0 = Debug|Win32 17 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|Win32.Build.0 = Debug|Win32
18 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|x64.ActiveCfg = Debug|x64
19 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Debug|x64.Build.0 = Debug|x64
16 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.ActiveCfg = Release|Win32 20 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.ActiveCfg = Release|Win32
17 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.Build.0 = Release|Win32 21 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|Win32.Build.0 = Release|Win32
22 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|x64.ActiveCfg = Release|x64
23 {1543533F-481B-40EC-BEFC-90E46456A5F8}.Release|x64.Build.0 = Release|x64
18 EndGlobalSection 24 EndGlobalSection
19 GlobalSection(SolutionProperties) = preSolution 25 GlobalSection(SolutionProperties) = preSolution
20 HideSolutionNode = FALSE 26 HideSolutionNode = FALSE
diff --git a/DCP/DCP.vcxproj b/DCP/DCP.vcxproj
index 8d88b2c..b2ef313 100644
--- a/DCP/DCP.vcxproj
+++ b/DCP/DCP.vcxproj
@@ -1,15 +1,22 @@
1<?xml version="1.0" encoding="utf-8"?> 1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> 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"> 3 <ItemGroup Label="ProjectConfigurations">
5 <ProjectConfiguration Include="Debug|Win32"> 4 <ProjectConfiguration Include="Debug|Win32">
6 <Configuration>Debug</Configuration> 5 <Configuration>Debug</Configuration>
7 <Platform>Win32</Platform> 6 <Platform>Win32</Platform>
8 </ProjectConfiguration> 7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Debug|x64">
9 <Configuration>Debug</Configuration>
10 <Platform>x64</Platform>
11 </ProjectConfiguration>
9 <ProjectConfiguration Include="Release|Win32"> 12 <ProjectConfiguration Include="Release|Win32">
10 <Configuration>Release</Configuration> 13 <Configuration>Release</Configuration>
11 <Platform>Win32</Platform> 14 <Platform>Win32</Platform>
12 </ProjectConfiguration> 15 </ProjectConfiguration>
16 <ProjectConfiguration Include="Release|x64">
17 <Configuration>Release</Configuration>
18 <Platform>x64</Platform>
19 </ProjectConfiguration>
13 </ItemGroup> 20 </ItemGroup>
14 <PropertyGroup Label="Globals"> 21 <PropertyGroup Label="Globals">
15 <ProjectGuid>{1543533F-481B-40EC-BEFC-90E46456A5F8}</ProjectGuid> 22 <ProjectGuid>{1543533F-481B-40EC-BEFC-90E46456A5F8}</ProjectGuid>
@@ -23,6 +30,12 @@
23 <PlatformToolset>v120</PlatformToolset> 30 <PlatformToolset>v120</PlatformToolset>
24 <CharacterSet>Unicode</CharacterSet> 31 <CharacterSet>Unicode</CharacterSet>
25 </PropertyGroup> 32 </PropertyGroup>
33 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
34 <ConfigurationType>Application</ConfigurationType>
35 <UseDebugLibraries>true</UseDebugLibraries>
36 <PlatformToolset>v120</PlatformToolset>
37 <CharacterSet>Unicode</CharacterSet>
38 </PropertyGroup>
26 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration"> 39 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
27 <ConfigurationType>Application</ConfigurationType> 40 <ConfigurationType>Application</ConfigurationType>
28 <UseDebugLibraries>false</UseDebugLibraries> 41 <UseDebugLibraries>false</UseDebugLibraries>
@@ -30,24 +43,47 @@
30 <WholeProgramOptimization>true</WholeProgramOptimization> 43 <WholeProgramOptimization>true</WholeProgramOptimization>
31 <CharacterSet>Unicode</CharacterSet> 44 <CharacterSet>Unicode</CharacterSet>
32 </PropertyGroup> 45 </PropertyGroup>
46 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
47 <ConfigurationType>Application</ConfigurationType>
48 <UseDebugLibraries>false</UseDebugLibraries>
49 <PlatformToolset>v120</PlatformToolset>
50 <WholeProgramOptimization>true</WholeProgramOptimization>
51 <CharacterSet>Unicode</CharacterSet>
52 </PropertyGroup>
33 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> 53 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
34 <ImportGroup Label="ExtensionSettings"> 54 <ImportGroup Label="ExtensionSettings">
35 </ImportGroup> 55 </ImportGroup>
36 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 56 <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" /> 57 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
58 <Import Project="D:\3rdLibs\OpenCV3\OpenCV3GPU.props" />
59 </ImportGroup>
60 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
61 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
62 <Import Project="D:\3rdLibs\OpenCV3\OpenCV3GPU.props" />
38 </ImportGroup> 63 </ImportGroup>
39 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 64 <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" /> 65 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66 <Import Project="D:\3rdLibs\OpenCV3\OpenCV3GPU.props" />
67 </ImportGroup>
68 <ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
69 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
70 <Import Project="D:\3rdLibs\OpenCV3\OpenCV3GPU.props" />
41 </ImportGroup> 71 </ImportGroup>
42 <PropertyGroup Label="UserMacros"> 72 <PropertyGroup Label="UserMacros">
43 <NuGetPackageImportStamp>f521f52d</NuGetPackageImportStamp> 73 <NuGetPackageImportStamp>ed7df352</NuGetPackageImportStamp>
44 </PropertyGroup> 74 </PropertyGroup>
45 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 75 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
46 <LinkIncremental>true</LinkIncremental> 76 <LinkIncremental>true</LinkIncremental>
47 </PropertyGroup> 77 </PropertyGroup>
78 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
79 <LinkIncremental>true</LinkIncremental>
80 </PropertyGroup>
48 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 81 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
49 <LinkIncremental>false</LinkIncremental> 82 <LinkIncremental>false</LinkIncremental>
50 </PropertyGroup> 83 </PropertyGroup>
84 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
85 <LinkIncremental>false</LinkIncremental>
86 </PropertyGroup>
51 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'"> 87 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
52 <ClCompile> 88 <ClCompile>
53 <PrecompiledHeader> 89 <PrecompiledHeader>
@@ -61,6 +97,19 @@
61 <GenerateDebugInformation>true</GenerateDebugInformation> 97 <GenerateDebugInformation>true</GenerateDebugInformation>
62 </Link> 98 </Link>
63 </ItemDefinitionGroup> 99 </ItemDefinitionGroup>
100 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
101 <ClCompile>
102 <PrecompiledHeader>
103 </PrecompiledHeader>
104 <WarningLevel>Level3</WarningLevel>
105 <Optimization>Disabled</Optimization>
106 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
107 </ClCompile>
108 <Link>
109 <SubSystem>Console</SubSystem>
110 <GenerateDebugInformation>true</GenerateDebugInformation>
111 </Link>
112 </ItemDefinitionGroup>
64 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'"> 113 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
65 <ClCompile> 114 <ClCompile>
66 <WarningLevel>Level3</WarningLevel> 115 <WarningLevel>Level3</WarningLevel>
@@ -78,9 +127,27 @@
78 <OptimizeReferences>true</OptimizeReferences> 127 <OptimizeReferences>true</OptimizeReferences>
79 </Link> 128 </Link>
80 </ItemDefinitionGroup> 129 </ItemDefinitionGroup>
130 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
131 <ClCompile>
132 <WarningLevel>Level3</WarningLevel>
133 <PrecompiledHeader>
134 </PrecompiledHeader>
135 <Optimization>MaxSpeed</Optimization>
136 <FunctionLevelLinking>true</FunctionLevelLinking>
137 <IntrinsicFunctions>true</IntrinsicFunctions>
138 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
139 </ClCompile>
140 <Link>
141 <SubSystem>Console</SubSystem>
142 <GenerateDebugInformation>true</GenerateDebugInformation>
143 <EnableCOMDATFolding>true</EnableCOMDATFolding>
144 <OptimizeReferences>true</OptimizeReferences>
145 </Link>
146 </ItemDefinitionGroup>
81 <ItemGroup> 147 <ItemGroup>
82 <ClInclude Include="dcp.h" /> 148 <ClInclude Include="dcp.h" />
83 <ClInclude Include="dcp_core.h" /> 149 <ClInclude Include="dcp_core.h" />
150 <ClInclude Include="utility.h" />
84 </ItemGroup> 151 </ItemGroup>
85 <ItemGroup> 152 <ItemGroup>
86 <ClCompile Include="airlight.cpp" /> 153 <ClCompile Include="airlight.cpp" />
@@ -91,18 +158,6 @@
91 <ClCompile Include="test.cpp" /> 158 <ClCompile Include="test.cpp" />
92 <ClCompile Include="transmission.cpp" /> 159 <ClCompile Include="transmission.cpp" />
93 </ItemGroup> 160 </ItemGroup>
94 <ItemGroup>
95 <None Include="packages.config" />
96 </ItemGroup>
97 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> 161 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
98 <ImportGroup Label="ExtensionTargets"> 162 <ImportGroup Label="ExtensionTargets" />
99 <Import Project="..\packages\OpenCV.2.4.10\build\native\OpenCV.targets" Condition="Exists('..\packages\OpenCV.2.4.10\build\native\OpenCV.targets')" />
100 </ImportGroup>
101 <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
102 <PropertyGroup>
103 <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>
104 </PropertyGroup>
105 <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'))" />
106 <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'))" />
107 </Target>
108</Project> \ No newline at end of file 163</Project> \ No newline at end of file
diff --git a/DCP/DCP.vcxproj.filters b/DCP/DCP.vcxproj.filters
index 0992c1b..23bfa2a 100644
--- a/DCP/DCP.vcxproj.filters
+++ b/DCP/DCP.vcxproj.filters
@@ -38,14 +38,14 @@
38 </ClCompile> 38 </ClCompile>
39 </ItemGroup> 39 </ItemGroup>
40 <ItemGroup> 40 <ItemGroup>
41 <None Include="packages.config" />
42 </ItemGroup>
43 <ItemGroup>
44 <ClInclude Include="dcp_core.h"> 41 <ClInclude Include="dcp_core.h">
45 <Filter>Header Files</Filter> 42 <Filter>Header Files</Filter>
46 </ClInclude> 43 </ClInclude>
47 <ClInclude Include="dcp.h"> 44 <ClInclude Include="dcp.h">
48 <Filter>Header Files</Filter> 45 <Filter>Header Files</Filter>
49 </ClInclude> 46 </ClInclude>
47 <ClInclude Include="utility.h">
48 <Filter>Header Files</Filter>
49 </ClInclude>
50 </ItemGroup> 50 </ItemGroup>
51</Project> \ No newline at end of file 51</Project> \ No newline at end of file
diff --git a/DCP/airlight.cpp b/DCP/airlight.cpp
index 08f18d0..78ec9a9 100644
--- a/DCP/airlight.cpp
+++ b/DCP/airlight.cpp
@@ -1,10 +1,7 @@
1#include "dcp_core.h" 1#include "dcp_core.h"
2#include <malloc.h>
3#include <vector>
4#include <iostream>
5#include <algorithm>
6 2
7using namespace std; 3#include <algorithm>
4using std::sort;
8 5
9struct Pixel 6struct Pixel
10{ 7{
@@ -33,7 +30,6 @@ void CalcAirlight(IplImage *darkchannel, IplImage *input, double A[])
33 } 30 }
34 sort(v_darkchannel, v_darkchannel + count, [](struct Pixel &a, struct Pixel &b){ return a.value > b.value; }); 31 sort(v_darkchannel, v_darkchannel + count, [](struct Pixel &a, struct Pixel &b){ return a.value > b.value; });
35 32
36
37 IplImage *mask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); 33 IplImage *mask = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
38 cvZero(mask); 34 cvZero(mask);
39 35
@@ -65,12 +61,12 @@ void CalcAirlight(IplImage *darkchannel, IplImage *input, double A[])
65 61
66 sort(v_channel, v_channel + count, [](struct Pixel &a, struct Pixel &b){ return a.value > b.value; }); 62 sort(v_channel, v_channel + count, [](struct Pixel &a, struct Pixel &b){ return a.value > b.value; });
67 63
68 int channel_airlight = 0; 64 double channel_airlight = 0;
69 for (int i = 0; i < count * 0.01; i++) 65 for (int i = 0; i < count * 0.01; i++)
70 { 66 {
71 channel_airlight += v_channel[i].value; 67 channel_airlight += v_channel[i].value;
72 } 68 }
73 channel_airlight /= (count * 0.01); 69 channel_airlight = channel_airlight / (count * 0.01);
74 A[k] = channel_airlight; 70 A[k] = channel_airlight;
75 71
76 free(v_channel); 72 free(v_channel);
diff --git a/DCP/dcp.cpp b/DCP/dcp.cpp
index 4e100c6..716759c 100644
--- a/DCP/dcp.cpp
+++ b/DCP/dcp.cpp
@@ -1,7 +1,4 @@
1#include "dcp.h" 1#include "dcp_core.h"
2
3#include <iostream>
4using namespace std;
5 2
6void dehaze(IplImage *recover, IplImage *input) 3void dehaze(IplImage *recover, IplImage *input)
7{ 4{
@@ -12,18 +9,36 @@ void dehaze(IplImage *recover, IplImage *input)
12 IplImage *transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); 9 IplImage *transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
13 IplImage *refine_transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1); 10 IplImage *refine_transmission = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
14 11
15 int darkchannelradius = MIN(width, height) * 0.02; 12 int darkchannelradius = cvRound(MIN(width, height) * 0.02);
16
17
18
19 double Airlight[3] = { 0.0, 0.0, 0.0 }; 13 double Airlight[3] = { 0.0, 0.0, 0.0 };
14
15 TicToc t;
16 t.tic();
17 printf("CalcDarkChannel...");
20 CalcDarkChannel(darkchannel, input, darkchannelradius); 18 CalcDarkChannel(darkchannel, input, darkchannelradius);
21 19 t.toc();
20
21 t.tic();
22 printf("CalcAirlight...");
22 CalcAirlight(darkchannel, input, Airlight); 23 CalcAirlight(darkchannel, input, Airlight);
23 24 t.toc();
25
26 t.tic();
27 printf("CalcTransmission...");
24 CalcTransmission(transmission, input, Airlight, darkchannelradius); 28 CalcTransmission(transmission, input, Airlight, darkchannelradius);
29 t.toc();
30
31 t.tic();
32 printf("GuidedFilterColor...");
25 GuidedFilterColor(refine_transmission, input, transmission, 1e-6, 60); 33 GuidedFilterColor(refine_transmission, input, transmission, 1e-6, 60);
26 CalcRecover(recover, input, refine_transmission, Airlight); 34 t.toc();
27 35
28 36 t.tic();
37 printf("CalcRecover...");
38 CalcRecover(recover, input, refine_transmission, Airlight);
39 t.toc();
40
41 cvReleaseImage(&refine_transmission);
42 cvReleaseImage(&transmission);
43 cvReleaseImage(&darkchannel);
29} 44}
diff --git a/DCP/dcp_core.h b/DCP/dcp_core.h
index 85e4d59..658e461 100644
--- a/DCP/dcp_core.h
+++ b/DCP/dcp_core.h
@@ -4,11 +4,17 @@
4#include <opencv\cv.h> 4#include <opencv\cv.h>
5#include <opencv\highgui.h> 5#include <opencv\highgui.h>
6 6
7#include <iostream>
8
9#include <cstdio>
10#include <malloc.h>
11
12#include "utility.h"
13
7void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius); 14void CalcDarkChannel(IplImage *darkchannel, IplImage *input, int radius);
8void CalcAirlight(IplImage *darkchannel, IplImage *input, double A[]); 15void CalcAirlight(IplImage *darkchannel, IplImage *input, double A[]);
9void CalcTransmission(IplImage *transmission, IplImage *input, double A[], int radius); 16void CalcTransmission(IplImage *transmission, IplImage *input, double A[], int radius);
10void CalcRecover(IplImage *result, IplImage *input, IplImage *transmission, double A[]); 17void CalcRecover(IplImage *result, IplImage *input, IplImage *transmission, double A[]);
11void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r); 18void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r);
12 19
13
14#endif \ No newline at end of file 20#endif \ No newline at end of file
diff --git a/DCP/guidedfilter.cpp b/DCP/guidedfilter.cpp
index bfdf956..34d255a 100644
--- a/DCP/guidedfilter.cpp
+++ b/DCP/guidedfilter.cpp
@@ -1,10 +1,5 @@
1#include "dcp_core.h" 1#include "dcp_core.h"
2 2
3#include <iostream>
4#include <vector>
5
6using namespace std;
7
8void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r) 3void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r)
9{ 4{
10 int height = q->height; 5 int height = q->height;
@@ -35,26 +30,24 @@ void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r
35 double tmp_Ir, tmp_Ig, tmp_Ib; 30 double tmp_Ir, tmp_Ig, tmp_Ib;
36 double tmp_p, tmp_q; 31 double tmp_p, tmp_q;
37 32
38 vector<double> v_ak_r; 33 double *v_ak_r = (double *)malloc(sizeof(double) * height * width);
39 vector<double> v_ak_g; 34 double *v_ak_g = (double *)malloc(sizeof(double) * height * width);
40 vector<double> v_ak_b; 35 double *v_ak_b = (double *)malloc(sizeof(double) * height * width);
41 vector<double> v_bk; 36 double *v_bk = (double *)malloc(sizeof(double) * height * width);
37
38 int count = 0;
42 39
43 for (i = 1; i <= height; i++) 40 for (i = 0; i < height; i++)
44 { 41 {
45 for (j = 1; j <= width; j++) 42 for (j = 0; j < width; j++)
46 { 43 {
47 st_row = i - r, ed_row = i + r; 44 st_row = i - r, ed_row = i + r;
48 st_col = j - r, ed_col = j + r; 45 st_col = j - r, ed_col = j + r;
49 46
50 if (st_row <= 0) 47 st_row = st_row < 0 ? 0 : st_row;
51 st_row = 1; 48 ed_row = ed_row >= height ? (height - 1) : ed_row;
52 if (ed_row > height) 49 st_col = st_col < 0 ? 0 : st_col;
53 ed_row = height; 50 ed_col = ed_col >= width ? (width - 1) : ed_col;
54 if (st_col <= 0)
55 st_col = 1;
56 if (ed_col > width)
57 ed_col = width;
58 51
59 sum_Ir = sum_Ig = sum_Ib = 0; 52 sum_Ir = sum_Ig = sum_Ib = 0;
60 sum_Ir_square = sum_Ig_square = sum_Ib_square = 0; 53 sum_Ir_square = sum_Ig_square = sum_Ib_square = 0;
@@ -67,11 +60,11 @@ void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r
67 { 60 {
68 for (n = st_col; n <= ed_col; n++) 61 for (n = st_col; n <= ed_col; n++)
69 { 62 {
70 tmp_Ib = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch); 63 tmp_Ib = *(uchar *)(II->imageData + (m) * widthstep + (n) * nch);
71 tmp_Ig = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 1); 64 tmp_Ig = *(uchar *)(II->imageData + (m) * widthstep + (n) * nch + 1);
72 tmp_Ir = *(uchar *)(II->imageData + (m - 1) * widthstep + (n - 1) * nch + 2); 65 tmp_Ir = *(uchar *)(II->imageData + (m) * widthstep + (n) * nch + 2);
73 66
74 tmp_p = *(uchar *)(p->imageData + (m - 1) * gwidthstep + (n - 1)); 67 tmp_p = *(uchar *)(p->imageData + (m) * gwidthstep + (n));
75 68
76 sum_Ib += tmp_Ib; 69 sum_Ib += tmp_Ib;
77 sum_Ig += tmp_Ig; 70 sum_Ig += tmp_Ig;
@@ -118,41 +111,34 @@ void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r
118 111
119 bk = (sum_PiIg - sum_IrIg * ak_r - (sum_Ig_square + w * eps) * ak_g - sum_IgIb * ak_b) / sum_Ig; 112 bk = (sum_PiIg - sum_IrIg * ak_r - (sum_Ig_square + w * eps) * ak_g - sum_IgIb * ak_b) / sum_Ig;
120 113
121 tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch); 114 tmp_Ib = *(uchar *)(II->imageData + i * widthstep + j * nch);
122 tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1); 115 tmp_Ig = *(uchar *)(II->imageData + i * widthstep + j * nch + 1);
123 tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2); 116 tmp_Ir = *(uchar *)(II->imageData + i * widthstep + j * nch + 2);
124 117
125 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk; 118 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
119 tmp_q = tmp_q > 255 ? 255 : (tmp_q < 0 ? 0 : tmp_q);
126 120
127 if (tmp_q > 255) 121 *(uchar *)(q->imageData + i * gwidthstep + j) = cvRound(tmp_q);
128 tmp_q = 255;
129 else if (tmp_q < 0)
130 tmp_q = 0;
131 122
132 *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q; 123 v_ak_b[count] = ak_b;
133 124 v_ak_g[count] = ak_g;
134 v_ak_b.push_back(ak_b); 125 v_ak_r[count] = ak_r;
135 v_ak_g.push_back(ak_g); 126 v_bk[count] = bk;
136 v_ak_r.push_back(ak_r); 127 count++;
137 v_bk.push_back(bk);
138 } 128 }
139 } 129 }
140 130
141 for (int i = 1; i <= height; i++) 131 for (int i = 0; i < height; i++)
142 { 132 {
143 for (int j = 1; j <= width; j++) 133 for (int j = 0; j < width; j++)
144 { 134 {
145 st_row = i - r, ed_row = i + r; 135 st_row = i - r, ed_row = i + r;
146 st_col = j - r, ed_col = j + r; 136 st_col = j - r, ed_col = j + r;
147 137
148 if (st_row <= 0) 138 st_row = st_row < 0 ? 0 : st_row;
149 st_row = 1; 139 ed_row = ed_row >= height ? (height - 1) : ed_row;
150 if (ed_row > height) 140 st_col = st_col < 0 ? 0 : st_col;
151 ed_row = height; 141 ed_col = ed_col >= width ? (width - 1) : ed_col;
152 if (st_col <= 0)
153 st_col = 1;
154 if (ed_col > width)
155 ed_col = width;
156 142
157 double ak_r, ak_g, ak_b, bk; 143 double ak_r, ak_g, ak_b, bk;
158 ak_r = ak_g = ak_b = bk = 0; 144 ak_r = ak_g = ak_b = bk = 0;
@@ -162,10 +148,10 @@ void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r
162 { 148 {
163 for (int n = st_col; n <= ed_col; n++) 149 for (int n = st_col; n <= ed_col; n++)
164 { 150 {
165 ak_r += v_ak_r[(m - 1) * width + n - 1]; 151 ak_r += v_ak_r[(m) * width + n];
166 ak_g += v_ak_g[(m - 1) * width + n - 1]; 152 ak_g += v_ak_g[(m) * width + n];
167 ak_b += v_ak_b[(m - 1) * width + n - 1]; 153 ak_b += v_ak_b[(m) * width + n];
168 bk += v_bk[(m - 1) * width + n - 1]; 154 bk += v_bk[(m) * width + n];
169 number++; 155 number++;
170 } 156 }
171 } 157 }
@@ -175,18 +161,18 @@ void GuidedFilterColor(IplImage *q, IplImage *II, IplImage *p, double eps, int r
175 ak_b /= number; 161 ak_b /= number;
176 bk /= number; 162 bk /= number;
177 163
178 tmp_Ib = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch); 164 tmp_Ib = *(uchar *)(II->imageData + i * widthstep + j * nch);
179 tmp_Ig = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 1); 165 tmp_Ig = *(uchar *)(II->imageData + i * widthstep + j * nch + 1);
180 tmp_Ir = *(uchar *)(II->imageData + (i - 1) * widthstep + (j - 1) * nch + 2); 166 tmp_Ir = *(uchar *)(II->imageData + i * widthstep + j * nch + 2);
181 167
182 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk; 168 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
183 169 tmp_q = tmp_q > 255 ? 255 : (tmp_q < 0 ? 0 : tmp_q);
184 if (tmp_q > 255) 170
185 tmp_q = 255; 171 *(uchar *)(q->imageData + i * gwidthstep + j) = cvRound(tmp_q);
186 else if (tmp_q < 0)
187 tmp_q = 0;
188
189 *(uchar *)(q->imageData + (i - 1) * gwidthstep + (j - 1)) = tmp_q;
190 } 172 }
191 } 173 }
174 free(v_ak_b);
175 free(v_ak_g);
176 free(v_ak_r);
177 free(v_bk);
192} 178}
diff --git a/DCP/packages.config b/DCP/packages.config
deleted file mode 100644
index b2057a2..0000000
--- a/DCP/packages.config
+++ /dev/null
@@ -1,4 +0,0 @@
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
index 5dbd75e..b4609d7 100644
--- a/DCP/recover.cpp
+++ b/DCP/recover.cpp
@@ -27,17 +27,14 @@ void CalcRecover(IplImage *result, IplImage *input, IplImage *transmission, doub
27 t /= 255.0; 27 t /= 255.0;
28 for (k = 0; k < 3; k++) 28 for (k = 0; k < 3; k++)
29 { 29 {
30 a = *(uchar *)(input->imageData + (i) * widthstep + (j) * nch + k); 30 a = *(uchar *)(input->imageData + i * widthstep + j * nch + k);
31 a /= 255.0; 31 a /= 255.0;
32 32
33 tmp_res = ((a - A[k]) / MAX(t, t0)) + A[k]; 33 tmp_res = ((a - A[k]) / MAX(t, t0)) + A[k];
34 tmp_res *= 255.0;
35 tmp_res = tmp_res > 255 ? 255 : (tmp_res < 0 ? 0 : tmp_res);
34 36
35 if (tmp_res > 1) 37 *(uchar *)(result->imageData + i * widthstep + j * nch + k) = cvRound(tmp_res);
36 tmp_res = 1;
37 else if (tmp_res < 0)
38 tmp_res = 0;
39
40 *(uchar *)(result->imageData + (i) * widthstep + (j) * nch + k) = tmp_res * 255.0;
41 } 38 }
42 } 39 }
43 } 40 }
diff --git a/DCP/test.cpp b/DCP/test.cpp
index 7efeeb7..2af8719 100644
--- a/DCP/test.cpp
+++ b/DCP/test.cpp
@@ -2,13 +2,12 @@
2 2
3int main() 3int main()
4{ 4{
5 IplImage *input = cvLoadImage("input.png"); 5 IplImage *input = cvLoadImage("house-input.bmp");
6 IplImage *result = cvCreateImage(cvGetSize(input), IPL_DEPTH_8U, 3); 6 IplImage *result = cvCreateImage(cvGetSize(input), IPL_DEPTH_8U, 3);
7 dehaze(result, input); 7 dehaze(result, input);
8 8
9 cvNamedWindow("Result"); 9 cvSaveImage("result.bmp", result);
10 cvShowImage("Result", result); 10 cvReleaseImage(&result);
11 cvWaitKey(); 11 cvReleaseImage(&input);
12
13 return 0; 12 return 0;
14} \ No newline at end of file 13}
diff --git a/DCP/transmission.cpp b/DCP/transmission.cpp
index 48a8299..0079ef7 100644
--- a/DCP/transmission.cpp
+++ b/DCP/transmission.cpp
@@ -22,7 +22,7 @@ void CalcTransmission(IplImage *transmission, IplImage *input, double A[], int r
22 tmp = tmp / A[k] * 255.0; 22 tmp = tmp / A[k] * 255.0;
23 23
24 tmp = tmp > 255 ? 255 : tmp; 24 tmp = tmp > 255 ? 255 : tmp;
25 *(uchar *)(normalized_input->imageData + i * widthstep + j * nch + k) = tmp; 25 *(uchar *)(normalized_input->imageData + i * widthstep + j * nch + k) = cvRound(tmp);
26 } 26 }
27 } 27 }
28 } 28 }
@@ -35,11 +35,10 @@ void CalcTransmission(IplImage *transmission, IplImage *input, double A[], int r
35 double tran = *(uchar *)(transmission->imageData + i * gwidthstep + j); 35 double tran = *(uchar *)(transmission->imageData + i * gwidthstep + j);
36 36
37 tran = 1 - w * (tran / 255.0); 37 tran = 1 - w * (tran / 255.0);
38 tran *= 255.0;
39 tran = tran > 255 ? 255 : (tran < 0 ? 0 : tran);
38 40
39 tran = tran > 1 ? 1 : tran; 41 *(uchar *)(transmission->imageData + i * gwidthstep + j) = cvRound(tran);
40 tran = tran < 0 ? 0 : tran;
41
42 *(uchar *)(transmission->imageData + i * gwidthstep + j) = tran * 255;
43 } 42 }
44 } 43 }
45 cvReleaseImage(&normalized_input); 44 cvReleaseImage(&normalized_input);
diff --git a/DCP/utility.h b/DCP/utility.h
new file mode 100644
index 0000000..55cc100
--- /dev/null
+++ b/DCP/utility.h
@@ -0,0 +1,29 @@
1#ifndef UTILITY_H
2#define UTILITY_H
3
4#include <iostream>
5#include <chrono>
6
7class TicToc
8{
9private:
10 typedef std::chrono::high_resolution_clock clock;
11 typedef std::chrono::microseconds res;
12 clock::time_point t1, t2;
13
14public:
15 void tic()
16 {
17 t1 = clock::now();
18 }
19
20 void toc()
21 {
22 t2 = clock::now();
23 std::cout << "Elapsed time: "
24 << std::chrono::duration_cast<res>(t2 - t1).count() / 1e6
25 << " seconds." << std::endl;
26 }
27};
28
29#endif \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)