⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 denoise.m

📁 You need to download the general purpose toolbox and the signal toolbox. You need to unzip these
💻 M
字号:
function y = denoise(M,k,weight_fun)

% denoise - denoise an image.
%
%   y = denoise(M,k,weight_fun);
%
%   'k' is the size of the neighborhood (ie the square
%   taken around each pixel is of size (2k+1)x(2k+1)).
%   
%   Copyright (c) 2004 Gabriel Peyr

if nargin<2
    k = 3;
end
if nargin<3
    weight_fun = @weight_lin;
end

n = length(M);
y = zeros(n);



for i = k+1:n-k
    for j = k+1:n-k
        
        % current windows
        M1 = M(i-k:i+k,j-k:j+k);
        % compute distance matrix
        dist = zeros(n,n) + Inf;
        for i1 = k+1:n-k
            for j1 = k+1:n-k
                M2 = M(i1-k:i1+k,j1-k:j1+k);   % difference image
                dist(i1,j1) = norm(M2-M1,'fro');
            end
        end
        dist = dist/(2*k+1)^2;
        w = feval(weight_fun,dist);
        w = w ./ sum(sum(w));
        
%         I = find(w>0);
%         for s = I';
%             [i1,j1] = ind2sub(size(M),s);
%             y(i,j) = y(i,j) + w(i1,j1) * M(i1,j1);
%         end

for i1 = k+1:n-k
    for j1 = k+1:n-k
        y(i,j) = y(i,j) + w(i1,j1) * M(i1,j1);
    end
end
        
    end
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -