-
Notifications
You must be signed in to change notification settings - Fork 7
/
a.py
127 lines (109 loc) · 3.64 KB
/
a.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
121
122
123
124
125
126
127
import os
import glob
import numpy as np
from utils.y4m_tools import read_y4m
from data.info_list import CARTOONS
from data.youku import SISRDataset
def main(dir):
video_paths = glob.glob(f"{dir}/*h_GT")
avg = list()
for i, vp in enumerate(video_paths):
# if os.path.basename(vp)[-16:-5] not in CARTOONS:
# continue
paths = glob.glob(f"{vp}/*npy")
va = np.zeros([len(paths), 3], dtype=np.float64)
for j, p in enumerate(paths):
img = np.load(p).astype(np.float64)
va[j, :] = np.mean(img.mean(axis=0), axis=0)
avg.append(va.mean(axis=0))
print(f"{vp} mean: {avg[-1]}")
avg = np.array(avg)
np.save('results/car.npy', avg)
print(avg.mean(axis=0))
return
def cal_std():
mean = np.array([99.00332925, 124.7647323, 128.69159715], dtype=np.float64)
video_paths = glob.glob(f"D:/youku/data/*.y4m")
all_std = list()
for vp in video_paths:
frames, _ = read_y4m(vp)
std_l = np.zeros([len(frames), 3], dtype=np.float64)
for j in range(len(frames)):
diff = frames[j].astype(np.float64) - mean
std = np.sqrt(diff * diff)
std_l[j, :] = np.mean(std.mean(axis=0), axis=0)
all_std.append(std_l.mean(axis=0))
print(f"{vp} mean: {all_std[-1]}")
all_std = np.array(all_std)
np.save('std.npy', all_std)
print(all_std.mean(axis=0))
print((all_std / 255).mean(axis=0))
return
def stat_info():
video_paths = glob.glob(f"D:/youku/data/*.y4m")
all_mm = list()
for vp in video_paths:
frames, _ = read_y4m(vp)
std_max = np.zeros([len(frames), 3], dtype=np.float64)
std_min = np.zeros([len(frames), 3], dtype=np.float64)
for j in range(len(frames)):
std_max[j, :] = np.max(frames[j].max(axis=0), axis=0)
std_min[j, :] = np.min(frames[j].min(axis=0), axis=0)
all_mm.append(std_max.max(axis=0))
all_mm.append(std_min.min(axis=0))
print(f"{vp} min: {all_mm[-1]}, max: {all_mm[-2]}")
all_mm = np.array(all_mm)
np.save('stat.npy', all_mm)
print(all_mm.min(axis=0))
print(all_mm.max(axis=0))
print((all_mm / 255).min(axis=0))
print((all_mm / 255).max(axis=0))
return
if __name__ == '__main__':
DIR = r"D:/DATA/train"
import SimpleITK as sitk
import matplotlib.pyplot as plt
import numpy as np
image = sitk.ReadImage('C:/users/z/desktop/628127.mhd')
image = sitk.GetArrayFromImage(image)
image = np.squeeze(image[7, ...]) # if the image is 3d, the slice is integer
plt.imshow(image, cmap='gray')
plt.axis('off')
plt.show()
# ds = glob.glob(f"{DIR}/*_l")
# for dp in ds:
# fpl = glob.glob(f'{dp}/*.npy')
# for i, fp in enumerate(fpl):
# if i % 10 != 0:
# os.remove(fp)
# os.remove(fp.replace('_l', '_h_GT'))
# else:
# print(fp)
# stat_info()
cfg = {'data_dir': DIR,
'scale': 4,
'v_freq': 5,
'n_workers': 6, # per GPU
'batch_size': 16,
'patch_size': 256,
'augmentation': True,
'color': 'RGB'}
yk = SISRDataset(DIR, True, 256, rgb=True)
yk.__getitem__(0)
# test()
main(DIR)
pass
# header: 'signature width height fps interlacing pixelAspectRadio colorSpace comment'
"""
均值
99.00332925, 124.7647323 , 128.69159715
0.38824835, 0.48927346, 0.50467293
标准差:
[51.16912088 9.29543705 9.23474285]
[0.20066322 0.03645269 0.03621468]
最大最小值
[0. 0. 8.]
[255. 235. 255.]
[0. 0. 0.03137255]
[1. 0.92156863 1. ]
"""