日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

数字图像噪声_Python

發(fā)布時(shí)間:2024/1/23 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数字图像噪声_Python 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

數(shù)字圖像噪聲_Python

本文鏈接:https://blog.csdn.net/TOMBOY_Marry/article/details/83997515

一:數(shù)字圖像噪聲來(lái)源

圖像的獲取(數(shù)字化過(guò)程)和傳輸過(guò)程,當(dāng)使用相機(jī)獲取圖像時(shí),光照程度和傳感器溫度是生成圖像大量噪點(diǎn)的主要因素。

二:灰度圖加入高斯噪聲(正態(tài)噪聲)

def GaussianNoise(src,mean,sigma):NoiseImg=srcrows,cols=NoiseImg.shapefor i in range(rows):for j in range(cols):NoiseImg[i,j]=NoiseImg[i,j]+random.gauss(mean,sigma)if NoiseImg[i,j]<0:NoiseImg[i,j]=0elif NoiseImg[i,j]>255:NoiseImg[i,j]=255return NoiseImgimg=cv2.imread('IMG_4470.JPG',0) img=GaussianNoise(img,2,4) cv2.imwrite('IMG_4470_GaussianNoise.jpg',img) cv2.imshow('IMG_4470_GaussianNoise',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:
原圖為:

三:彩色圖加入高斯噪聲

def GaussianNoise_color(src,mean,sigma):NoiseImg=srcrows,cols,_=NoiseImg.shapefor i in range(rows):for j in range(cols):NoiseImg[i,j]=NoiseImg[i,j]+random.gauss(mean,sigma)return NoiseImgimg=cv2.imread('IMG_4470.JPG') img=GaussianNoise_color_percentage(img,2,4) cv2.imwrite('IMG_4470_GaussianNoise_color_1.jpg',img) cv2.imshow('IMG_4470_GaussianNoise_color_1',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出為:

四:部分像素點(diǎn)加入高斯噪聲

def GaussianNoise_color_percentage(src,mean,sigma,percentage):NoiseImg=srcrows,cols,_=NoiseImg.shapenum=int(rows*cols*percentage)for i in range(num):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)NoiseImg[randX,randY]=NoiseImg[randX,randY]+random.gauss(mean,sigma)return NoiseImgimg=cv2.imread('IMG_4470.JPG') img=GaussianNoise_color_percentage(img,2,4,0.5) cv2.imwrite('IMG_4470_GaussianNoise_color_percentage_1.jpg',img) cv2.imshow('IMG_4470_GaussianNoise_color_percentage_1',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

五:圖像加入椒鹽噪聲_胡椒點(diǎn)

def Pepper(src,percentage):NoiseImg=srcrows,cols,_=NoiseImg.shapeNoiseNum=int(percentage*rows*cols)for i in range(NoiseNum):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if random.randint(0,1)<=0.5:NoiseImg[randX,randY]=0else:NoiseImg[randX,randY]=NoiseImg[randX,randY]return NoiseImgimg=cv2.imread('IMG_4470.JPG') img=PepperandSalt_2(img,0.01) cv2.imwrite('IMG_4470_PepperandSalt_7_pepper.jpg',img) cv2.imshow('IMG_4470_PepperandSalt_7',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

六:圖像加入椒鹽噪聲_鹽點(diǎn)

def salt(src,percentage):NoiseImg=srcrows,cols,_=NoiseImg.shapeNoiseNum=int(percentage*rows*cols)for i in range(NoiseNum):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if random.randint(0,1)<=0.5:NoiseImg[randX,randY]=255else:NoiseImg[randX,randY]=NoiseImg[randX,randY]return NoiseImgimg=cv2.imread('IMG_4470.JPG') img=salt(img,0.01) cv2.imwrite('IMG_4470_PepperandSalt_8_salt.jpg',img) cv2.imshow('IMG_4470_PepperandSalt_8',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

七:灰度圖加入椒鹽噪聲

def PepperandSalt(src,percentage):NoiseImg=srcrows,cols=NoiseImg.shapeNoiseNum=int(percentage*rows*cols)for i in range(NoiseNum):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if random.randint(0,1)<=0.5:NoiseImg[randX,randY]=0else:NoiseImg[randX,randY]=255return NoiseImgimg=cv2.imread('IMG_4470.JPG',0) img=PepperandSalt(img,0.05) cv2.imwrite('IMG_4470_PepperandSalt_2.jpg',img) cv2.imshow('IMG_4470_PepperandSalt_2',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

八:彩色圖加入椒鹽噪聲

def PepperandSalt_color(src,percentage):NoiseImg=srcrows,cols,_=NoiseImg.shapeNoiseNum=int(percentage*rows*cols)for i in range(NoiseNum):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if random.randint(0,1)<=0.5:NoiseImg[randX,randY]=0else:NoiseImg[randX,randY]=255return NoiseImgimg=cv2.imread('IMG_4470.JPG') img=PepperandSalt_color(img,0.05) cv2.imwrite('IMG_4470_PepperandSalt_color.jpg',img) cv2.imshow('IMG_4470_PepperandSalt_color',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

九:指數(shù)分布噪聲

def Exponent(src,constant,percentage):NoiseImg=srcrows,cols=NoiseImg.shapenum=int(rows*cols*percentage)for i in range(num):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if NoiseImg[randX,randY]>128:NoiseImg[randX,randY]=constant*np.exp(-constant*NoiseImg[randX,randY]) else:NoiseImg[randX,randY]=NoiseImg[randX,randY]return NoiseImgimg=cv2.imread('IMG_4470.JPG',0) img=Exponent(img,0.5,0.01) cv2.imwrite('IMG_4470_Exponent.jpg',img) cv2.imshow('IMG_4470_Exponent',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

十:均勻分布噪聲

def distribution(src,low,high,percentage):NoiseImg=srcrows,cols=NoiseImg.shapenum=int(rows*cols*percentage)for i in range(num):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if low<NoiseImg[randX,randY]<high and a!=b:NoiseImg[randX,randY]=1/(a-b) else:NoiseImg[randX,randY]=NoiseImg[randX,randY]return NoiseImgimg=cv2.imread('IMG_4470.JPG',0) img=distribution(img,100,200,0.1) cv2.imwrite('IMG_4470_distribution.jpg',img) cv2.imshow('IMG_4470_distribution',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

十一:伽馬(愛(ài)爾蘭)噪聲

伽馬曲線如下:

a=10 b=20 z=np.arange(1,20,0.1) y=(a**b)*(z**(b-1))/np.math.factorial(b-1)*np.exp(-a*z) plt.plot(z,y)

def gamma_noise(src,constant_a,constant_b,percentage):NoiseImg=srcrows,cols=NoiseImg.shapenum=int(rows*cols*percentage)for i in range(num):randX=np.random.randint(0,rows-1)randY=np.random.randint(0,cols-1)if NoiseImg[randX,randY]>120 and b!=0:z=NoiseImg[randX,randY]NoiseImg[randX,randY]=(a**b)*(z**(b-1))/np.math.factorial(b-1)*np.exp(-a*z) else:NoiseImg[randX,randY]=NoiseImg[randX,randY]return NoiseImgimg=cv2.imread('IMG_4470.JPG',0) img=gamma_noise(img,5,10,0.01) cv2.imwrite('IMG_4470_gamma_noise.jpg',img) cv2.imshow('IMG_4470_gamma_noise',img) cv2.waitKey(0) cv2.destroyAllWindows() cv2.waitKey(1)

輸出結(jié)果為:

總結(jié)

以上是生活随笔為你收集整理的数字图像噪声_Python的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。