forked from zlinker/DehazeNet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
tmqi_script.py
120 lines (102 loc) · 5.16 KB
/
tmqi_script.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
'''
This script computes the NIQE (naturalness image quality evaluator) scores for the input images
as well as the dehazed version of those images and saves the results in an excel file.
'''
from openpyxl import load_workbook
from util.get_path import get_path
from util.tmqi import compute_tmqi
import os
import cv2
# from util.CLAHE import apply_CLAHE
from util.gamma_correction import gamma_correction
import numpy as np
with_coloration_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/testForImageCharacteristics/with-coloration/'
without_coloration_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/testForImageCharacteristics/without-coloration/'
dehazenet_coloration_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/images_with_coloration/'
dehazenet_without_coloration_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/images_without_coloration/'
gt_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/gt/'
enhanced_image_save_path = '/mnt/c/Users/Administrator/Desktop/SOTS/outdoor/processed_images/AdaptiveEnhance+CLAHE/'
excel_path = '/mnt/c/Users/Administrator/Desktop/criteria-test_Adaptive+CLAHE.xlsx'
wb = load_workbook(excel_path)
ws = wb['TMQI-1']
def tmqi_scores():
i = 0
for filename in os.listdir(with_coloration_path):
i += 1
gt_name = filename[:filename.find(
'_')] + '.png' # till the first occurence of underscore
# print(gt_name)
# print(gt_path + gt_name)
gt_img = gt_path + gt_name
im_path = with_coloration_path + filename
inp_img = cv2.imread(im_path)
predicted_path = get_path(inp_img, 117) # threshold=117
ws['A{}'.format(i + 1)] = filename
# ws['B{}'.format(i + 1)] = compute_tmqi(gt_img, im_path)
# dehazenet_image = dehazenet_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(
# filename[:-4])
# tmqi_dehaze = compute_tmqi(gt_img, dehazenet_image)
# ws['C{}'.format(i + 1)] = tmqi_dehaze
if predicted_path == 1:
# equalized_img = dehazenet_coloration_path + '{}_Equalized.jpg'.format(
# filename[:-4])
enh_path = enhanced_image_save_path + filename
enhanced_img = cv2.imread(enhanced_image_save_path + filename)
ws['D{}'.format(i + 1)] = compute_tmqi(gt_img, enh_path)
else:
ws['D{}'.format(i + 1)] = ws['C{}'.format(i + 1)].value
# Comparison with raw input image scores
if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
ws['E{}'.format(i + 1)] = "Yes"
elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
ws['E{}'.format(i + 1)] = "No"
else:
ws['E{}'.format(i + 1)] = "Equal"
# Comparison with DehazeNet scores
if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
ws['F{}'.format(i + 1)] = "Yes"
elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
ws['F{}'.format(i + 1)] = "No"
else:
ws['F{}'.format(i + 1)] = "Equal"
print("TMQI computed for: ", filename)
for filename in os.listdir(without_coloration_path):
i += 1
gt_name = filename[:filename.find(
'_')] + '.png' # till the first occurence of underscore
gt_img = gt_path + gt_name
im_path = without_coloration_path + filename
inp_img = cv2.imread(im_path)
predicted_path = get_path(inp_img, 117) # threshold=117
ws['A{}'.format(i + 1)] = filename
# ws['B{}'.format(i + 1)] = compute_tmqi(im_path, gt_img)
# dehazenet_image = dehazenet_without_coloration_path + '{}_finalWithoutCLAHE.jpg'.format(
# filename[:-4])
# tmqi_dehaze = compute_tmqi(dehazenet_image, gt_img)
# ws['C{}'.format(i + 1)] = tmqi_dehaze
if predicted_path == 1:
# equalized_img = dehazenet_without_coloration_path + '{}_Equalized.jpg'.format(
# filename[:-4])
enh_path = enhanced_image_save_path + filename
enhanced_img = cv2.imread(enhanced_image_save_path + filename)
ws['D{}'.format(i + 1)] = compute_tmqi(gt_img, enh_path)
else:
ws['D{}'.format(i + 1)] = ws['C{}'.format(i + 1)].value
# Comparison with raw input image scores
if ws['D{}'.format(i + 1)].value > ws['B{}'.format(i + 1)].value:
ws['E{}'.format(i + 1)] = "Yes"
elif ws['D{}'.format(i + 1)].value < ws['B{}'.format(i + 1)].value:
ws['E{}'.format(i + 1)] = "No"
else:
ws['E{}'.format(i + 1)] = "Equal"
# Comparison with DehazeNet scores
if ws['D{}'.format(i + 1)].value > ws['C{}'.format(i + 1)].value:
ws['F{}'.format(i + 1)] = "Yes"
elif ws['D{}'.format(i + 1)].value < ws['C{}'.format(i + 1)].value:
ws['F{}'.format(i + 1)] = "No"
else:
ws['F{}'.format(i + 1)] = "Equal"
print("TMQI computed for: ", filename)
wb.save(excel_path)
print("Script complete and excel saved!")
tmqi_scores()