And third important type of noise will be a black and pepper.

Here we will due to a bit simplar visualization represent only a noise that has white pixels.

One approach to do so is to let's say simply take a "uniform_noise" image.

Set a threshold rule, where we will convert all pixels larger than a threshold to white (255) and we will set the remaining to zero.

In [7]:
impulse_noise = uniform_noise.copy()

Here a number 250 is defined as a threshold value.

Obviously, if we want to increase a number of white pixels we will need to decrease it.

Otherwise, we can increase it and in that way we will suppress the number of white pixels.

In [8]:
ret,impulse_noise = cv2.threshold(uniform_noise,250,255,cv2.THRESH_BINARY)

cv2.imshow('Impuls noise',impulse_noise)
cv2.waitKey()
cv2.imwrite("Impuls noise.jpg",impulse_noise)
Out[8]:
True