-
Notifications
You must be signed in to change notification settings - Fork 0
/
tuz biber-histogram.py
49 lines (36 loc) · 1.3 KB
/
tuz biber-histogram.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
37
38
39
40
41
42
43
44
45
46
47
48
49
import random
import cv2
def add_noise(img):
# Getting the dimensions of the image
row, col = img.shape
# Randomly pick some pixels in the
# image for coloring them white
# Pick a random number between 300 and 10000
number_of_pixels = random.randint(300, 10000)
for i in range(number_of_pixels):
# Pick a random y coordinate
y_coord = random.randint(0, row - 1)
# Pick a random x coordinate
x_coord = random.randint(0, col - 1)
# Color that pixel to white
img[y_coord][x_coord] = 255
# Randomly pick some pixels in
# the image for coloring them black
# Pick a random number between 300 and 10000
number_of_pixels = random.randint(300, 10000)
for i in range(number_of_pixels):
# Pick a random y coordinate
y_coord = random.randint(0, row - 1)
# Pick a random x coordinate
x_coord = random.randint(0, col - 1)
# Color that pixel to black
img[y_coord][x_coord] = 0
return img
# salt-and-pepper noise can
# be applied only to grayscale images
# Reading the color image in grayscale image
img = cv2.imread('flower.jpg', cv2.IMREAD_GRAYSCALE)
# Storing the image
cv2.imshow('img', add_noise(img))
cv2.waitKey(0)
#plotting histogram