opencv图像特效之毛玻璃

import cv2
import numpy as np
import random
img = cv2.imread("E:/code/conputer_visual/data/0.jpg", 1)
cv2.imshow("pre", img)
imginfo = img.shape
height = imginfo[0]
width = imginfo[1]
dst = np.zeros((height, width, 3), np.uint8)
mm = 4
for m in range(0, height):
    for n in range(0, width):
        if m > height-mm or n > width-mm:
            (b,g,r) = img[m, n]
            dst[m,n] = (b,g,r)
        else:
            index = int(random.random()*4)
            (b,g,r) = img[m+index, n+index]
        dst[m,n] = (b,g,r)
cv2.imshow("dst", dst)
cv2.waitKey()

在这里插入图片描述

原理: 将进行毛玻璃处理的区域的像素值替换为其附近4x4像素框中的随机某个像素值

猜你喜欢

转载自blog.csdn.net/cyj5201314/article/details/114646608