高斯雜訊的**如下:
def gaussiannoise(src,means,sigma):
noiseimg=src
rows=noiseimg.shape[0]
cols=noiseimg.shape[1]
for i in range(rows):
for j in range(cols):
noiseimg[i,j]=noiseimg[i,j]+random.gauss(means,sigma)
if noiseimg[i,j]< 0:
noiseimg[i,j]=0
elif noiseimg[i,j]>255:
noiseimg[i,j]=255
return noiseimg
椒鹽雜訊的函式定義如下:
def pepperandsalt(src,percetage):
noiseimg=src
noisenum=int(percetage*src.shape[0]*src.shape[1])
for i in range(noisenum):
randx=random.random_integers(0,src.shape[0]-1)
randy=random.random_integers(0,src.shape[1]-1)
if random.random_integers(0,1)<=0.5:
noiseimg[randx,randy]=0
else:
noiseimg[randx,randy]=255
return noiseimg
椒鹽雜訊總體**如下:
加入椒鹽雜訊之後的執行結果如下:
高斯雜訊的**為:
加入高斯雜訊的執行結果為:
高斯雜訊和椒鹽雜訊的python程式實現
首首先我們先來看下python中shape 函式的用法 from numpy import a array 1,2,3 2,3,4 3,4,5 4,5,6 a.shape 0 得到a的行數為 4 然後輸入 a.shape 1 得到a的列數為 3 圖1 執行在python的idle中示例 通過程式我們...
Python OpenCV寫椒鹽雜訊和高斯雜訊
import cv2 import numpy as np import random import tkinter import math def rgb2gray rgb gray np.zeros rgb.shape 0 rgb.shape 1 1 np.uint8 建立影象變數,防止gray...
霧看OpenCV 6 椒鹽雜訊與高斯雜訊
參考 1 椒鹽雜訊 椒鹽雜訊也稱脈衝雜訊,它是一種隨機出現的白點或者黑點,可能是亮的區域有黑色畫素或是在暗的區域有白色畫素 或是兩者皆有 影象模擬新增椒鹽雜訊是通過 隨機獲取畫素點,並設定為高亮度點和低亮度點來實現的。2 高斯雜訊 高斯雜訊是指概率密度函式服從高斯分布的一類雜訊。特別的,如果乙個雜訊...