0
点赞
收藏
分享

微信扫一扫

ECharts 词云图案例二:创意蒙版应用

南柯Taylor 2024-06-25 阅读 37
def noise(image, n=10000):
    result = image.copy()
    length, high = result.shape[:2]
    for i in range(n):
        # 根据随机值来指定x, y位置
        x = np.random.randint(1, length)
        y = np.random.randint(1, high)
        # 改变x, y位置的值
        if np.random.randint(2) == 0:  # 取值为0或1
            result[x, y] = 255
        else:
            result[x, y] = 0
    return result


image = cv2.imread('图片路径')
cv2.imshow('original', image)
#设置等待
cv2.waitKey(0)

result = noise(image)
cv2.imshow('noise', result)
#设置等待
cv2.waitKey(0)
#关闭所有打开的窗口
cv2.destroyAllWindows()

 

举报

相关推荐

0 条评论