一. motion blur
运动模糊是我们在日常生活中很常见的一种模糊。当我们按下快门拍照时,如果照片里的事物(或者我们的相机)正在运动的话,我们拍出的照片就会产生运动模糊。
二. motion filter

图1:大小为3*3,对角线方向上的运动模糊算子 ↑

图2:大小为5*5,竖直方向上的运动模糊算子 ↑

使用 图2 这个5*5的竖直方向运动模糊算子作用于清晰图像后产生的图像 ↑
三. python实现3*3的对角线方向的运动模糊滤波器(图1滤波器)
import cv2 import numpy as np # motion filter def motion_filter(img, K_size=3): H, W, C = img.shape # Kernel K = np.diag( [1] * K_size ).astype(np.float) K /= K_size # zero padding pad = K_size // 2 out = np.zeros((H + pad * 2, W + pad * 2, C), dtype=np.float) out[pad: pad + H, pad: pad + W] = img.copy().astype(np.float) tmp = out.copy() # filtering for y in range(H): for x in range(W): for c in range(C): out[pad + y, pad + x, c] = np.sum(K * tmp[y: y + K_size, x: x + K_size, c]) out = out[pad: pad + H, pad: pad + W].astype(np.uint8) return out # Read image img = cv2.imread("../paojie.jpg") # motion filtering out = motion_filter(img, K_size=3) # Save result cv2.imwrite("out.jpg", out) cv2.imshow("result", out) cv2.waitKey(0) cv2.destroyAllWindows()
四. 上面程序的输出结果:

3*3的对角线方向运动模糊算子模糊后的图像 ↑

原图像 ↑
五. 参考内容: