文史赏析古今中外

104. 运动模糊退化模型

2025-08-27  本文已影响0人  大龙10

7. 图像复原与重建索引

一、 模型法估计退化函数

二、运动模糊退化模型

三、例程

import cv2
import numpy as np
from matplotlib import pyplot as plt

# 9.18: 运动模糊退化图像 (Motion blur degradation)
def motionBlur(image, degree=10, angle=45):
    image = np.array(image)
    center = (degree/2, degree/2)  # 旋转中心
    M = cv2.getRotationMatrix2D(center, angle, 1)  # 无损旋转
    kernel = np.diag(np.ones(degree) / degree)  # 运动模糊内核
    kernel = cv2.warpAffine(kernel, M, (degree, degree))

    blurred = cv2.filter2D(image, -1, kernel)  # 图像卷积
    blurredNorm = np.uint8(cv2.normalize(blurred, None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]
    return blurredNorm

# 运动模糊图像
img = cv2.imread(r"E:/OpenCV/Fig0507b.tif", 0)  # flags=0 读取为灰度图像

imgBlur1 = motionBlur(img, degree=30, angle=45)
imgBlur2 = motionBlur(img, degree=40, angle=45)
imgBlur3 = motionBlur(img, degree=60, angle=45)

plt.figure(figsize=(9, 6))
plt.subplot(131), plt.title("degree=20"), plt.axis('off'), plt.imshow(imgBlur1, 'gray')
plt.subplot(132), plt.title("degree=40"), plt.axis('off'), plt.imshow(imgBlur2, 'gray')
plt.subplot(133), plt.title("degree=60"), plt.axis('off'), plt.imshow(imgBlur3, 'gray')
plt.tight_layout()
plt.show()

四、资料

youcans_的博客:
https://blog.csdn.net/youcans/article/details/123027195
上一篇 下一篇

猜你喜欢

热点阅读