matlab图像复原维纳滤波,最小二乘方,L-R,盲去卷积图像复原比较的程序代码

matlab图像复原维纳滤波,最小二乘方,L-R,盲去卷积图像复原比较的程序代码,第1张

clcclear all

%读原始图像%

format long

Blurred=imread('fig525(b).bmp')

subplot(1,2,1)imshow( Blurred)title('原图像')

%自编函数进行维纳滤波%

k=0.0025

[m,n]=size(Blurred)

spectrum=zeros(m,n)

H=zeros(m,n)

for u=1:m

for v=1:n

H(u,v)=exp(-k*((u-m/2)^2+(v-n/2)^2)^(5/6))

spectrum(u,v)=H(u,v)^2

end

end

f=double(Blurred)

F1=fftshift(fft2(f))

HW=H./(spectrum+0.001)

restore1=HW.*F1

restored=real(ifft2(ifftshift(restore1)))

subplot(1,2,2)imshow(restored,[])title('自编函数进行维纳滤波')

%调用matlab提供的维纳滤波函数%

figure

hw1=real(ifft2(ifftshift(H)))%转化到空域上来

result1=deconvwnr(Blurred,hw1,0.001)

result2=ifftshift(result1)%再去图像进行1,3象限对调,2与4象限对调

subplot(1,2,1)imshow(result2,[])title('调用维纳滤波函数')

PSF

=

fspecial('motion',len,ang)

%建立扩散子,其中len是模糊长度,ang是模糊角度

img2=deconvlucy(img,PSF,n)

%用lucy-richardson方法复原图像,其中img是运动模糊图像,PSF是扩散子,n是迭代次数,img2是复原图像

这个问题 建议你百度百科下 就有类似的课程设计or毕设 里面有源代码的

L = input('输入信号样本个数L=')

N = input('输入FIR滤波器阶数N=')

a = 0.95

K = 50

sigma_a2 = 1-a^2

a_ = [1,-a]

while(1)

w = sqrt(sigma_a2)*(randn(L,1))%获得方差为sigma_a2的高斯白噪声w

v = randn(L,1) %获得方差为1的高斯白噪声v

s(1) = w(1)%通过公式:s(n) = a*s(n-1)+wn(n)获得源信号s与加了噪声v的x

for i=1:L-1

s(i+1)=a*s(i)+w(i+1)

x(i) = s(i)+v(i)

end

x(L) = s(L)+v(L)

%%%%%%%%%%%%%%%%%估计相关函数r_xx和r_xs%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i=1:K+1

rxx(i)=sum(x(i:L).*x(1:L-i+1))/(L-i+1)

end

r_xx_g=[rxx(K+1:-1:2),rxx(1:K+1)]

for i=1:K+1

rxs(i)=sum(x(i:L).*s(1:L-i+1))/(L-i+1)

end

r_xs_g=[rxs(K+1:-1:2),rxs(1:K+1)]

%%%%%%%%%%%%%%检验x的r_xx和r_xs是否与理论值相符%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

r_xx_t = a.^abs([-K:K])

r_xx_t(K+1) = r_xx_t(K+1)+1

r_xs_t = a.^abs([-K:K])

rou_xx=(sum((r_xx_g-r_xx_t).^2))/sum(r_xx_t.^2)

rou_xs=(sum(r_xs_g-r_xs_t).^2)/sum(r_xs_t.^2)

if rou_xx<0.03 &rou_xs<0.01

break

end

end

%%%%%%%%%%%%%%x(n)的自相关函数的理论值(红色)和实际值(蓝色)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(1)

stem(r_xx_t,'r')

hold on

stem(r_xx_g,'*','b')

title('x(n)的自相关函数的理论值和实际值(*)')

%%%%%%%%%%%%%%最后100个s(n)(红色)和x(n)(蓝色)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

figure(2)

stem(s(L-100:L),'r')

hold on

stem(x(L-100:L),'*','b')

title('最后100个s(n)和x(n)(*)')

%%%%%%%%%%%%%%N个理想h(n)(h_t红色)估计h(n)(h_g蓝色)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

n = 0:N-1

h_t = 0.238*(0.724).^n%求得理想的h(n)

for i=1:N

xx(i)=sum(x(i:L).*x(1:L-i+1))/(L-i+1)

end

for i=1:N

Rxx(i,1:N)=[xx(i:-1:1),xx(2:N+1-i)]

end

for i=1:N

xs(i)=sum(x(i:L).*s(1:L-i+1))/(L-i+1)

end

invRxx=inv(Rxx)

h_g=invRxx*xs' %估计h

figure(3)

stem(h_t,'r')

hold on

stem(h_g,'*','b')

title('N个理想h(n)(h_t)估计h(n)(*h_g)')

%%%%%%%%%%%%%%最后100个s(n)(红色)理想维纳滤波S_l(n)(蓝色)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

y_l(1) = s(1)%得到理想维纳滤波的S(n)

for i = 1:L-1

y_l(i+1) = 0.724*s(i)+0.238*x(i+1)

end

figure(4)

stem(s(L-100:L),'r')

hold on

stem(y_l(L-100:L),'*','b')

title('最后100个s(n)理想维纳滤波S_R(n)(*)')

%%%%%%%%%%%%%%最后100个s(n)(红色)根据式FIR滤波S_R(n)(蓝色)%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i=1:9 %得到FIR维纳滤波的S(n)

y_F(i)=sum(h_g(1:i)'.*x(i:-1:1))

end

for i=10:L

y_F(i)=sum(h_g'.*x(i:-1:i-9))

end

figure(5)

stem(s(L-100:L),'r')

hold on

stem(y_F(L-100:L),'*','b')

title('最后100个s(n)根据式FIR滤波S_R(n)(*)')

%%%%%%%%%%%%%%%%%求均方误差%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

e_x=sum((x-s(1:L)).^2)/L%求各自的均方误差

e_i=sum((y_l-s(1:L)).^2)/L

e_f=sum((y_F-s(1:L)).^2)/L


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8115708.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-13
下一篇 2023-04-13

发表评论

登录后才能评论

评论列表(0条)

保存