运动模糊核方向和角度估计
这里介绍一种通用的做法即倒谱法如下:
这里需要注意的是公式中的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]