日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

数字图像噪声_Python

發布時間:2024/1/23 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 数字图像噪声_Python 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

數字圖像噪聲_Python

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

一:數字圖像噪聲來源

圖像的獲取(數字化過程)和傳輸過程,當使用相機獲取圖像時,光照程度和傳感器溫度是生成圖像大量噪點的主要因素。

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

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)

輸出結果為:
原圖為:

三:彩色圖加入高斯噪聲

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)

輸出為:

四:部分像素點加入高斯噪聲

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)

輸出結果為:

五:圖像加入椒鹽噪聲_胡椒點

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)

輸出結果為:

六:圖像加入椒鹽噪聲_鹽點

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)

輸出結果為:

七:灰度圖加入椒鹽噪聲

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)

輸出結果為:

八:彩色圖加入椒鹽噪聲

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)

輸出結果為:

九:指數分布噪聲

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)

輸出結果為:

十:均勻分布噪聲

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)

輸出結果為:

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

伽馬曲線如下:

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)

輸出結果為:

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。