from PIL import Image
import numpy as np

def imnoise(img, d):
    img_noisy = np.array(img)
    p = np.random.rand(img_noisy.shape[0], img_noisy.shape[1], img_noisy.shape[2])

    img_noisy[p < d/2] = 0
    img_noisy[np.logical_and(p >= d/2, p < d)] = 255

    return Image.fromarray(img_noisy)

# load an image
img = Image.open('./ISO_clean.jpg')

# add some noise
img_noisy = imnoise(img, 0.02)
img_noisy.save('./ISO_noisy.jpg')

img_noisy.show()

