File size: 29,895 Bytes
c0fcf02
 
 
 
 
c9304bd
 
 
c0fcf02
 
 
 
48b514b
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48b514b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
48b514b
c0fcf02
 
 
 
48b514b
 
 
c0fcf02
48b514b
 
 
 
 
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48b514b
 
 
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48b514b
ab4f77f
 
 
 
 
 
 
 
48b514b
 
 
 
 
 
 
 
 
 
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
48b514b
c0fcf02
 
 
48b514b
c0fcf02
 
 
 
 
 
 
 
 
c8c1962
c0fcf02
 
 
 
 
 
48b514b
c0fcf02
 
 
48b514b
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48b514b
c0fcf02
 
 
48b514b
c0fcf02
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
import os
from PIL import Image
from pathlib import Path
import numpy as np
import random
# import torchvision.transforms.functional as TF
# import torchvision.transforms as transforms
# import cv2
import re
import json

# ir dataset dictionary:
base_rt = f'/home/work/shared-fi-datasets-01/users/hsiang.chen/Project/Datasets/IR'
dataset_dict = {
    # Image Restoration
    ## Super Resolution (3)
    "HR": {
        "DIV2K": {'train': 'SuperResolution/DIV2K/metas/DIV2K_train_HR.list',           # (800, single)
                  'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_HR.list'},            # (100, single)
        "Flickr2K": {'train': 'SuperResolution/Flickr2K/metas/Flickr2K_HR.list'}, # (2650, single)
        "OST": {'train': 'SuperResolution/OST/metas/OST_HR.list'},                # (10324, single)
    },

    "Low Resolution": {
        "DIV2K": {'train1': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR1.list',    # (800, pair)
                  'train2': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR2.list',    # (800, pair)
                  'train3': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_SR3.list',    # (800, pair)
                  'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_pair_SR.list'},       # (100, pair)
        "Flickr2K": {'train1': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR1.list', # (2650, pair)
                     'train2': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR2.list', # (2650, pair)
                     'train3': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_SR3.list'},# (2650, pair)
        "OST": {'train1': 'SuperResolution/OST/metas/OST_train_pair_SR1.list',        # (10324, pair)
                'train2': 'SuperResolution/OST/metas/OST_train_pair_SR2.list',        # (10324, pair)
                'train3': 'SuperResolution/OST/metas/OST_train_pair_SR3.list'},       # (10324, pair)      
    },

    ## Derain (5)
    "Rain": {
        "RainTrainL": {'train': 'Derain/RainTrainL/metas/train.list'}, # (200, pair)
        "Rain100L": {'test': 'Derain/Rain100L/metas/test.list'},       # (100, pair)
        "LHPRain": {'train': 'Derain/LHPRain/metas/train.list',        # (2100, pair)    
                    'val': 'Derain/LHPRain/metas/val.list',            # (600, pair)
                    'test': 'Derain/LHPRain/metas/test.list'},         # (300, pair)
        "UHDRain": {'train': 'Derain/UHD-Rain/metas/train.list',       # (3000, pair)
                    'test': 'Derain/UHD-Rain/metas/test.list'},        # (200, pair)
        "Practical": {'test': 'Derain/Practical/metas/test.list'},     # (15, real)
    },

    ## Deraindrop (2)
    "RainDrop": {
        "RainDrop": {'train': 'Derain/RainDrop/metas/Raindrop_train.list',      # (861, pair)
                     'test_a': 'Derain/RainDrop/metas/Raindrop_test_a.list',    # (58, pair)
                     'test_b': 'Derain/RainDrop/metas/Raindrop_test_b.list'},   # (249, pair)
        "RainDS_syn_rainstreak": {'train': 'Derain/RainDS/metas/RainDS_syn_train_rainstreak.list',  # (1000, pair)
                                'test': 'Derain/RainDS/metas/RainDS_syn_test_rainstreak.list'},     # (200, pair)
        "RainDS_syn_raindrop": {'train': 'Derain/RainDS/metas/RainDS_syn_train_raindrop.list',      # (1000, pair)
                                'test': 'Derain/RainDS/metas/RainDS_syn_test_raindrop.list'},       # (200, pair)
        "RainDS_syn_rainstreak_raindrop": {'train': 'Derain/RainDS/metas/RainDS_syn_train_rainstreak_raindrop.list', # (1000, pair)
                                        'test': 'Derain/RainDS/metas/RainDS_syn_test_rainstreak_raindrop.list'},  # (200, pair)
        "RainDS_real_rainstreak": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_rainstreak.list', # (150, pair)
                                'test': 'Derain/RainDS/metas/RainDS_real_test_set_rainstreak.list'},  # (98, pair)
        "RainDS_real_raindrop": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_raindrop.list',     # (150, pair)
                                'test': 'Derain/RainDS/metas/RainDS_real_test_set_raindrop.list'},      # (98, pair)
        "RainDS_real_rainstreak_raindrop": {'train': 'Derain/RainDS/metas/RainDS_real_train_set_rainstreak_raindrop.list', # (150, pair)
                                            'test': 'Derain/RainDS/metas/RainDS_real_test_set_rainstreak.list'},           # (98, pair)
    },

    ## Dehaze (5)
    "Fog":{
        "SOTS": {'test': 'Dehaze/SOTS/metas/test.list'},           # (500, pair)
        "OTS": {'train': 'Dehaze/OTS/metas/train.list'},           # (72135, pair)
        "4kID": {'train': 'Dehaze/4kID/metas/train.list',          # (15606, pair)
                'test': 'Dehaze/4kID/metas/test.list'},           # (97, pair)
        "Unann": {'test': 'Dehaze/UnannotatedHazyImages/metas/test.list'},   # (4809, real)
        "NH-Haze": {'test': 'Dehaze/NH-Haze/metas/test.list'},     # (5, real)
    },

    ## Denoise  (9)
    "Noise": {
        "BSD400": {'train': 'Denoise/BSD400/metas/BSD400.list',
                   'train1': 'Denoise/BSD400/metas/BSD400_Noise_L1.list',
                   'train2': 'Denoise/BSD400/metas/BSD400_Noise_L3.list',
                   'train3': 'Denoise/BSD400/metas/BSD400_Noise_L5.list',},  # (400, syn)    
        "WED": {'train': 'Denoise/WaterlooED/metas/WaterlooED.list',
                'train1': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L1.list',
                'train2': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L3.list',
                'train3': 'Denoise/WaterlooED/metas/WaterlooED_Noise_L5.list',},  # (4744, syn)
        "BSD68": {'test': 'Denoise/BSD68/metas/BSD68.list',
                  'test1': 'Denoise/BSD68/metas/BSD68_Noise_L1.list',
                  'test2': 'Denoise/BSD68/metas/BSD68_Noise_L3.list',
                  'test3': 'Denoise/BSD68/metas/BSD68_Noise_L5.list'},           # (68, syn)
        "Urban": {'test': 'Denoise/Urban100/metas/Urban100.list',
                  'test1': 'Denoise/Urban100/metas/Urban100_Noise_L1.list',
                  'test2': 'Denoise/Urban100/metas/Urban100_Noise_L3.list',
                  'test3': 'Denoise/Urban100/metas/Urban100_Noise_L5.list'},     # (100, syn)
        "CBSD68": {'test': 'Denoise/CBSD68/metas/CBSD68.list',
                   'test1': 'Denoise/CBSD68/metas/CBSD68_Noise_L1.list',
                   'test2': 'Denoise/CBSD68/metas/CBSD68_Noise_L3.list',
                   'test3': 'Denoise/CBSD68/metas/CBSD68_Noise_L5.list',},        # (68, syn)
        "Kodak": {'test': 'Denoise/Kodak/metas/Kodak.list',
                  'test1': 'Denoise/Kodak/metas/Kodak_Noise_L1.list',
                  'test2': 'Denoise/Kodak/metas/Kodak_Noise_L3.list',
                  'test3': 'Denoise/Kodak/metas/Kodak_Noise_L5.list'},           # (24, syn)
        "McMaster": {'test': 'Denoise/McMaster/metas/McMaster.list',
                     'test1': 'Denoise/McMaster/metas/McMaster_Noise_L1.list',
                     'test2': 'Denoise/McMaster/metas/McMaster_Noise_L3.list',
                     'test3': 'Denoise/McMaster/metas/McMaster_Noise_L5.list'},  # (18, syn)
        "Set12": {'test': 'Denoise/Set12/metas/Set12.list',
                  'test1': 'Denoise/Set12/metas/Set12_Noise_L1.list',
                  'test2': 'Denoise/Set12/metas/Set12_Noise_L3.list',
                  'test3': 'Denoise/Set12/metas/Set12_Noise_L5.list',},           # (12, syn)
        "SIDD": {'train': 'Denoise/SIDD/metas/train.list',             # (320, pair)
                'test': 'Denoise/SIDD/metas/test.list'},              # (1280, pair)

        "DIV2K": {'train1': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L1.list',    # (800, pair)
                  'train2': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L3.list',    # (800, pair)
                  'train3': 'SuperResolution/DIV2K/metas/DIV2K_train_pair_Noise_L5.list',    # (800, pair)
                  'val': 'SuperResolution/DIV2K/metas/DIV2K_valid_pair_Noise.list'},         # (100, pair)
        "Flickr2K": {'train1': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L1.list', # (2650, pair)
                     'train2': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L3.list', # (2650, pair)
                     'train3': 'SuperResolution/Flickr2K/metas/Flickr2K_train_pair_Noise_L5.list'},# (2650, pair)
    },

    ## Desnow (2)
    "Snow": {
        "Snow100k": {'train': 'Desnow/Snow100k/metas/train.list'},     # (50000, syn)
        "Snow100k-S": {'test': 'Desnow/Snow100k/metas/test_S.list'},   # (16611, syn)
        "Snow100k-M": {'test': 'Desnow/Snow100k/metas/test_M.list'},   # (16588, syn)
        "Snow100k-L": {'test': 'Desnow/Snow100k/metas/test_L.list'},   # (16801, syn)
        "Snow100k-R": {'test': 'Desnow/Snow100k/metas/test_realistic.list'},   # (1329, real)
        "UHDSnow": {'train': 'Desnow/UHD-Snow/metas/train.list',   # (3000, pair)
                    'test': 'Desnow/UHD-Snow/metas/test.list'},    # (200, pair)
    },

    ## Deblur (3)
    "Blur": {
        "GoPro": {'train': 'Deblur/GoPro/metas/train.list',        # (2103, pair)
                'test': 'Deblur/GoPro/metas/test.list'},         # (1111, pair)
        "HIDE": {'train': 'Deblur/HIDE/metas/train.list',  # (6397, pair)
                'test': 'Deblur/HIDE/metas/test.list'},   # (2025, pair)
        "RealBlur-J": {'test': 'Deblur/RealBlur-J_ECC_IMCORR_centroid_itensity_ref/metas/test.list'},     # (980, pair)
        "RealBlur-R": {'test': 'Deblur/RealBlur-R_BM3D_ECC_IMCORR_centroid_itensity_ref/metas/test.list'},# (980, pair)
    },

    ## Lowlight (6)
    "Low-light": {
        "LOL": {'train': 'LowLight/LOL/metas/train.list',      # (485, pair)
                'test': 'LowLight/LOL/metas/test.list'},       # (15, pair)
        "DICM": {'test': 'LowLight/DICM/metas/test.list'},     # (69, real)
        "MEF": {'test': 'LowLight/MEF/metas/test.list'},       # (17, real)
        "NPE": {'test': 'LowLight/NPE/metas/test.list'},       # (8, real)
        "LIME": {'test': 'LowLight/LIME/metas/test.list'},     # (10, real)
        "VV": {'test': 'LowLight/VV/metas/test.list'},         # (24, real)
    },

    ## Others (1)
    "Unknown": {
        "UDC": {'val': 'Other/UDC/metas/val.list',            # (60, pair)
                'test': 'Other/UDC/metas/test.list'},         # (60, pair)
    },

    ## Composite (1)
    "Composite": {
        "CDD": {
            'train': 'Composite/CDD11/metas/train.list',                        # (13013, pair)
            'test_haze': 'Composite/CDD11/metas/test_haze.list',                # (200, pair)
            'test_haze_rain': 'Composite/CDD11/metas/test_haze_rain.list',      # (200, pair)
            'test_haze_snow': 'Composite/CDD11/metas/test_haze_snow.list',      # (200, pair)
            'test_low': 'Composite/CDD11/metas/test_low.list',                  # (200, pair)
            'test_low_haze': 'Composite/CDD11/metas/test_low_haze.list',        # (200, pair)
            'test_low_haze_rain': 'Composite/CDD11/metas/test_low_haze_rain.list',    # (200, pair)
            'test_low_haze_snow': 'Composite/CDD11/metas/test_low_haze_snow.list',    # (200, pair)
            'test_low_rain': 'Composite/CDD11/metas/test_low_rain.list',        # (200, pair)
            'test_low_snow': 'Composite/CDD11/metas/test_low_snow.list',        # (200, pair)
            'test_rain': 'Composite/CDD11/metas/test_rain.list',                # (200, pair)
            'test_snow': 'Composite/CDD11/metas/test_snow.list',                # (200, pair)
        },
    },
}

