自适应滤波器设计及Matlab实现,附程序代码 下载本文

if classChanged,

f = changeclass(classin, f);

%使图像矩阵的数据类型与输入时相同 end %%%

%%% Subfunction ParseInputs %%%

function [g, nhood, block, noise, msg] = ParseInputs(varargin) g = []; nhood = [3 3]; block = []; noise = []; msg = '';

switch nargin%表示输入参数个数的系统参数 case 0

msg = 'Too few input arguments.'; return; case 1

% wiener2(I)

g = varargin{1};%把输入的第一个参数赋值给g case 2

g = varargin{1};

switch prod(size(varargin{2}))

case 1

% wiener2(I,noise)

noise = varargin{2}; case 2

% wiener2(I,[m n])

nhood = varargin{2}; otherwise

msg = 'Invalid input syntax'; return; end case 3

g = varargin{1};

if (prod(size(varargin{3})) == 2)

% wiener2(I,[m n],[mblock nblock]) OBSOLETE

warning(['WIENER2(I,[m n],[mblock nblock]) is an obsolete syntax.',...

nhood = varargin{2}; block = varargin{3}; else

% wiener2(I,[m n],noise) nhood = varargin{2}; noise = varargin{3};

'Omit the block size, the image matrix is processed all at once.']);

end case 4

% wiener2(I,[m n],[mblock nblock],noise) OBSOLETE

warning(['WIENER2(I,[m n],[mblock nblock],noise) is an obsolete syntax.',... 'Omit the block size, the image matrix is processed all at once.']); g = varargin{1}; nhood = varargin{2}; block = varargin{3}; noise = varargin{4}; otherwise

msg = 'Too many input arguments.'; return; end

% checking if input image is a truecolor image-not supported by WIENER2 if (ndims(g) == 3)%判断是否为三维图像

msg = 'WIENER2 does not support 3D truecolor images as an input.'; return; end;

if (isempty(block))

block = bestblk(size(g));

附录C

% iterative wiener filter clear all; tic

% orignal image I=checkerboard(2); % num of iterations num_iter=128;

for snr =20% 20:10:40 ? res = size(I,1) % image size res2 = res^2 % image size square %%% degradation %%%

h=[6;1;1;1;1;1;zeros(res2-11,1);1;1;1;1;1]; % blur h=h/sum(h); % normalize Dh= fft(h); % diagonal

for c=1:1 % process RGB components individually f=I; % orignal

f_vec=reshape(f, res2,1); % vector image mn_f=mean(f_vec); % mean

amp_f = norm(f_vec)/res; % amplitude

noise_vec = randn(res2, 1)*amp_f/10^(snr/20); % Guassian noise given SNR Dn = abs(fft(noise_vec )).^2/res2; % psd of noise %%% observation %%% g_vec = noise_vec;

for i=1:res2 % degraded image

g_vec(i) = g_vec(i) + [h(res2-i+2: res2)', h(1:res2-i+1)']*f_vec; % H %is circulant matrix end

mn_g = mean(g_vec);

g_vec = g_vec -mn_g; % forced to be zero-mean Dg = abs(fft(g_vec )).^2/res2; % psd of degraded image

%%%%%%%%%%%% Wiener %%%%%%%%%%%%%%% Df = Dg; % basic iterative