کاهش نویز تصویر با فیلتر وینر در متلب
کدهای پروژه
function [J,v_noise] = mywiener(I,hsize);
I= im2double(I);
r=hsize(1);
c=hsize(2);
% padding
nr= floor(r/2);
nc= floor(c/2);
J1= padarray(I,[nr nc]);
mu_local=I;
v_local=I;
[rows,cols]= size(J1);
for i=nr+1:rows-nr
for j=nc+1:cols-nc
temp= J1(i-nr:i+nr,j-nc:j+nc);
mu_local(i-nr,j-nc)=mean(temp(:));
v_local(i-nr,j-nc)= var(temp(:));
end
end
%% calculate noise variance
v_noise= mean(v_local(:));
%% apply wiener filter
J2= I;
[rows,cols]= size(I);
for i=1:rows
for j=1:cols
a= I(i,j);
mu= mu_local(i,j);
s2= v_local(i,j);
% b= mu + ((s2 – v_noise)/s2)* (a-mu);% not true
b= mu + (max(s2 – v_noise,0)/max(s2,v_noise))* (a-mu);% true
J2(i,j)= b;
end
end
##########
clc
clear
close all
I= imread(‘coins.png’);
I= im2double(I);
if size(I,3)>1
I= rgb2gray(I);
end
figure
imshow(I)
r=3;
c=3;
% padding
nr= floor(r/2);
nc= floor(c/2);
J1= padarray(I,[nr nc]);
mu_local=I;
mu_local(:,:)=0;
v_local=I;
v_local(:,:)=0;
[rows,cols]= size(J1);
for i=nr+1:rows-nr
for j=nc+1:cols-nc
temp= J1(i-nr:i+nr,j-nc:j+nc);
mu_local(i-nr,j-nc)=mean(temp(:));
v_local(i-nr,j-nc)= var(temp(:));
end
end
%% calculate noise variance
v_noise= mean(v_local(:));
%% wiener filter
J2= I;
J2(:,:)= 0;
[rows,cols]= size(I);
for i=1:rows
for j=1:cols
a= I(i,j);
mu= mu_local(i,j);
s2= v_local(i,j);
% b= mu + ((s2 – v_noise)/s2)* (a-mu);% not true
b= mu + (max(s2 – v_noise,0)/max(s2,v_noise))* (a-mu);% true
J2(i,j)= b;
end
end
figure
imshow(J2)
J=J2;
end
دیدگاهتان را بنویسید