-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsalt_pepper.py
37 lines (28 loc) · 861 Bytes
/
salt_pepper.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import cv2
from matplotlib import pyplot as plt
import numpy as np
import random
def show_diff(img1, img2):
plt.imshow(np.hstack((img1, img2)), cmap="gray")
plt.show()
def add_noise(image):
row, col = image.shape
number_of_pixels = random.randint(1000, 10000)
for i in range(number_of_pixels):
y_axis = random.randint(0, row - 1)
x_axis = random.randint(0, col - 1)
image[y_axis][x_axis] = 255
number_of_pixels = random.randint(300, 10000)
for i in range(number_of_pixels):
y_axis = random.randint(0, row - 1)
x_axis = random.randint(0, col - 1)
image[y_axis][x_axis] = 0
return image
image = cv2.imread('images\\resim.jpg', 0)
plt.hist(image)
plt.title("Original image")
plt.show()
noisy_image = add_noise(image)
plt.hist(noisy_image)
plt.title("Noisy image")
plt.show()