aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xGuidedFilter/GuidedFilter.sln22
-rwxr-xr-xGuidedFilter/GuidedFilter/GuidedFilter.vcxproj90
-rwxr-xr-xGuidedFilter/GuidedFilter/GuidedFilter.vcxproj.filters30
-rwxr-xr-xGuidedFilter/GuidedFilter/OpenCV3.props16
-rwxr-xr-xGuidedFilter/GuidedFilter/guide.pngbin0 -> 389646 bytes
-rwxr-xr-xGuidedFilter/GuidedFilter/guidedfilter.cpp202
-rwxr-xr-xGuidedFilter/GuidedFilter/guidedfilter.h15
-rwxr-xr-xGuidedFilter/GuidedFilter/src.bmpbin0 -> 315478 bytes
-rwxr-xr-xGuidedFilter/GuidedFilter/test.cpp18
9 files changed, 393 insertions, 0 deletions
diff --git a/GuidedFilter/GuidedFilter.sln b/GuidedFilter/GuidedFilter.sln
new file mode 100755
index 0000000..c4c2744
--- /dev/null
+++ b/GuidedFilter/GuidedFilter.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}") = "GuidedFilter", "GuidedFilter\GuidedFilter.vcxproj", "{7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}"
7EndProject
8Global
9 GlobalSection(SolutionConfigurationPlatforms) = preSolution
10 Debug|Win32 = Debug|Win32
11 Release|Win32 = Release|Win32
12 EndGlobalSection
13 GlobalSection(ProjectConfigurationPlatforms) = postSolution
14 {7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}.Debug|Win32.ActiveCfg = Debug|Win32
15 {7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}.Debug|Win32.Build.0 = Debug|Win32
16 {7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}.Release|Win32.ActiveCfg = Release|Win32
17 {7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}.Release|Win32.Build.0 = Release|Win32
18 EndGlobalSection
19 GlobalSection(SolutionProperties) = preSolution
20 HideSolutionNode = FALSE
21 EndGlobalSection
22EndGlobal
diff --git a/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj b/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj
new file mode 100755
index 0000000..2d4af0e
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj
@@ -0,0 +1,90 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ItemGroup Label="ProjectConfigurations">
4 <ProjectConfiguration Include="Debug|Win32">
5 <Configuration>Debug</Configuration>
6 <Platform>Win32</Platform>
7 </ProjectConfiguration>
8 <ProjectConfiguration Include="Release|Win32">
9 <Configuration>Release</Configuration>
10 <Platform>Win32</Platform>
11 </ProjectConfiguration>
12 </ItemGroup>
13 <PropertyGroup Label="Globals">
14 <ProjectGuid>{7E8D3A00-45B3-448F-96C6-E5A87C57BCD3}</ProjectGuid>
15 <Keyword>Win32Proj</Keyword>
16 <RootNamespace>GuidedFilter</RootNamespace>
17 </PropertyGroup>
18 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
19 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
20 <ConfigurationType>Application</ConfigurationType>
21 <UseDebugLibraries>true</UseDebugLibraries>
22 <PlatformToolset>v120</PlatformToolset>
23 <CharacterSet>Unicode</CharacterSet>
24 </PropertyGroup>
25 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
26 <ConfigurationType>Application</ConfigurationType>
27 <UseDebugLibraries>false</UseDebugLibraries>
28 <PlatformToolset>v120</PlatformToolset>
29 <WholeProgramOptimization>true</WholeProgramOptimization>
30 <CharacterSet>Unicode</CharacterSet>
31 </PropertyGroup>
32 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
33 <ImportGroup Label="ExtensionSettings">
34 </ImportGroup>
35 <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
36 <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
37 <Import Project="OpenCV3.props" />
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 <Import Project="OpenCV3.props" />
42 </ImportGroup>
43 <PropertyGroup Label="UserMacros" />
44 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
45 <LinkIncremental>true</LinkIncremental>
46 </PropertyGroup>
47 <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
48 <LinkIncremental>false</LinkIncremental>
49 </PropertyGroup>
50 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
51 <ClCompile>
52 <PrecompiledHeader>
53 </PrecompiledHeader>
54 <WarningLevel>Level3</WarningLevel>
55 <Optimization>Disabled</Optimization>
56 <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
57 </ClCompile>
58 <Link>
59 <SubSystem>Console</SubSystem>
60 <GenerateDebugInformation>true</GenerateDebugInformation>
61 </Link>
62 </ItemDefinitionGroup>
63 <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
64 <ClCompile>
65 <WarningLevel>Level3</WarningLevel>
66 <PrecompiledHeader>
67 </PrecompiledHeader>
68 <Optimization>MaxSpeed</Optimization>
69 <FunctionLevelLinking>true</FunctionLevelLinking>
70 <IntrinsicFunctions>true</IntrinsicFunctions>
71 <PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
72 </ClCompile>
73 <Link>
74 <SubSystem>Console</SubSystem>
75 <GenerateDebugInformation>true</GenerateDebugInformation>
76 <EnableCOMDATFolding>true</EnableCOMDATFolding>
77 <OptimizeReferences>true</OptimizeReferences>
78 </Link>
79 </ItemDefinitionGroup>
80 <ItemGroup>
81 <ClInclude Include="guidedfilter.h" />
82 </ItemGroup>
83 <ItemGroup>
84 <ClCompile Include="guidedfilter.cpp" />
85 <ClCompile Include="test.cpp" />
86 </ItemGroup>
87 <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
88 <ImportGroup Label="ExtensionTargets">
89 </ImportGroup>
90</Project> \ No newline at end of file
diff --git a/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj.filters b/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj.filters
new file mode 100755
index 0000000..06fa319
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/GuidedFilter.vcxproj.filters
@@ -0,0 +1,30 @@
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 <ClInclude Include="guidedfilter.h">
19 <Filter>Header Files</Filter>
20 </ClInclude>
21 </ItemGroup>
22 <ItemGroup>
23 <ClCompile Include="guidedfilter.cpp">
24 <Filter>Source Files</Filter>
25 </ClCompile>
26 <ClCompile Include="test.cpp">
27 <Filter>Source Files</Filter>
28 </ClCompile>
29 </ItemGroup>
30</Project> \ No newline at end of file
diff --git a/GuidedFilter/GuidedFilter/OpenCV3.props b/GuidedFilter/GuidedFilter/OpenCV3.props
new file mode 100755
index 0000000..1cdcd81
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/OpenCV3.props
@@ -0,0 +1,16 @@
1<?xml version="1.0" encoding="utf-8"?>
2<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3 <ImportGroup Label="PropertySheets" />
4 <PropertyGroup Label="UserMacros" />
5 <PropertyGroup />
6 <ItemDefinitionGroup>
7 <ClCompile>
8 <AdditionalIncludeDirectories>F:\3rdLibs\OpenCV3\opencv_build_with_contrib\install\x86\vc12\..\..\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
9 </ClCompile>
10 <Link>
11 <AdditionalLibraryDirectories>F:\3rdLibs\OpenCV3\opencv_build_with_contrib\install\x86\vc12\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
12 <AdditionalDependencies>opencv_calib3d300d.lib;opencv_core300d.lib;opencv_features2d300d.lib;opencv_flann300d.lib;opencv_hal300d.lib;opencv_highgui300d.lib;opencv_imgcodecs300d.lib;opencv_imgproc300d.lib;opencv_ml300d.lib;opencv_objdetect300d.lib;opencv_photo300d.lib;opencv_shape300d.lib;opencv_stitching300d.lib;opencv_superres300d.lib;opencv_ts300d.lib;opencv_video300d.lib;opencv_videoio300d.lib;opencv_videostab300d.lib;opencv_ximgproc300d.lib;%(AdditionalDependencies)</AdditionalDependencies>
13 </Link>
14 </ItemDefinitionGroup>
15 <ItemGroup />
16</Project> \ No newline at end of file
diff --git a/GuidedFilter/GuidedFilter/guide.png b/GuidedFilter/GuidedFilter/guide.png
new file mode 100755
index 0000000..cbee301
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/guide.png
Binary files differ
diff --git a/GuidedFilter/GuidedFilter/guidedfilter.cpp b/GuidedFilter/GuidedFilter/guidedfilter.cpp
new file mode 100755
index 0000000..92c2913
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/guidedfilter.cpp
@@ -0,0 +1,202 @@
1#include "guidedfilter.h"
2
3void GuidedFilterMono(Mat guide, Mat src, Mat dst, int radius, double eps);
4void GuidedFilterColor(Mat guide, Mat src, Mat dst, int radius, double eps);
5
6void GuidedFilter(Mat guide, Mat src, Mat dst, int radius, double eps)
7{
8 int depth = guide.channels();
9 CV_Assert(depth == 1 || depth == 3);
10
11 if (depth == 3)
12 GuidedFilterColor(guide, src, dst, radius, eps);
13 else if (depth == 1)
14 GuidedFilterMono(guide, src, dst, radius, eps);
15}
16
17void GuidedFilterColor(Mat guide, Mat src, Mat dst, int radius, double eps)
18{
19 int height = src.rows;
20 int width = src.cols;
21 int widthstep = guide.step;
22 int gwidthstep = src.step;
23 int nch = guide.elemSize();
24 int gnch = src.elemSize();
25
26 int i, j;
27 int m, n;
28 int w;
29 int e = 0;
30 int st_row, ed_row;
31 int st_col, ed_col;
32
33 double sum_Ir, sum_Ig, sum_Ib;
34 double sum_Ir_square, sum_Ig_square, sum_Ib_square;
35 double sum_IrIg, sum_IgIb, sum_IrIb;
36 double sum_PiIr, sum_PiIg, sum_PiIb;
37 double sum_Pi;
38
39 double A, B, C, D, E, F, G, H, I, J, K, L;
40 double X, Y, Z;
41 double ak_r, ak_g, ak_b;
42 double bk;
43 double det;
44
45 double tmp_Ir, tmp_Ig, tmp_Ib;
46 double tmp_p, tmp_q;
47
48 double *v_ak_r = (double *)malloc(sizeof(double) * height * width);
49 double *v_ak_g = (double *)malloc(sizeof(double) * height * width);
50 double *v_ak_b = (double *)malloc(sizeof(double) * height * width);
51 double *v_bk = (double *)malloc(sizeof(double) * height * width);
52
53 int count = 0;
54
55 uchar *data_guide = guide.data;
56 uchar *data_src = src.data;
57 uchar *data_dst = dst.data;
58
59 for (i = 0; i < height; i++)
60 {
61 for (j = 0; j < width; j++)
62 {
63 st_row = i - radius, ed_row = i + radius;
64 st_col = j - radius, ed_col = j + radius;
65
66 st_row = st_row < 0 ? 0 : st_row;
67 ed_row = ed_row >= height ? (height - 1) : ed_row;
68 st_col = st_col < 0 ? 0 : st_col;
69 ed_col = ed_col >= width ? (width - 1) : ed_col;
70
71 sum_Ir = sum_Ig = sum_Ib = 0;
72 sum_Ir_square = sum_Ig_square = sum_Ib_square = 0;
73 sum_IrIg = sum_IgIb = sum_IrIb = 0;
74 sum_PiIr = sum_PiIg = sum_PiIb = 0;
75 sum_Pi = 0;
76 w = 0;
77
78 for (m = st_row; m <= ed_row; m++)
79 {
80 for (n = st_col; n <= ed_col; n++)
81 {
82 tmp_Ib = *(data_guide + m * widthstep + n * nch);
83 tmp_Ig = *(data_guide + m * widthstep + n * nch + 1);
84 tmp_Ir = *(data_guide + m * widthstep + n * nch + 2);
85
86 tmp_p = *(data_src + m * gwidthstep + n * gnch);
87
88 sum_Ib += tmp_Ib;
89 sum_Ig += tmp_Ig;
90 sum_Ir += tmp_Ir;
91
92 sum_Ib_square += tmp_Ib * tmp_Ib;
93 sum_Ig_square += tmp_Ig * tmp_Ig;
94 sum_Ir_square += tmp_Ir * tmp_Ir;
95
96 sum_IrIg += tmp_Ir * tmp_Ig;
97 sum_IgIb += tmp_Ig * tmp_Ib;
98 sum_IrIb += tmp_Ir * tmp_Ib;
99
100 sum_Pi += tmp_p;
101 sum_PiIb += tmp_p * tmp_Ib;
102 sum_PiIg += tmp_p * tmp_Ig;
103 sum_PiIr += tmp_p * tmp_Ir;
104
105 w++;
106 }
107 }
108
109 A = (sum_Ir_square + w * eps) * sum_Ig - sum_Ir * sum_IrIg;
110 B = sum_IrIg * sum_Ig - sum_Ir * (sum_Ig_square + w * eps);
111 C = sum_IrIb * sum_Ig - sum_Ir * sum_IgIb;
112 D = sum_PiIr * sum_Ig - sum_PiIg * sum_Ir;
113 E = (sum_Ir_square + w * eps) * sum_Ib - sum_IrIb * sum_Ir;
114 F = sum_IrIg * sum_Ib - sum_IgIb * sum_Ir;
115 G = sum_IrIb * sum_Ib - (sum_Ib_square + w * eps) * sum_Ir;
116 H = sum_PiIr * sum_Ib - sum_PiIb * sum_Ir;
117 I = (sum_Ir_square + w * eps) * w - sum_Ir * sum_Ir;
118 J = sum_IrIg * w - sum_Ig * sum_Ir;
119 K = sum_IrIb * w - sum_Ib * sum_Ir;
120 L = sum_PiIr * w - sum_Pi * sum_Ir;
121
122 det = A * F * K + B * G * I + C * E * J - C * F * I - A * G * J - B * E * K;
123 X = D * F * K + B * G * L + C * H * J - C * F * L - D * G * J - B * H * K;
124 Y = A * H * K + D * G * I + C * E * L - C * H * I - D * E * K - A * G * L;
125 Z = A * F * L + B * H * I + D * J * E - D * F * I - B * E * L - A * H * J;
126
127 ak_r = X / det;
128 ak_g = Y / det;
129 ak_b = Z / det;
130
131 bk = (sum_PiIg - sum_IrIg * ak_r - (sum_Ig_square + w * eps) * ak_g - sum_IgIb * ak_b) / sum_Ig;
132
133 tmp_Ib = *(data_guide + i * widthstep + j * nch);
134 tmp_Ig = *(data_guide + i * widthstep + j * nch + 1);
135 tmp_Ir = *(data_guide + i * widthstep + j * nch + 2);
136
137 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
138 tmp_q = tmp_q > 255 ? 255 : (tmp_q < 0 ? 0 : tmp_q);
139
140 *(data_dst + i * gwidthstep + j * gnch) = cvRound(tmp_q);
141
142 v_ak_b[count] = ak_b;
143 v_ak_g[count] = ak_g;
144 v_ak_r[count] = ak_r;
145 v_bk[count] = bk;
146 count++;
147 }
148 }
149
150 for (int i = 0; i < height; i++)
151 {
152 for (int j = 0; j < width; j++)
153 {
154 st_row = i - radius, ed_row = i + radius;
155 st_col = j - radius, ed_col = j + radius;
156
157 st_row = st_row < 0 ? 0 : st_row;
158 ed_row = ed_row >= height ? (height - 1) : ed_row;
159 st_col = st_col < 0 ? 0 : st_col;
160 ed_col = ed_col >= width ? (width - 1) : ed_col;
161
162 double ak_r, ak_g, ak_b, bk;
163 ak_r = ak_g = ak_b = bk = 0;
164
165 int number = 0;
166 for (int m = st_row; m <= ed_row; m++)
167 {
168 for (int n = st_col; n <= ed_col; n++)
169 {
170 ak_r += v_ak_r[(m) * width + n];
171 ak_g += v_ak_g[(m) * width + n];
172 ak_b += v_ak_b[(m) * width + n];
173 bk += v_bk[(m) * width + n];
174 number++;
175 }
176 }
177
178 ak_r /= number;
179 ak_g /= number;
180 ak_b /= number;
181 bk /= number;
182
183 tmp_Ib = *(data_guide + i * widthstep + j * nch);
184 tmp_Ig = *(data_guide + i * widthstep + j * nch + 1);
185 tmp_Ir = *(data_guide + i * widthstep + j * nch + 2);
186
187 tmp_q = ak_b * tmp_Ib + ak_g * tmp_Ig + ak_r * tmp_Ir + bk;
188 tmp_q = tmp_q > 255 ? 255 : (tmp_q < 0 ? 0 : tmp_q);
189
190 *(data_dst + i * gwidthstep + j * gnch) = cvRound(tmp_q);
191 }
192 }
193 free(v_ak_b);
194 free(v_ak_g);
195 free(v_ak_r);
196 free(v_bk);
197}
198
199void GuidedFilterMono(Mat guide, Mat src, Mat dst, int radius, double eps)
200{
201
202} \ No newline at end of file
diff --git a/GuidedFilter/GuidedFilter/guidedfilter.h b/GuidedFilter/GuidedFilter/guidedfilter.h
new file mode 100755
index 0000000..1b4db66
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/guidedfilter.h
@@ -0,0 +1,15 @@
1#ifndef GUIDED_FILTER_H
2#define GUIDED_FILTER_H
3
4#include <opencv\cv.h>
5#include <opencv\highgui.h>
6#include <opencv2\opencv.hpp>
7#include <opencv2\ximgproc.hpp>
8
9using namespace cv;
10
11#include <stdio.h>
12
13void GuidedFilter(Mat guide, Mat src, Mat dst, int radius, double eps);
14
15#endif
diff --git a/GuidedFilter/GuidedFilter/src.bmp b/GuidedFilter/GuidedFilter/src.bmp
new file mode 100755
index 0000000..58d8485
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/src.bmp
Binary files differ
diff --git a/GuidedFilter/GuidedFilter/test.cpp b/GuidedFilter/GuidedFilter/test.cpp
new file mode 100755
index 0000000..e0dc95d
--- /dev/null
+++ b/GuidedFilter/GuidedFilter/test.cpp
@@ -0,0 +1,18 @@
1#include "guidedfilter.h"
2
3int main()
4{
5 Mat src = imread("src.bmp", IMREAD_GRAYSCALE);
6 Mat guide = imread("guide.png");
7 Mat dst_own(src.rows, src.cols, CV_8UC1, Scalar(0));
8 Mat dst_opencv(src.rows, src.cols, CV_8UC1, Scalar(0));
9
10 GuidedFilter(guide, src, dst_own, 3, 1e-6);
11 imwrite("own.bmp", dst_own);
12
13 cv::ximgproc::guidedFilter(guide, src, dst_opencv, 3, 1e-6);
14 imwrite("opencv.bmp", dst_opencv);
15
16 printf("Done");
17 return 0;
18} \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)