为了账号安全,请及时绑定邮箱和手机立即绑定

使用python在图像中插入白色高斯噪声

使用python在图像中插入白色高斯噪声

皈依舞 2021-09-02 20:11:05
我试图搜索与 Matlab 函数(imnoise)相对应的 python 函数。我想使用高斯白噪声来增强图像。高斯白噪声的 matlab 代码:[I, map]=imread("img.png");I=double(I)/255;V=var(I(:)); %compute the image varianceJ=imnoise(I, 'gaussian', 0, V/10); %insert gaussian white noise with mean zero and tenth of that variance
查看完整描述

1 回答

?
泛舟湖上清波郎朗

TA贡献1818条经验 获得超3个赞

你可以使用 numpy 和 Pillow !


from PIL import Image

import numpy as np


# Load the image into a numpy array

I = Image.open(filename)

I_array = np.array(im)


# Calculate the variance for the image and the noise

M = 0

V = np.var(im_array)

noise = np.random.normal(mean, variance, I_array.shape)


# Add the noise to the image numpy array and convert

# everything back to a PIL image.

I_array_noise = np.add(I_array, noise)

J = Image.fromarray(I_array_noise)


查看完整回答
反对 回复 2021-09-02
  • 1 回答
  • 0 关注
  • 289 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号