From 2c425c06f30ac4be6b0b6d35aab6d390b169efa4 Mon Sep 17 00:00:00 2001 From: Jinwei Zhao Date: Thu, 21 Jan 2016 19:53:38 +0800 Subject: add MATLAB code --- MATLAB/guidedfilter.m | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 MATLAB/guidedfilter.m (limited to 'MATLAB/guidedfilter.m') 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 @@ +function q = guidedfilter(I, p, r, eps) +% GUIDEDFILTER O(1) time implementation of guided filter. +% +% - guidance image: I (should be a gray-scale/single channel image) +% - filtering input image: p (should be a gray-scale/single channel image) +% - local window radius: r +% - regularization parameter: eps + +[hei, wid] = size(I); +N = boxfilter(ones(hei, wid), r); % the size of each local patch; N=(2r+1)^2 except for boundary pixels. + +mean_I = boxfilter(I, r) ./ N; +mean_p = boxfilter(p, r) ./ N; +mean_Ip = boxfilter(I.*p, r) ./ N; +cov_Ip = mean_Ip - mean_I .* mean_p; % this is the covariance of (I, p) in each local patch. + +mean_II = boxfilter(I.*I, r) ./ N; +var_I = mean_II - mean_I .* mean_I; + +a = cov_Ip ./ (var_I + eps); % Eqn. (5) in the paper; +b = mean_p - a .* mean_I; % Eqn. (6) in the paper; + +mean_a = boxfilter(a, r) ./ N; +mean_b = boxfilter(b, r) ./ N; + +q = mean_a .* I + mean_b; % Eqn. (8) in the paper; +end \ No newline at end of file -- cgit v1.2.3