opencv图像处理毛玻璃

    科技2023-09-27  101

    opencv图像处理毛玻璃

    毛玻璃的算法为将当前像素周围的0~8个单位的随机值付给当前像素,

    import cv2 import numpy as np import random img = cv2.imread(r"C:\Users\lenovo\Desktop\python\python_vision\image.jpg",1) imgInfo = img.shape height = imgInfo[0] weight = imgInfo[1] dst = np.zeros((height,weight,3),np.uint8) mm = 8 for m in range(0,height-mm): for n in range(0,weight-mm): index = int(random.random()*8) (b,g,r) = img[m+index,n+index] dst[m,n] = (b,g,r) cv2.imshow("dst",dst) cv2.waitKey(0)

    代码解释: 此为本次毛玻璃图像处理最核心的代码,将像素0~8个单位的像素赋给当前像素。

    index = int(random.random()*8) (b,g,r) = img[m+index,n+index] dst[m,n] = (b,g,r)
    Processed: 0.021, SQL: 8