数字图像处理python实现-图像复原之维纳滤波

数字图像处理python实现-图像复原之维纳滤波内容简介
运动模糊核⽅向和⾓度估计
这⾥介绍⼀种通⽤的做法即倒谱法如下:
这⾥需要注意的是公式中的I 是傅⽴叶变换后的其他的就是公式中的步骤
代码如下:
def main():
摆摆歌
f = plt.imread("pic_hd.jpg")
f = cv.cvtColor(f, cv.COLOR_RGB2GRAY)
# ⽣成倒谱图
ft = np.fft.fft2(f)
ift = np.fft.fftshift(np.abs(np.fft.fft2(np.log(ft +1e-3))))
瓶颈工序logF = np.log(ift +1e-3)
plt.figure()
show(ift,"original",1,2,1)
show(logF,"cepstrum",1,2,2)
plt.show()
最优运动模糊核长度和⾓度确定
按上⾯的倒谱图最终估计到的图像长度,⾓度组合有很多,因此就需要到⼀个最优的长度和⾓度这⾥使⽤的是使⽤局部光滑区域拉普拉斯变换确定最优运动模糊核长度和⾓度
代码如下:这⾥代码对接的上⾯代码
def main():
line = cv.HoughLinesP(ift.astype(np.uint8),1, np.pi /180,20,0,25,0)
甲型血友病l =[]
for i in range(len(line)):
r = np.power((line[i][0][2]- line[i][0][0])**2+(line[i][0][3]- line[i][0][1])**2,0.5)
theta = math.atan2(line[i][0][3]- line[i][0][1], line[i][0][2]- line[i][0][0])/ math.pi *180.
if20< r <50and30< theta <60:
l.append((r,-theta))
# 使⽤局部光滑区域拉普拉斯变换确定最优运动模糊核长度和⾓度
硅溶胶
vars=[]
kernel = np.array([0,-1,0,-1,4,-1,0,-1,0]).reshape(3,3)
for k in l:
r, theta = k
PSF = get_motion_dsf(f.shape,int(r),int(theta))
rf = wiener(f, PSF,0.0001)
temp = rf[425:450,325:350]
for i in range(1, temp.shape[0]-1):
for j in range(1, temp.shape[1]-1):
temp[i, j]= np.abs(np.sum(temp[i -1:i +2, j -1:j +2]* kernel))
vars.append(np.sum(temp))
r, theta = l[vars.index(min(vars))]
print(r)
print(theta)
运动模糊核⽣成
这⾥使⽤的是⽹上的常见代码,我也不太懂引⽤谁的,其中我需要建议读者看数字图像书的⼀页会豁然开朗如下:
其实我看了很多⽂章但是没有⼀篇⽂章解释过,尺⼨问题以及后⾯的运动模糊核⽣成的步骤,这⼀页我认为这是读者需要仔细看的代码如下:
def get_motion_dsf(image_size, motion_dis, motion_angle):
PSF = np.zeros(image_size)# 点扩散函数
x_center =(image_size[0]-1)/2
y_center =(image_size[1]-1)/2
sin_val = math.sin(motion_angle * math.pi /180)
cos_val = s(motion_angle * math.pi /180)
过氧化氢酶活性测定# 将对应⾓度上motion_dis个点置成1
for i in range(motion_dis):
x_offset =round(sin_val * i)
y_offset =round(cos_val * i)
PSF[int(x_center - x_offset),int(y_center + y_offset)]=1
return np.fft.fft2(PSF / PSF.sum())
维纳滤波
这⾥的简介引⽤的是中科院光电研究所师兄的⼀篇论⽂的论述如下
步骤推导,这⾥给出中科院讲义如下:
下⾯给出整个复原过程所有代码如下:
import math
import math
import cv2
import cv2 as cv
import matplotlib.pyplot as plt唐山师范学院刘丹
import numpy as np
# 模糊核⽣成
def get_motion_dsf(image_size, motion_dis, motion_angle):    PSF = np.zeros(image_size)# 点扩散函数
x_center =(image_size[0]-1)/2
y_center =(image_size[1]-1)/2
sin_val = math.sin(motion_angle * math.pi /180)
cos_val = s(motion_angle * math.pi /180)
# 将对应⾓度上motion_dis个点置成1
for i in range(motion_dis):
x_offset =round(sin_val * i)
y_offset =round(cos_val * i)
PSF[int(x_center - x_offset),int(y_center + y_offset)]=1 return np.fft.fft2(PSF / PSF.sum())
# 维纳滤波
def wiener(f, PSF,K=0.01):# 维纳滤波,K=0.01
input_fft = np.fft.fft2(f)
PSF_fft_1 = np.conj(PSF)/(np.abs(PSF)**2+ K)
result = np.fft.ifftshift(np.fft.ifft2(input_fft * PSF_fft_1)) al

本文发布于:2024-09-22 16:43:10,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/477284.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:需要   长度   代码   测定   种通   篇论   给出   变换
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议