-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata_process.py
47 lines (41 loc) · 1.25 KB
/
data_process.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
# -*- coding:utf-8 -*-
import SimpleITK as sitk
import cv2
from keras.preprocessing.image import img_to_array, load_img
def to_hu(image):
MIN_BLOOD = -10
MAX_BLOOD = 400
print(MAX_BLOOD, "===", MIN_BLOOD)
image = (image - MIN_BLOOD) / (MAX_BLOOD - MIN_BLOOD)
image[image > 1] = 1.
image[image < 0] = 0.
return image
image = sitk.ReadImage("20001.dcm")
image_array = sitk.GetArrayFromImage(image) # z, y, x
print(image_array)
print(image_array.shape)
image_array = image_array.swapaxes(0, 2)
image_array = image_array.swapaxes(0, 1)
# 可以使用 transpose
# 维数变化
print("image_array==shape==>", image_array.shape)
image_array[image_array == -2000] = 0
# np.savetxt("test.txt", image_array)
image_array = to_hu(image_array)*2
image_array = image_array * 255
#image_array[image_array < 40] = 0
print(image_array[255][255])
print(image_array[160][160])
cv2.imwrite("info.png", image_array)
# np.savetxt("test2.txt", image_array * 255)
# images = np.squeeze(image_array)
#
# plt.imshow(images, cmap="gray")
# plt.axis("off")
# plt.savefig("test.png")
# plt.show()
print("image_array done")
img = load_img("20001_mask.png", color_mode="grayscale")
# img = img_to_array(img)
label = img_to_array(img)
print("label==shape ==", label.shape)