import cv2
import numpy as np
import random
img = cv2.imread('face.jpg', 1)
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
dst = np.zeros((height, width, 3), np.uint8)
# 边值
mm = 8
for m in range(0, height - mm):
for n in range(0, width - mm):
# 随机产生的像素索引
index = int(random.random() * 8)
(b, g, r) = img[m + index, n + index]
dst[m, n] = (b, g, r)
cv2.imshow('src', img)
# 最边上的8像素没有填充 原始是0(黑色)
cv2.imshow('dst', dst)
cv2.waitKey(0)
毛玻璃效果如下:
image.png
网友评论