-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_DR_2019.py
80 lines (59 loc) · 2.16 KB
/
run_DR_2019.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
import cv2
import os
import matplotlib.pyplot as plt
from DeepRare_2019_lib import DeepRare2019
from keras.applications.vgg16 import VGG16
sal = DeepRare2019() # instantiate class
sal.model = VGG16() # call VGG16 and send it to the class
sal.filt = 1 # make filtering
sal.face = 1 # use face (to be used only with VGG16)
directory = r'input'
plt.figure(1)
for filename in os.listdir(directory):
if filename.endswith(".jpg") or filename.endswith(".png"):
go_path = os.path.join(directory, filename)
img = cv2.imread(go_path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
sal.img = img
saliency_map, saliency_details, face = sal.compute() # here no visualization, only final sal maps but if you use the line above and uncomment the lines in the lib you can get the groups
plt.subplot(421)
plt.imshow(img)
plt.axis('off')
plt.title('Initial Image')
plt.subplot(422)
plt.imshow(saliency_map)
plt.axis('off')
plt.title('Final Saliency Map')
plt.subplot(423)
plt.imshow(saliency_details[:, :, 0])
plt.axis('off')
plt.title('LowLevel1 Saliency Map')
plt.subplot(424)
plt.imshow(saliency_details[:, :, 1])
plt.axis('off')
plt.title('LowLevel2 Saliency Map')
plt.subplot(425)
plt.imshow(saliency_details[:, :, 2])
plt.axis('off')
plt.title('MidLevel1 Saliency Map')
plt.subplot(426)
plt.imshow(saliency_details[:, :, 3])
plt.axis('off')
plt.title('MidLevel2 Saliency Map')
plt.subplot(427)
plt.imshow(saliency_details[:, :, 4])
plt.axis('off')
plt.title('HighLevel Saliency Map')
plt.subplot(428)
plt.imshow(face)
plt.axis('off')
plt.title('Large faces')
plt.show()
if not os.path.exists('output_raw'):
os.makedirs('output_raw')
file_no_extension = os.path.splitext(filename)[0]
file_out = file_no_extension + '.jpg'
go_path_raw = os.path.join('output_raw', file_out)
cv2.imwrite(go_path_raw, 255*saliency_map)
else:
continue