(img, N=0.0015)
| 73 | |
| 74 | |
| 75 | def random_pepper(img, N=0.0015): |
| 76 | img = np.array(img) |
| 77 | noiseNum = int(N * img.shape[0] * img.shape[1]) |
| 78 | for i in range(noiseNum): |
| 79 | randX = random.randint(0, img.shape[0] - 1) |
| 80 | randY = random.randint(0, img.shape[1] - 1) |
| 81 | if random.randint(0, 1) == 0: |
| 82 | img[randX, randY] = 0 |
| 83 | else: |
| 84 | img[randX, randY] = 255 |
| 85 | return Image.fromarray(img) |