forked from arcadelab/deepdrr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdownsample_tool.py
48 lines (39 loc) · 1.83 KB
/
downsample_tool.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
import pydicom as dicom
import glob
import copy
import numpy as np
from skimage.transform import resize
import segmentation
import math
def downsample_tool(ori_CT_volume, CT_volume, CT_voxel_size, tool_volume, tool_voxel_size, CT_materials, tool_materials,
origin, tool_origin):
tool_size = np.shape(tool_volume)
CT_size = np.shape(CT_volume)
tool_volume_temp = copy.copy(tool_volume)
tool_volume_temp_ori = copy.copy(tool_volume)
CT_volume_temp = copy.copy(CT_volume)
CT_volume_temp_ori = copy.copy(ori_CT_volume)
CT_materials_temp = copy.copy(CT_materials)
tool_materials_temp = copy.copy(tool_materials)
##Calculate origin bias
bias_x = tool_origin[0] - origin[0]
bias_y = tool_origin[1] - origin[1]
bias_z = tool_origin[2] - origin[2]
[i, j, k] = np.nonzero(np.array(tool_volume_temp))
x = np.ceil(
(bias_x + i * tool_voxel_size[0] + CT_size[0] * CT_voxel_size[0] / 2 - tool_size[0] * tool_voxel_size[0] / 2) /
CT_voxel_size[0])
x = np.minimum(x, CT_size[0])
y = np.ceil(
(bias_y + j * tool_voxel_size[1] + CT_size[1] * CT_voxel_size[1] / 2 - tool_size[1] * tool_voxel_size[1] / 2) /
CT_voxel_size[1])
y = np.minimum(y, CT_size[1])
z = np.ceil(
(bias_z + k * tool_voxel_size[2] + CT_size[2] * CT_voxel_size[2] / 2 - tool_size[2] * tool_voxel_size[2] / 2) /
CT_voxel_size[2])
z = np.minimum(z, CT_size[2])
tool_volume_temp[i, j, k] = CT_volume_temp[x.astype(int), y.astype(int), z.astype(int)]
tool_volume_temp_ori[i, j, k] = CT_volume_temp_ori[x.astype(int), y.astype(int), z.astype(int)]
for mat in CT_materials_temp:
tool_materials_temp[mat][i, j, k] = CT_materials_temp[mat][x.astype(int), y.astype(int), z.astype(int)]
return tool_volume_temp, tool_volume_temp_ori, tool_materials_temp