-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageNoiseGame.py
More file actions
104 lines (63 loc) · 2.31 KB
/
ImageNoiseGame.py
File metadata and controls
104 lines (63 loc) · 2.31 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import numpy as np
import random
import cv2
import sys
from PIL import Image
from subprocess import call
def sp_noise(image,prob):
'''
Add salt and pepper noise to image
prob: Probability of the noise
'''
output = np.zeros(image.shape,np.uint8)
thres = 1 - prob
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn < prob:
output[i][j] = 0
elif rdn > thres:
output[i][j] = 255
else:
output[i][j] = image[i][j]
return output
print("")
print("Welcome to the image guessing game.")
print("")
print("Each time you input, the noise level will go down by 5 percent on the image.")
print("")
print("Try to guess who or what you are seeing as soon as you can.")
print("")
imlst = ["image0.jpg", "image1,jpg", "image2.jpg", "image3.jpg"]
ilen = len(imlst)
chin = random.randrange(ilen)
anslst = [("Ringo Starr", "Ringo", "Starr", "Beatle", "Beatle's Drummer", "A Beatle"), ("Paul McCartney", "Paul", "McCCartney", "Beatle", "Beatle's Singer", "A Beatle"), ("John Lennon", "John", "Lennon", "Beatle", "Beatle's Singer", "A Beatle") ,("George Harrison", "George", "Harrison", "Beatle", "Beatle's Guitarist", "A Beatle") ]
for ctr in range(10,0,-1):
prob = (ctr*5)/100
input("Press enter to start: ")
print("")
print("Working on image intensity: ", ctr)
image = cv2.imread(imlst[chin], 0) # Only for grayscale image
noise_img = sp_noise(image, prob)
cv2.imwrite("mysteryimage.jpg", noise_img)
print("")
img = Image.open('mysteryimage.jpg')
img.show()
ans = input("Look at the jpg in the new tab, and take your best guess as to who or what you see: ")
print("")
corr = 0
for elem in anslst[chin]:
if ans.lower() == elem.lower():
corr = 1
if corr > 0:
print("You are correct! The image is of", anslst[chin][0], "of the Beatles!")
print("")
rstr = input("Press q to quit or anything else to play again: ")
print("")
if rstr != "q":
call(["python", "ImageNoiseGame.py"])
sys.exit()
if corr == 0:
print("That is not correct! Keep trying and guessing!")
print("")
## THE GHOST OF THE SHADOW ##