当前位置:网站首页>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

边栏推荐
- Wechat applet Bluetooth connects hardware devices and communicates. Applet Bluetooth automatically reconnects due to abnormal distance. JS realizes CRC check bit
- 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
- Simple case of SSM framework
- An example of multi module collaboration based on NCF
- The 2022 China low / no code Market Research and model selection evaluation report was released
- Leetcode: maximum number of "balloons"
- 关于服装ERP,你知道多少?
- 判断文件是否为DICOM文件
- Go language context explanation
- 数据中心为什么需要一套基础设施可视化管理系统
猜你喜欢

分布式事务介绍

基于NCF的多模块协同实例

力扣102题:二叉树的层序遍历

Simple case of SSM framework

SAP ABAP BDC(批量数据通信)-018

Forkjoin is the most comprehensive and detailed explanation (from principle design to use diagram)

An example of multi module collaboration based on NCF

TCC of distributed transaction solutions

sql查询:将下一行减去上一行,并做相应的计算

Red Hat安装内核头文件
随机推荐
404 not found service cannot be reached in SAP WebService test
SAP ABAP BDC (batch data communication) -018
In memory, I moved from CSDN to blog park!
STM32按键状态机2——状态简化与增加长按功能
三级菜单数据实现,实现嵌套三级菜单数据
make makefile cmake qmake都是什么,有什么区别?
How digitalization affects workflow automation
谈fpga和asic的区别
zabbix_ Get test database failed
集群、分布式、微服務的區別和介紹
async / await
ForkJoin最全详解(从原理设计到使用图解)
Mapbox Chinese map address
拼多多商品详情接口、拼多多商品基本信息、拼多多商品属性接口
纪念下,我从CSDN搬家到博客园啦!
Flink SQL realizes reading and writing redis and dynamically generates hset key
SQL query: subtract the previous row from the next row and make corresponding calculations
Taobao store release API interface (New), Taobao oauth2.0 store commodity API interface, Taobao commodity release API interface, Taobao commodity launch API interface, a complete set of launch store i
Reptile exercises (III)
Unity keeps the camera behind and above the player