-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathWL.py
More file actions
32 lines (28 loc) · 913 Bytes
/
WL.py
File metadata and controls
32 lines (28 loc) · 913 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
import numpy as np
import pydicom
def WL(data, WC, WW):
# WC: 窗位 WW:窗宽
data = data.pixel_array*data.RescaleSlope + data.RescaleIntercept
min = (2*WC - WW) / 2.0
max = (2*WC + WW) / 2.0
# print(max, min)
idx_max = np.where(data > max)
idx_min = np.where(data < min)
idx_in = np.where((data >= min) & (data <= max))
data = (data -min) * 254 / (max - min)
data[idx_max] = 255
data[idx_min] = 0
return data
def WL_NII(data, WC, WW):
# WC: 窗位 WW:窗宽
data = data.pixel_array*data.RescaleSlope + data.RescaleIntercept
min = (2*WC - WW) / 2.0
max = (2*WC + WW) / 2.0
# print(max, min)
idx_max = np.where(data > max)
idx_min = np.where(data < min)
idx_in = np.where((data >= min) & (data <= max))
data = (data -min) * 254 / (max - min)
data[idx_max] = 255
data[idx_min] = 0
return data