简体   繁体   中英

How to add gaussian noise in an image in Python using PyMorph

I'm new at Python and I'd like to add a gaussian noise in a grey scale image. I'm already converting the original image into a grey scale to test some morphological methods to denoise (using PyMorph) but I have no idea how to add noise to it.

You did not provide a lot of info about the current state of your code and what exact kind of noise you want. But usually one would use numpy-based images and then it's simply adding some random-samples based on some distribution.

Example:

import numpy as np
# ...
img = ...    # numpy-array of shape (N, M); dtype=np.uint8
# ...
mean = 0.0   # some constant
std = 1.0    # some constant (standard deviation)
noisy_img = img + np.random.normal(mean, std, img.shape)
noisy_img_clipped = np.clip(noisy_img, 0, 255)  # we might get out of bounds due to noise

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM