A list,
1. Principle of NLM filtering
2 Pixelwise Implementation
3 Patchwise Implementation
-
Function [output]=NLmeans(input,t,f,h) % input: image to be smoothed % t: search window radius % f: similarity window radius % h: smoothing parameter % NLmeans(ima,5,2,sigma); % image size [m n]=size(input); % Output Output = zeros (m, n); input2 = padarray(input,[f+t f+t],'symmetric'); % kernel = make_kernel(f); kernel = kernel / sum(sum(kernel)); h=h*h; for i=1:m for j=1:n i1 = i+ f+t; % Pixel position of original image (center pixel) j1 = j+ f+t; W1= input2(i1-f:i1+f , j1-f:j1+f); % small window wmax=0; average=0; sweight=0; %rmin = max(i1-t,f+1); %rmax = min(i1+t,m+f); %smin = max(j1-t,f+1); %smax = min(j1+t,n+f); rmin=i1-t; rmax=i1+t; smin=j1-t; smax=j1+t; For r=rmin:1:rmax % for s=smin:1:smax if(r== i1&&s ==j1) continue; end; W2= input2(r-f:r+f , s-f:s+f); % d little similarity search window (window = sum (the sum (kernel. * (W1, W2). * (W1, W2))); w=exp(-d/h); If w>wmax wmax=w; End sweight = sweight + w; % the weight in the large window and Average = average + w*input2(r,s); end end average = average + wmax*input2(i1,j1); sweight = sweight + wmax; if sweight > 0 output(i,j) = average / sweight; else output(i,j) = input(i,j); End end end function nX = noise(varargin) % % X - Image to be processed % Type - Noise type % Variance/Density - Variance of Gaussian noise /density of salt and pepper noise (optional) % M - Template for controlling noise area (optional) % Default parameter variance = 0.01; The default value of % Gaussian noise variance is 0.01 density = 0.05; % salt-pepper noise density default value 0.05m = ones(size(varargin{1})); X = varargin{1}; % Image type = varargin{2}; % Noise type % Optional if nargin>=3 variance = varargin{3}; density = varargin{3}; if nargin == 4 M = varargin{4}; end endCopy the code
3. Operation results
Fourth, note
Complete code or simulation consulting to add QQ1575304183