def IRImageData(listfile):
    # [degradation, clean, label]
    paths = []
    with open(listfile) as fin:
        for line in fin:
            line = line.strip().split()
            if len(line) == 3:
                paths.append(line)
    paths = sorted(paths)
    # Dataset
    LQ_list = []
    HQ_list = []
    labels = []
    for data in paths:
        lq_pth, hq_pth, label = data
        if os.path.isfile(lq_pth):
            LQ_list.append(lq_pth)
        else:
            LQ_list.append(None)

        if os.path.isfile(hq_pth):
            HQ_list.append(hq_pth)
        else:
            HQ_list.append(None)

        
    return LQ_list, HQ_list

# question dictionary:
question_dict = {
    "Full-Reference": {
        "ONE": [
            "Compared to the reference, what ONE distortion stands out most in the evaluated image?",
            "Determine the leading ONE degradation when comparing the evaluated image to the reference.",
            "Determine the most impactful ONE distortion in the evaluated image compared to the reference.",
            "Highlight the most significant ONE distortion in the evaluated image in comparison to the reference.",
            "Identify the chief ONE degradation in the evaluated image when compared to the reference.",
            "Identify the most notable ONE distortion in the evaluated image's quality when compared to the reference.",
            "In comparison to the reference, what ONE distortion is most prominent in the evaluated image?",
            "What ONE distortion is most apparent in the evaluated image relative to the reference?",
            "What ONE distortion most significantly affects the evaluated image compared to the reference?",
            "What ONE distortion stands out in the evaluated image against the reference?",
            "What critical ONE quality degradation is present in the evaluated image versus the reference?",
        ], 
        "TWO": [
            "Compared to the reference, what TWO distortions stand out most in the evaluated image?",
            "Determine the leading TWO degradations when comparing the evaluated image to the reference.",
            "Determine the most impactful TWO distortions in the evaluated image compared to the reference.",
            "Highlight the most significant TWO distortions in the evaluated image in comparison to the reference.",
            "Identify the chief TWO degradations in the evaluated image when compared to the reference.",
            "Identify the most notable TWO distortions in the evaluated image's quality when compared to the reference.",
            "In comparison to the reference, what TWO distortions are most prominent in the evaluated image?",
            "What TWO distortions are most apparent in the evaluated image relative to the reference?",
            "What TWO distortions most significantly affect the evaluated image compared to the reference?",
            "What TWO distortions stand out in the evaluated image against the reference?",
            "What critical TWO quality degradations are present in the evaluated image versus the reference?",
        ],
        "Common": [
            "Compared to the reference, what distortion(s) stand out most in the evaluated image?",
            "Determine the leading degradation(s) when comparing the evaluated image to the reference.",
            "Determine the most impactful distortion(s) in the evaluated image compared to the reference.",
            "Highlight the most significant distortion(s) in the evaluated image in comparison to the reference.",
            "Identify the chief degradation(s) in the evaluated image when compared to the reference.",
            "Identify the most notable distortion(s) in the evaluated image's quality when compared to the reference.",
            "In comparison to the reference, what distortion(s) are most prominent in the evaluated image?",
            "What critical quality degradation(s) are present in the evaluated image versus the reference?",
            "What distortion(s) are most apparent in the evaluated image relative to the reference?",
            "What distortion(s) most significantly affect the evaluated image compared to the reference?",
            "What distortion(s) stand out in the evaluated image against the reference?"
        ]
    },
    "Non-Reference": {
        "ONE": [
            "Determine the leading ONE degradation in the evaluated image.",
            "Determine the most impactful ONE distortion in the evaluated image.",
            "Highlight the most significant ONE distortion in the evaluated image.",
            "Identify the chief ONE degradation in the evaluated image.",
            "Identify the most critical ONE distortion in the evaluated image.",
            "Identify the most notable ONE distortion in the evaluated image's quality.",
            "In terms of image quality, what is the most glaring ONE issue with the evaluated image?",
            "In the evaluated image, what ONE distortion is most detrimental to image quality?",
            "Pinpoint the foremost ONE image quality issue in the evaluated image.",
            "What ONE distortion is most apparent in the evaluated image?",
            "What ONE distortion is most evident in the evaluated image?",
            "What ONE distortion is most prominent in the evaluated image?",
            "What ONE distortion is most prominent when examining the evaluated image?",
            "What ONE distortion most detrimentally affects the overall quality of the evaluated image?",
            "What ONE distortion most notably affects the clarity of the evaluated image?",
            "What ONE distortion most significantly affects the evaluated image?",
            "What ONE distortion stands out in the evaluated image?",
            "What ONE quality degradation is most apparent in the evaluated image?",
            "What critical ONE quality degradation is present in the evaluated image?",
            "What is the foremost ONE distortion affecting the evaluated image's quality?",
            "What is the leading ONE distortion in the evaluated image?",
            "What is the most critical ONE image quality issue in the evaluated image?",
            "What is the most severe ONE degradation observed in the evaluated image?",
            "What is the primary ONE degradation observed in the evaluated image?"
        ],
        "TWO": [
            "Determine the leading TWO degradations in the evaluated image.",
            "Determine the most impactful TWO distortions in the evaluated image.",
            "Highlight the most significant TWO distortions in the evaluated image.",
            "Identify the chief TWO degradations in the evaluated image.",
            "Identify the most critical TWO distortions in the evaluated image.",
            "Identify the most notable TWO distortions in the evaluated image's quality.",
            "In terms of image quality, what are the most glaring TWO issues with the evaluated image?",
            "In the evaluated image, what TWO distortions are most detrimental to image quality?",
            "Pinpoint the foremost TWO image quality issues in the evaluated image.",
            "What TWO distortions are most apparent in the evaluated image?",
            "What TWO distortions are most evident in the evaluated image?",
            "What TWO distortions are most prominent in the evaluated image?",
            "What TWO distortions are most prominent when examining the evaluated image?",
            "What TWO distortions most detrimentally affect the overall quality of the evaluated image?",
            "What TWO distortions most notably affect the clarity of the evaluated image?",
            "What TWO distortions most significantly affect the evaluated image?",
            "What TWO distortions stand out in the evaluated image?",
            "What TWO quality degradations are most apparent in the evaluated image?",
            "What are the foremost TWO distortions affecting the evaluated image's quality?",
            "What are the leading TWO distortions in the evaluated image?",
            "What are the most critical TWO image quality issues in the evaluated image?",
            "What are the most severe TWO degradations observed in the evaluated image?",
            "What are the primary TWO degradations observed in the evaluated image?",
            "What critical TWO quality degradations are present in the evaluated image?",
        ],
        "Common": [
            "Determine the leading degradation(s) in the evaluated image.",
            "Determine the most impactful distortion(s) in the evaluated image.",
            "Highlight the most significant distortion(s) in the evaluated image.",
            "Identify the chief degradation(s) in the evaluated image.",
            "Identify the most critical distortion(s) in the evaluated image.",
            "Identify the most notable distortion(s) in the evaluated image's quality.",
            "In terms of image quality, what are the most glaring issue(s) with the evaluated image?",
            "In the evaluated image, what distortion(s) are most detrimental to image quality?",
            "Pinpoint the foremost image quality issue(s) in the evaluated image.",
            "What are the foremost distortion(s) affecting the evaluated image's quality?",
            "What are the leading distortion(s) in the evaluated image?",
            "What are the most critical image quality issue(s) in the evaluated image?",
            "What are the most severe degradation(s) observed in the evaluated image?",
            "What are the primary degradation(s) observed in the evaluated image?",
            "What critical quality degradation(s) are present in the evaluated image?",
            "What distortion(s) are most apparent in the evaluated image?",
            "What distortion(s) are most evident in the evaluated image?",
            "What distortion(s) are most prominent in the evaluated image?",
            "What distortion(s) are most prominent when examining the evaluated image?",
            "What distortion(s) most detrimentally affect the overall quality of the evaluated image?",
            "What distortion(s) most notably affect the clarity of the evaluated image?",
            "What distortion(s) most significantly affect the evaluated image?",
            "What distortion(s) stand out in the evaluated image?",
            "What quality degradation(s) are most apparent in the evaluated image?"
        ]
    }
}

