当前位置:网站首页>Add salt and pepper noise or Gaussian noise to the picture
Add salt and pepper noise or Gaussian noise to the picture
2022-07-07 05:50:00 【Yingtai night snow】
Add salt and pepper noise or Gaussian noise to the picture
Salt and pepper noise added
Salt and pepper noise (salt & pepper noise) Is a common noise in digital images , Salt and pepper , Pepper is black , Salt is white , Salt and pepper noise is the random appearance of black and white pixels on the image . Salt and pepper noise is a kind of noise caused by signal pulse strength , The algorithm to generate this noise is also relatively simple .
Add salt and pepper noise to the grayscale image
# Add salt and pepper noise to grayscale images
# src Enter the path of the image
# dst Output image path
# prob Proportion of noise
def addSaltPepperNoise_gray(src,dst,probility=0.05,method="salt_pepper"):
# Convert the picture into a grayscale image
imarray=np.array(Image.open(src).convert('L'))
height,width=imarray.shape
for i in range(height):
for j in range(width):
# Add salt and pepper noise randomly
if np.random.random(1)<probility:
if np.random.random(1)<0.05:
imarray[i,j]=0
else:
imarray[i,j]=255
# Add the generated salt and pepper noise image to
new_im=Image.fromarray(imarray)
new_im.save(dst)
return new_im
Add salt and pepper noise to the color map
def RGBAddNoise(src, dst, prob): # Add clutter at the same time (RGB Single noise )RGB Figure noise prob: Noise ratio
imarray = np.array(Image.open(src))
height, width, channels = imarray.shape
# prob = 0.05 # Noise ratio It's already obvious >0.1 Seriously affect the image quality
NoiseImg = imarray.copy()
NoiseNum = int(prob * height * width)
for i in range(NoiseNum):
rows = np.random.randint(0, height - 1)
cols = np.random.randint(0, width - 1)
channel = np.random.randint(0, 3)
if np.random.randint(0, 2) == 0:
NoiseImg[rows, cols, channel] = 0
else:
NoiseImg[rows, cols, channel] = 255
# return NoiseImg
new_im = Image.fromarray(NoiseImg)
new_im.save(dst)
return new_im
Gaussian noise added
Gaussian noise means that the probability density function of noise distribution obeys Gaussian distribution ( Normal distribution ) A kind of noise , The main reason is that the camera has a dark field of view and uneven brightness when shooting , At the same time, high temperature caused by long-time operation of the camera will also cause Gaussian noise , In addition, the noise and mutual influence of circuit components are also one of the important reasons for Gaussian noise .
Add Gaussian noise to the grayscale image
def addGaussNoiseGray(src,dst,mean,sigma):
image=cv2.imread(src,cv2.IMREAD_GRAYSCALE)
height,width=image.shape
gauss=np.random.normal(mean,sigma,image.shape)
gauss=gauss.reshape(height,width)
noiseImage=image+gauss
noiseImage=np.clip(noiseImage,0,255)
noiseImage=noiseImage.astype('uint8')
cv2.imwrite(dst,noiseImage)
return noiseImage
Add Gaussian noise to the color map
# Add Gaussian noise to color images
def addGaussNoiseRgb(src,dst,mean,sigma):
image=cv2.imread(src)
height,width,channels=image.shape
# Establish Gaussian noise
gauss=np.random.normal(mean,sigma,(height,width,channels))
gauss=gauss.reshape(height,width,channels)
noiseImage=image+gauss
noiseImage=np.clip(noiseImage,0,255)
noiseImage=noiseImage.astype('uint8')
cv2.imwrite(dst,noiseImage)
return noiseImage
Result display

边栏推荐
- nodejs获取客户端ip
- Mybaits multi table query (joint query, nested query)
- 404 not found service cannot be reached in SAP WebService test
- 原生小程序 之 input切换 text与password类型
- Taobao commodity details page API interface, Taobao commodity list API interface, Taobao commodity sales API interface, Taobao app details API interface, Taobao details API interface
- TCC of distributed transaction solutions
- 分布式事务介绍
- 数字IC面试总结(大厂面试经验分享)
- Message queuing: how to ensure that messages are not lost
- Paper reading [MM21 pre training for video understanding challenge:video captioning with pre training techniqu]
猜你喜欢

C#可空类型

The year of the tiger is coming. Come and make a wish. I heard that the wish will come true

Get the way to optimize the one-stop worktable of customer service

Red Hat安装内核头文件

《2022中国低/无代码市场研究及选型评估报告》发布

分布式事务介绍

软件测试面试技巧

Realize GDB remote debugging function between different network segments
![R language [logic control] [mathematical operation]](/img/93/06a306561e3e7cb150d243541cc839.png)
R language [logic control] [mathematical operation]

ForkJoin最全详解(从原理设计到使用图解)
随机推荐
SAP ABAP BDC (batch data communication) -018
1. AVL tree: left-right rotation -bite
Pytorch builds neural network to predict temperature
C nullable type
Realize GDB remote debugging function between different network segments
What is message queuing?
In memory, I moved from CSDN to blog park!
zabbix_ Get test database failed
R language [logic control] [mathematical operation]
C#可空类型
OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
async / await
盘点国内有哪些EDA公司?
常用消息队列有哪些?
架构设计的五个核心要素
集群、分布式、微服務的區別和介紹
分布式全局ID生成方案
Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)
微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
Mybaits multi table query (joint query, nested query)