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/boxfilter.m
parentba1633c59d98341b378ca3da61e9531b5f253c22 (diff)
downloadGuidedFilter-2c425c06f30ac4be6b0b6d35aab6d390b169efa4.tar.gz
add MATLAB code
Diffstat (limited to 'MATLAB/boxfilter.m')
-rwxr-xr-xMATLAB/boxfilter.m27
1 files changed, 27 insertions, 0 deletions
diff --git a/MATLAB/boxfilter.m b/MATLAB/boxfilter.m
new file mode 100755
index 0000000..9990fa6
--- /dev/null
+++ b/MATLAB/boxfilter.m
@@ -0,0 +1,27 @@
1function imDst = boxfilter(imSrc, r)
2
3% BOXFILTER O(1) time box filtering using cumulative sum
4%
5% - Definition imDst(x, y)=sum(sum(imSrc(x-r:x+r,y-r:y+r)));
6% - Running time independent of r;
7% - Equivalent to the function: colfilt(imSrc, [2*r+1, 2*r+1], 'sliding', @sum);
8% - But much faster.
9
10[hei, wid] = size(imSrc);
11imDst = zeros(size(imSrc));
12
13%cumulative sum over Y axis
14imCum = cumsum(imSrc, 1);
15%difference over Y axis
16imDst(1:r+1, :) = imCum(1+r:2*r+1, :);
17imDst(r+2:hei-r, :) = imCum(2*r+2:hei, :) - imCum(1:hei-2*r-1, :);
18imDst(hei-r+1:hei, :) = repmat(imCum(hei, :), [r, 1]) - imCum(hei-2*r:hei-r-1, :);
19
20%cumulative sum over X axis
21imCum = cumsum(imDst, 2);
22%difference over Y axis
23imDst(:, 1:r+1) = imCum(:, 1+r:2*r+1);
24imDst(:, r+2:wid-r) = imCum(:, 2*r+2:wid) - imCum(:, 1:wid-2*r-1);
25imDst(:, wid-r+1:wid) = repmat(imCum(:, wid), [1, r]) - imCum(:, wid-2*r:wid-r-1);
26end
27
Powered by cgit v1.2.3 (git 2.41.0)