-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnoise.py
105 lines (67 loc) · 2.45 KB
/
noise.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
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
103
import numpy as np
import random
import cv2
class spatial_noise_color(object) :
def __init__(self,photo) -> None:
self.photo = photo
return None
def salt(self,cycles:int):
photo = self.photo
new = np.copy(photo)
for count in range(cycles):
i = np.random.randint(0,800)
j = np.random.randint(0,1200)
new[i,j] = [255,255,255]
return new
def pepper(self,cycles:int):
photo = self.photo
new = np.copy(photo)
for count in range(cycles):
i = np.random.randint(0,800)
j = np.random.randint(0,1200)
new[i,j] = [0,0,0]
return new
def salt_pepper(self,cycles:int):
photo = self.photo
new = np.copy(photo)
for count in range(cycles):
i = np.random.randint(0,800)
j = np.random.randint(0,1200)
key = np.random.randint(0,2)
if key == 0 :
new[i,j] = [0,0,0]
else :
new[i,j] = [255,255,255]
return new
class probabilistic_noise (object):
def __init__(self,photo) -> None:
self.photo = photo
return None
def gaussian(self,std_dev):
photo = self.photo
mean = np.mean(photo)
noise = np.random.normal(loc=mean,scale=std_dev,size=(800,1200))
return photo+noise
def uniform(self,a,b):
photo = self.photo
mean = np.mean(photo)
noise = np.zeros((800,1200),np.float32)
for i in range(800):
for j in range(1200):
noise[i,j] = random.randrange(a,b+1)
return photo+noise
def erlang(self,a,b):
photo = self.photo
noise = np.random.gamma(a,b,(800,1200))
print(noise)
return photo+noise
def exponential(self,a):
photo = self.photo
noise = np.random.exponential(a,(800,1200))
print(noise)
return photo+noise
def poisson(self):
photo = self.photo
noise = np.random.poisson(lam=np.mean(photo), size=(800,1200))
print(noise)
return photo + noise