def question_generate(ref="Full-Reference", degra="Common"):
    option = f" Answer the question using a single word or phrase."
    template = random.choice(question_dict[ref]["Common"] + question_dict[ref][degra])
    if random.random() >= 0.4:
        template += option
    return template

if __name__ == "__main__":
    for degradation, degra_dict in dataset_dict.items(): # Low-light, [LOL, DICM ...]
        for dname, ddict in degra_dict.items():          # LOL, [train, test, ...]
            for dset, list_path in ddict.items():        # train, path.
                meta_refA = []
                meta_A = []
                meta_syn = []

                # read data list
                paths = []
                list_path = os.path.join(base_rt, list_path)
                with open(list_path) as fin:
                    for line in fin:
                        line = line.strip().split()
                        if len(line) == 3:
                            paths.append(line)
                paths = sorted(paths)

                # Dataset
                LQ_list = []
                HQ_list = []
                for data in paths:
                    lq_pth, hq_pth, label = data

                    if os.path.isfile(hq_pth):
                        HQ_list.append(hq_pth)  
                        image_ref = os.path.relpath(hq_pth, base_rt).replace("\\", "/")
                        id = os.path.basename(image_ref)
                    else:
                        image_ref = None

                    if os.path.isfile(lq_pth):
                        LQ_list.append(lq_pth)
                        image_A = os.path.relpath(lq_pth, base_rt).replace("\\", "/")
                        id = os.path.basename(image_A)
                    else:
                        image_A = None

                    if degradation == "Composite":
                        key_dict = {"haze": "Fog",
                                    "low": "Low-light",
                                    "rain": "Rain",
                                    "snow": "Snow"}
                        new_label = []
                        for one_label in label.split("_"):
                            new_label.append(key_dict[one_label])
                        annotation = ", ".join(new_label)
                    else:
                        annotation = degradation

                    if degradation == "Composite":
                        ref_question = question_generate(ref="Full-Reference", degra="Common")
                        nref_question = question_generate(ref="Non-Reference", degra="Common")
                    else:
                        ref_question = question_generate(ref="Full-Reference", degra="ONE")
                        nref_question = question_generate(ref="Non-Reference", degra="ONE")

                    meta_refA.append({
                        "distortion_class": degradation,
                        "distortion_name": degradation,
                        "severity": 3,
                        "id": id,
                        "image_ref": image_ref, 
                        "image_A": image_A, 
                        "image_B": None, 
                        "task_type": "quality_single_A",
                        "conversations": [
                            {
                                "from": "human",
                                "value": ref_question,
                            },
                            {
                                "from": "gpt",
                                "value": annotation
                            }
                        ],
                    })

                    meta_A.append({
                        "distortion_class": degradation,
                        "distortion_name": degradation,
                        "severity": 3,
                        "id": id,
                        "image_ref": image_ref, 
                        "image_A": image_A, 
                        "image_B": None, 
                        "task_type": "quality_single_A_noref",
                        "conversations": [
                            {
                                "from": "human",
                                "value": nref_question,
                            },
                            {
                                "from": "gpt",
                                "value": annotation
                            }
                        ],
                    })

                    meta_syn.append({
                        "distortion_class": degradation,
                        "distortion_name": degradation,
                        "severity": 3,
                        "id": id,
                        "image_ref": image_ref, 
                        "image_A": None, 
                        "image_B": None, 
                        "task_type": "quality_single_A_noref",
                        "conversations": [
                            {
                                "from": "human",
                                "value": nref_question,
                            },
                            {
                                "from": "gpt",
                                "value": annotation
                            }
                        ],
                    })

                if len(LQ_list) > 0 and len(HQ_list) > 0 and len(LQ_list) == len(HQ_list):   # pair
                    meta_refA_pth = list_path.replace(".list", "_iqa_refA_brief.json")
                    meta_A_pth = list_path.replace(".list", "_iqa_A_brief.json")
                    with open(meta_refA_pth, "w") as f:
                        json.dump(meta_refA, f, indent=4)
                    with open(meta_A_pth, "w") as f:
                        json.dump(meta_A, f, indent=4)
                    
                    print(f"[{os.path.relpath(meta_refA_pth, base_rt)}, ],     # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A,       {degradation}, {dname}-{dset}")
                    print(f"[{os.path.relpath(meta_A_pth, base_rt)}, ],     # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}")
                
                elif len(LQ_list) > 0 and len(HQ_list) == 0:    # real image
                    meta_A_pth = list_path.replace(".list", "_iqa_A_brief.json")
                    with open(meta_A_pth, "w") as f:
                        json.dump(meta_A, f, indent=4)
                    print(f"[{os.path.relpath(meta_A_pth, base_rt)}, ],     # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}")
                
                elif len(LQ_list) == 0 and len(HQ_list) > 0:    # syn image
                    meta_refA_pth = list_path.replace(".list", "_iqa_syn_refA_brief.json")
                    meta_syn_pth = list_path.replace(".list", "_iqa_syn_A_brief.json")
                    with open(meta_refA_pth, "w") as f:
                        json.dump(meta_refA, f, indent=4)
                    with open(meta_syn_pth, "w") as f:
                        json.dump(meta_syn, f, indent=4)
                    print(f"[{os.path.relpath(meta_refA_pth, base_rt)}, ],     # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A,       {degradation}, {dname}-{dset}")
                    print(f"[{os.path.relpath(meta_syn_pth, base_rt)}, ],     # LQ[{len(LQ_list)}], HQ[{len(HQ_list)}], quality_single_A_noref, {degradation}, {dname}-{dset}")
                
                else:
                    raise KeyError(f"the task is not matched, please check the dataset {list_path}")