-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNoise
More file actions
33 lines (28 loc) · 834 Bytes
/
Noise
File metadata and controls
33 lines (28 loc) · 834 Bytes
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
import cv2
import matplotlib.pyplot as plt
import numpy as np
import random
def main():
path ="D:\\image_processing_files\\Dataset\\"
imgpath = path + "4.1.08.tiff"
img = cv2.imread(imgpath,1)
img = cv2.cvtColor(img,cv2.COLOR_BGR2RGB)
rows,columns,channel = img.shape
p = 0.05
output = np.zeros(img.shape,np.uint8)
for i in range(rows):
for j in range(columns):
r = random.random()
if r < p/2:
#pepper noise
output[i][j] = [0,0,0]
elif r<p:
#salt noise
output[i][j] = [255,255,255]
else:
output[i][j] = img[i][j]
plt.imshow(output)
plt.title("Original Image")
plt.show()
if __name__ == "__main__":
main()