一、
图像毛玻璃效果
1.马赛克是指定范围内的统一填充,毛玻璃是指定范围内的随机取值
2.np.random.random(),随机产生[0,1]内的数
二、
import cv2
import numpy as np
img = cv2.imread('image01.jpg', 1)
imgHeight, imgWidth, imgDeep = img.shape
dst = np.zeros(img.shape, np.uint8)
basicRangeSize = [5,5]
for i in range(imgHeight):
for j in range(imgWidth):
randomHeight = int(np.random.random() * basicRangeSize[0])
randomWidth = int(np.random.random() * basicRangeSize[1])
if i < imgHeight - basicRangeSize[0] and j < imgWidth - basicRangeSize[1]:
dst[i, j] = img[i + randomHeight, j + randomWidth]
# 防止数据下标溢出
elif i < basicRangeSize[0]:
dst[i, j] = img[i + randomHeight, j]
elif j < basicRangeSize[1]:
dst[i, j] = img[i, j + randomWidth]
else:
dst[i, j] = img[i - randomHeight, j - randomWidth]
cv2.imshow('',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()