zoukankan      html  css  js  c++  java
  • 产生加性零均值高斯噪声

    处理前后的图片对比:

    代码实现:

    import cv2
    import numpy as np
    
    fn="./0.jpg"
    img=cv2.imread(fn)
    
    param=30
    #灰阶范围
    grayscale=256
    w=img.shape[1]
    h=img.shape[0]
    newimg=np.zeros((h,w,3),np.uint8)
    
    for x in range(0,h):
        for y in range(0,w,2):
            r1=np.random.random_sample()
            r2=np.random.random_sample()
            z1=param*np.cos(2*np.pi*r2)*np.sqrt((-2)*np.log(r1))
            z2=param*np.sin(2*np.pi*r2)*np.sqrt((-2)*np.log(r1))
            
            fxy = [0 if int(i)<0 else grayscale-1 if int(i)>grayscale-1 else int(i) for i in img[x,y]+[z1, z1, z1]]
            fxy1 = [0 if int(i)<0 else grayscale-1 if int(i)>grayscale-1 else int(i) for i in img[x,y+1]+[z2, z2, z2]]
    
            newimg[x,y]=fxy
            newimg[x,y+1]=fxy1
        
    cv2.imshow('preview',newimg)
    cv2.imwrite('./00.jpg', newimg)
    cv2.waitKey()
    cv2.destroyAllWindows()
  • 相关阅读:
    nginx平滑升级及回滚
    redis源码安装
    memcached安装
    Harbor源码部署
    Maven源码部署
    tomcat单机多实例(未完待续)
    部署tomcat
    nginx编译参数详解
    CentOS7 安装pip/pip3
    nginx 部署配置
  • 原文地址:https://www.cnblogs.com/czz0508/p/11042248.html
Copyright © 2011-2022 走看看