引导滤波的MATLAB代码
时间: 2023-04-01 11:03:49 浏览: 216
引导滤波.zip_usingiya_引导滤波_引导滤波代码
以下是引导滤波的MATLAB代码:
function [filteredSignal] = guidedfilter(I, p, r, eps)
% GUIDEDFILTER O(N) 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
%
% References:
% [1] K. He, J. Sun, and X. Tang, "Guided Image Filtering,"
% IEEE Transactions on Pattern Analysis and Machine Intelligence,
% Vol. 35, No. 6, pp. 1397-1409, June 2013.
% [2] http://kaiminghe.com/eccv10/
%
% Author: Kaiming He
% Email: kaiminghe@gmail.com
% Date: 04/17/2012
% Precompute mean values
mean_I = boxfilter(I, r) ./ (r^2);
mean_p = boxfilter(p, r) ./ (r^2);
mean_Ip = boxfilter(I.*p, r) ./ (r^2);
mean_II = boxfilter(I.*I, r) ./ (r^2);
% Compute covariance matrix of I and p in each local patch.
cov_Ip = mean_Ip - mean_I .* mean_p;
var_I = mean_II - mean_I .* mean_I;
% Compute a and b
a = cov_Ip ./ (var_I + eps);
b = mean_p - a .* mean_I;
% Compute mean value of a and b in each local patch
mean_a = boxfilter(a, r) ./ (r^2);
mean_b = boxfilter(b, r) ./ (r^2);
% Compute filtered output
filteredSignal = mean_a .* I + mean_b;
end
注意:以上代码仅供参考,使用时请自行验证。
阅读全文