一. 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的對角線方向運動模糊算子模糊后的圖像 ↑

原圖像 ↑
五. 參考內容: