aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJinwei Zhao <[email protected]>2016-01-21 19:53:38 +0800
committerJinwei Zhao <[email protected]>2016-01-21 19:53:38 +0800
commit2c425c06f30ac4be6b0b6d35aab6d390b169efa4 (patch)
tree8aaa2389c0c733f083024a6dc7311b5a07f26442 /MATLAB/guidedfilter.m
parentba1633c59d98341b378ca3da61e9531b5f253c22 (diff)
downloadGuidedFilter-2c425c06f30ac4be6b0b6d35aab6d390b169efa4.tar.gz
add MATLAB code
Diffstat (limited to 'MATLAB/guidedfilter.m')
-rwxr-xr-xMATLAB/guidedfilter.m27
1 files changed, 27 insertions, 0 deletions
diff --git a/MATLAB/guidedfilter.m b/MATLAB/guidedfilter.m
new file mode 100755
index 0000000..9e9595e
--- /dev/null
+++ b/MATLAB/guidedfilter.m
@@ -0,0 +1,27 @@
1function q = guidedfilter(I, p, r, eps)
2% GUIDEDFILTER O(1) time implementation of guided filter.
3%
4% - guidance image: I (should be a gray-scale/single channel image)
5% - filtering input image: p (should be a gray-scale/single channel image)
6% - local window radius: r
7% - regularization parameter: eps
8
9[hei, wid] = size(I);
10N = boxfilter(ones(hei, wid), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels.
11
12mean_I = boxfilter(I, r) ./ N;
13mean_p = boxfilter(p, r) ./ N;
14mean_Ip = boxfilter(I.*p, r) ./ N;
15cov_Ip = mean_Ip - mean_I .* mean_p; % this is the covariance of (I, p) in each local patch.
16
17mean_II = boxfilter(I.*I, r) ./ N;
18var_I = mean_II - mean_I .* mean_I;
19
20a = cov_Ip ./ (var_I + eps); % Eqn. (5) in the paper;
21b = mean_p - a .* mean_I; % Eqn. (6) in the paper;
22
23mean_a = boxfilter(a, r) ./ N;
24mean_b = boxfilter(b, r) ./ N;
25
26q = mean_a .* I + mean_b; % Eqn. (8) in the paper;
27end \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)