No account yet ?
Tested in Anaconda and Python 3.7
import cv2 import numpy as np import random if __name__ == "__main__": img = cv2.imread("Lenna.jpg") prob_noise = 0.01 thres = 1 - prob_noise for i in range(0, img.shape[0]): for j in range(0, img.shape[1]): rdn = random.random() if rdn < prob_noise: img[i][j] = 0 elif rdn > thres: img[i][j] = 255 else: img[i][j] = img[i][j] cv2.imwrite("Lenna_salt_pepper_noise.jpg", np.uint8(img))
Image-Restoration-in-Digital-Image-Processing - GitHub
Original image
Impulse salt and pepper image noise
Welcome, my name is Eric Soupet and I am the administrator of the site elodees.com. elodees.com is a state of the art of Artificial Intelligence and aims to be collaborative, you can now offer content such as articles, events, tutorials, ... so don't hesitate !
Platform images credit : Pixabay - Pixabay License | Pexels - Pexels License