当前位置:网站首页>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
边栏推荐
- 成为资深IC设计工程师的十个阶段,现在的你在哪个阶段 ?
- Realize GDB remote debugging function between different network segments
- 原生小程序 之 input切换 text与password类型
- OpenSergo 即将发布 v1alpha1,丰富全链路异构架构的服务治理能力
- Preliminary practice of niuke.com (9)
- 产业金融3.0:“疏通血管”的金融科技
- 4. 对象映射 - Mapping.Mapster
- Go language context explanation
- 淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
- 微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
猜你喜欢
sql优化常用技巧及理解
[binary tree] binary tree path finding
JD commodity details page API interface, JD commodity sales API interface, JD commodity list API interface, JD app details API interface, JD details API interface, JD SKU information interface
Introduction to distributed transactions
数据中心为什么需要一套基础设施可视化管理系统
1. AVL tree: left-right rotation -bite
得物客服一站式工作台卡顿优化之路
English grammar_ Noun possessive
Differences and introduction of cluster, distributed and microservice
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
随机推荐
【已解决】记一次EasyExcel的报错【读取xls文件时全表读不报错,指定sheet名读取报错】
STM32按键状态机2——状态简化与增加长按功能
SAP ABAP BDC(批量数据通信)-018
Pinduoduo product details interface, pinduoduo product basic information, pinduoduo product attribute interface
4. Object mapping Mapster
论文阅读【Open-book Video Captioning with Retrieve-Copy-Generate Network】
Randomly generate session_ id
淘宝商品详情页API接口、淘宝商品列表API接口,淘宝商品销量API接口,淘宝APP详情API接口,淘宝详情API接口
Modes of optical fiber - single mode and multimode
线性回归
Common skills and understanding of SQL optimization
The year of the tiger is coming. Come and make a wish. I heard that the wish will come true
淘宝店铺发布API接口(新),淘宝oAuth2.0店铺商品API接口,淘宝商品发布API接口,淘宝商品上架API接口,一整套发布上架店铺接口对接分享
zabbix_get测试数据库失败
SQLSTATE[HY000][1130] Host ‘host. docker. internal‘ is not allowed to connect to this MySQL server
谈fpga和asic的区别
Educational Codeforces Round 22 B. The Golden Age
三级菜单数据实现,实现嵌套三级菜单数据
微信小程序蓝牙连接硬件设备并进行通讯,小程序蓝牙因距离异常断开自动重连,js实现crc校验位
Go language context explanation