简单人工智能技术应用 使用Python+OpenCV进行图像处理( 六 )

如果我们增加内核的大小 , 像素值将更加归一化 。 因此图像也会变得越来越模糊 。 让我们用下面的代码对比处理结果 。 (为了便于比较 , 将把原始图像加到结果中 , 进行对比显示 。 )

# Import the image and convert to RGB

img = cv2.imread('text.jpg')

img = cv2.cvtColor(img , cv2.COLOR_BGR2RGB)

# Plot the image with different kernel sizes

kernels = [5 , 11 , 17]

fig , axs = plt.subplots(nrows = 1 , ncols = 3 , figsize = (20 , 20))

for ind , s in enumerate(kernels):

img_blurred = cv2.blur(img , ksize = (s , s))

ax = axs[ind]

推荐阅读