Spaces:
Sleeping
Sleeping
crop foreground (#4)
Browse files- add crop foreground (be79dc591f01372be453d63eed50d430485a61be)
app.py
CHANGED
@@ -296,8 +296,17 @@ with col2:
|
|
296 |
img_nii = None
|
297 |
if st.session_state.preds_3D_ori is not None and st.session_state.data_item is not None:
|
298 |
meta_dict = st.session_state.data_item['meta']
|
299 |
-
|
300 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
301 |
|
302 |
with tempfile.NamedTemporaryFile(suffix=".nii.gz") as tmpfile:
|
303 |
nib.save(img_nii, tmpfile.name)
|
@@ -323,9 +332,6 @@ with col3:
|
|
323 |
st.session_state.running = True
|
324 |
st.rerun()
|
325 |
|
326 |
-
# if len(st.session_state.points) > 0:
|
327 |
-
# st.write(st.session_state.points)
|
328 |
-
|
329 |
if st.session_state.running:
|
330 |
st.session_state.running = False
|
331 |
with st.status("Running...", expanded=False) as status:
|
|
|
296 |
img_nii = None
|
297 |
if st.session_state.preds_3D_ori is not None and st.session_state.data_item is not None:
|
298 |
meta_dict = st.session_state.data_item['meta']
|
299 |
+
foreground_start_coord = st.session_state.data_item['foreground_start_coord']
|
300 |
+
foreground_end_coord = st.session_state.data_item['foreground_end_coord']
|
301 |
+
original_shape = st.session_state.data_item['ori_shape']
|
302 |
+
pred_array = st.session_state.preds_3D_ori
|
303 |
+
original_array = np.zeros(original_shape)
|
304 |
+
original_array[foreground_start_coord[0]:foreground_end_coord[0],
|
305 |
+
foreground_start_coord[1]:foreground_end_coord[1],
|
306 |
+
foreground_start_coord[2]:foreground_end_coord[2]] = pred_array
|
307 |
+
|
308 |
+
original_array = original_array.transpose(2, 1, 0)
|
309 |
+
img_nii = nib.Nifti1Image(original_array, affine=meta_dict['affine'])
|
310 |
|
311 |
with tempfile.NamedTemporaryFile(suffix=".nii.gz") as tmpfile:
|
312 |
nib.save(img_nii, tmpfile.name)
|
|
|
332 |
st.session_state.running = True
|
333 |
st.rerun()
|
334 |
|
|
|
|
|
|
|
335 |
if st.session_state.running:
|
336 |
st.session_state.running = False
|
337 |
with st.status("Running...", expanded=False) as status:
|
model/data_process/__pycache__/demo_data_process.cpython-39.pyc
CHANGED
Binary files a/model/data_process/__pycache__/demo_data_process.cpython-39.pyc and b/model/data_process/__pycache__/demo_data_process.cpython-39.pyc differ
|
|
model/data_process/demo_data_process.py
CHANGED
@@ -60,7 +60,7 @@ def process_ct_gt(case_path, spatial_size=(32,256,256)):
|
|
60 |
DimTranspose(keys=["image"]),
|
61 |
MinMaxNormalization(),
|
62 |
transforms.SpatialPadd(keys=["image"], spatial_size=spatial_size, mode='constant'),
|
63 |
-
|
64 |
transforms.ToTensord(keys=["image"]),
|
65 |
]
|
66 |
)
|
@@ -81,12 +81,14 @@ def process_ct_gt(case_path, spatial_size=(32,256,256)):
|
|
81 |
ct_voxel_ndarray = np.array(ct_voxel_ndarray).squeeze()
|
82 |
ct_voxel_ndarray = np.expand_dims(ct_voxel_ndarray, axis=0)
|
83 |
item['image'] = ct_voxel_ndarray
|
|
|
84 |
|
85 |
# transform
|
86 |
item = transform(item)
|
87 |
item_zoom_out = zoom_out_transform(item)
|
88 |
item['zoom_out_image'] = item_zoom_out['image']
|
89 |
-
|
|
|
90 |
item_z = z_transform(item)
|
91 |
item['z_image'] = item_z['image']
|
92 |
item['meta'] = meta_tensor_dict
|
|
|
60 |
DimTranspose(keys=["image"]),
|
61 |
MinMaxNormalization(),
|
62 |
transforms.SpatialPadd(keys=["image"], spatial_size=spatial_size, mode='constant'),
|
63 |
+
transforms.CropForegroundd(keys=["image"], source_key="image"),
|
64 |
transforms.ToTensord(keys=["image"]),
|
65 |
]
|
66 |
)
|
|
|
81 |
ct_voxel_ndarray = np.array(ct_voxel_ndarray).squeeze()
|
82 |
ct_voxel_ndarray = np.expand_dims(ct_voxel_ndarray, axis=0)
|
83 |
item['image'] = ct_voxel_ndarray
|
84 |
+
ori_shape = np.swapaxes(ct_voxel_ndarray, -1, -3).shape[1:]
|
85 |
|
86 |
# transform
|
87 |
item = transform(item)
|
88 |
item_zoom_out = zoom_out_transform(item)
|
89 |
item['zoom_out_image'] = item_zoom_out['image']
|
90 |
+
item['ori_shape'] = ori_shape
|
91 |
+
|
92 |
item_z = z_transform(item)
|
93 |
item['z_image'] = item_z['image']
|
94 |
item['meta'] = meta_tensor_dict
|