如何为numpy数组添加运动模糊

问题描述 投票:2回答:3

我有一个来自图像的numpy数组

那么,有没有一个好方法: from PIL import Image a = Image.open('img') a = a.filter(MOTION_BLUR)

python image python-imaging-library blur
3个回答
6
投票
import cv2
import numpy as np

img = cv2.imread('input.jpg')
cv2.imshow('Original', img)

size = 15

# generating the kernel
kernel_motion_blur = np.zeros((size, size))
kernel_motion_blur[int((size-1)/2), :] = np.ones(size)
kernel_motion_blur = kernel_motion_blur / size

# applying the kernel to the input image
output = cv2.filter2D(img, -1, kernel_motion_blur)

cv2.imshow('Motion Blur', output)
cv2.waitKey(0)

解释你可以找到here


0
投票

我会用matplotlib

from PIL import Image
img = Image.open('your_image')
imgplot = plt.imshow(img, interpolation="bicubic")

0
投票

如果要应用垂直,可以使用此内核:

kernel_motion_blur = np.zeros((size, size))
kernel_motion_blur[int(:, (size-1)/2)] = np.ones(size)
kernel_motion_blur = kernel_motion_blur / size
© www.soinside.com 2019 - 2024. All rights reserved.