数字图像噪声_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相关推荐

  1. 计算机网络量化噪音是怎么消除的,数字图像噪声消除算法研究(可编辑).doc

    数字图像噪声消除算法研究(可编辑) 数字图像噪声消除算法研究 曲阜师范大学 硕士学位论文 数字图像噪声消除算法研究 姓名:李波 申请学位级别:硕士 专业:计算机应用技术 指导教师:赵景秀字图像噪声消除 ...

  2. python中值滤波去除椒盐噪声_python 中值滤波,椒盐去噪,图片增强实例

    受光照.气候.成像设备等因素的影响,灰度化后的图像存在噪声和模糊干扰,直接影响到下一步的文字识别,因此,需要对图像进行增强处理.图片预处理中重要一环就是椒盐去澡,通常用到中值滤波器进行处理,效果很好. ...

  3. python图像条状状噪声_python检测图片噪声(噪点噪声、雪花噪声、条纹噪声)

    首先是噪声的大体分类: 噪点噪声:又称脉冲噪声.椒盐噪声 雪花噪声:又称高斯噪声 条纹噪声: 分析完这些噪声的大致分布情况之后 importcv2from PIL importImagefrom PI ...

  4. python高斯噪声_python随机数组,高斯噪声,多项式函数

    在前面的numpy的学习中忽略了这几个重要的知识点,导致今天做作业异常的艰难.现在十分必要将它记录下来. 1.np.random.*必须的是一个非常强的命令啊.不仅可以产生随机数(包括随机整数,实数: ...

  5. matlab对有周期性噪声的图像去噪,数字图像中去除周期性噪声研究.doc

    摘要:图像增强是数字图像处理相对简单却最具艺术性的领域之一,其目的是消除噪声,显现被模糊的细节或突出感兴趣区域.经常采用的手段分空域和频域两类,其中频域更是给我们提供了不同的视角,简化了许多复杂的算法 ...

  6. python高斯噪声怎么去除_Python图像处理之Pillow--ImageFilter介绍

    mageFilter:Python中的图像滤波,主要对图像进行平滑.锐化.边界增强等滤波处理. 图像滤波:在尽量保留图像细节特征的条件下对目标图像的噪声进行抑制,是图像预处理中不可缺少的操作,其处理效 ...

  7. 数字图像中关于添加噪声及噪声处理

    数字图像中关于添加噪声及噪声处理 MATLAB源代码 图像处理结果 分析 说明 MATLAB源代码 A = imread('yuantu.jpg'); A = rgb2gray(A); A1 = im ...

  8. python高斯滤波和降噪_python添加高斯噪声和椒盐噪声,实现中值滤波和均值滤波,实现Roberts算子和Sobel算子...

    写在前面 HIT大三上学期视听觉信号处理课程中视觉部分的实验一,经过和学长们实验的对比发现每一级实验要求都不一样,因此这里标明了是2019年秋季学期的视觉实验一. 由于时间紧张,代码没有进行任何优化, ...

  9. 数字图像中高频噪声的滤波

    代码解释 本文通过对图像加入高频高斯噪声再通过低通滤波滤除噪声. 本文代码通过MATLAB2020a编写. 代码 clear; clc;I = imread("person_resize.j ...

最新文章

  1. CentOS7 service network start命令启动时报错解决方法
  2. Magento中如何在模块中使用多张数据表并配置多个model?
  3. ASP.NET的SEO:使用.ashx文件——排除重复内容
  4. pyqt5教程9:Widgets组件
  5. win32下安装mingw32和cmake来编译opencv2.4.9
  6. doxygen注释规范示例(C++)
  7. java url 处理,URL处理-Java架构师必看
  8. 对于JDBC的简单理解
  9. CECC2018赛季收官站我国×××手夺得年度总冠军
  10. z变换解差分方程例题_中级数学4 - 多元线性方程
  11. 笔记本电池续航测试软件,电池续航能力测试及整机试用总结
  12. WiFi连接过程简要分析
  13. 投影仪芯片0.33和0.47DMD哪个好?当贝F3 Air实测体验分享
  14. 特斯拉降价也无法阻挡国内新能源汽车厂商前进的步伐
  15. “左眼跳财,右眼跳灾”
  16. 有理数加法 (15 分)
  17. 心情日志 —— 2015/09/09
  18. 有一天,如果你和计算机一样思考问题,真是太太太太有趣了
  19. python能干啥是什么意思_这年头不懂点Python都不好意思说是码农 神奇的Python都能干啥...
  20. 中科院京区博士生申请申根(德国)签证流程

热门文章

  1. 深度学习与自然语言处理之五:从RNN到LSTM
  2. 【最优解法】1087 有多少不同的值 (20分)_17行代码AC
  3. 【简便解法】1077 互评成绩计算 (20分)_32行代码AC
  4. 【最详细解析】1070 结绳 (25分)_18行代码AC
  5. 【答案放在最后,看题看不到答案】2019年上半年软件设计师 上午选择题
  6. java 捕获特定异常_java – 使用特定消息捕获异常
  7. 手工搭建APACHE服务
  8. java打印6个偶数_Java编写一个应用程序,打印所有偶数从2到100
  9. python server.py_python manage.py runserver报错
  10. python中的matplotlib.pyplot_python matplotlib中axes与axis的区别?