Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
MPBA Radiomics
RADLER
Commits
ce1f12a5
Commit
ce1f12a5
authored
Mar 17, 2020
by
Alessia Marcolini
Browse files
Extract both CT+PT for 'deep' dataset and CT+PT+segmentation for 'radiomics' dataset
parent
f0cb9154
Changes
1
Show whitespace changes
Inline
Side-by-side
01_preprocessing/extract_roi_volume.py
View file @
ce1f12a5
...
@@ -11,25 +11,28 @@ import dicom_utils.dicom_utils as du
...
@@ -11,25 +11,28 @@ import dicom_utils.dicom_utils as du
import
dicom_utils.dicom_utils.visualize
as
viz
import
dicom_utils.dicom_utils.visualize
as
viz
import
gc
import
gc
from
utils
import
sitk_to_numpy
,
filter_outbounds
from
config
import
get_project_root
from
config
import
get_project_root
# os.chdir(PATH)
from
utils
import
sitk_to_numpy
,
filter_outbounds
#%%
#%%
PROJECT_ROOT
=
get_project_root
()
PROJECT_ROOT
=
get_project_root
()
DATASET_NAME
=
'HN_
BZ
'
DATASET_NAME
=
'HN_
val
'
PROJECT_DATA_PATH
=
PROJECT_ROOT
/
'data'
/
DATASET_NAME
PROJECT_DATA_PATH
=
PROJECT_ROOT
/
'data'
/
DATASET_NAME
PROCESSED_DATA_PATH
=
PROJECT_DATA_PATH
/
'processed'
PROCESSED_DATA_PATH
=
PROJECT_DATA_PATH
/
'processed'
CLINICAL_DATA_FILENAME_CLEAN
=
f
'clinical_
{
DATASET_NAME
}
.csv'
CLINICAL_DATA_FILENAME_CLEAN
=
f
'clinical_
{
DATASET_NAME
}
.csv'
DCM_DIR
=
PROCESSED_DATA_PATH
/
'dcm'
DCM_DIR
=
PROCESSED_DATA_PATH
/
'dcm'
BBOX_OUT_DIR
=
PROCESSED_DATA_PATH
/
'bbox'
BBOX_OUT_DIR
=
PROCESSED_DATA_PATH
/
'bbox'
BBOX_SUBDATASET
=
'bbox_64'
BBOX_SUBDATASET_DEEP
=
'bbox_64'
BBOX_SUBDATASET_RAD
=
'bbox_64_rad'
OUTDIR
=
BBOX_OUT_DIR
/
BBOX_SUBDATASET
OUTDIR_DEEP
=
BBOX_OUT_DIR
/
BBOX_SUBDATASET_DEEP
OUTDIR_RAD
=
BBOX_OUT_DIR
/
BBOX_SUBDATASET_RAD
os
.
makedirs
(
OUTDIR
,
exist_ok
=
False
)
os
.
makedirs
(
OUTDIR_DEEP
,
exist_ok
=
False
)
os
.
makedirs
(
OUTDIR_RAD
,
exist_ok
=
False
)
CT_ranges
=
[
-
1050
,
3050
]
CT_ranges
=
[
-
1050
,
3050
]
...
@@ -94,22 +97,35 @@ for i, row in tqdm(clinical.iterrows()):
...
@@ -94,22 +97,35 @@ for i, row in tqdm(clinical.iterrows()):
scan_PT_box
=
sitk
.
Resample
(
scan_PT
,
scan_CT_box
)
scan_PT_box
=
sitk
.
Resample
(
scan_PT
,
scan_CT_box
)
scan_PT_box
=
filter_outbounds
(
scan_PT_box
,
PT_ranges
)
scan_PT_box
=
filter_outbounds
(
scan_PT_box
,
PT_ranges
)
# segmentation_box = sitk.Resample(segmentation, scan_CT_box)
segmentation_box
=
sitk
.
Resample
(
segmentation
,
scan_CT_box
)
# segmentation_box = gaussian.Execute(segmentation_box)
# segmentation_box = gaussian.Execute(segmentation_box)
# out
= segmentation_box
>
0.5
mask_box
=
segmentation_box
>
0.5
start_mm
=
start_mm
+
5
# remove margin
start_mm
=
start_mm
+
5
# remove margin
stop_mm
=
stop_mm
-
5
# remove margin
stop_mm
=
stop_mm
-
5
# remove margin
scan_CT_box
=
du
.
extract_volume
(
scan_CT_box
,
start_mm
,
stop_mm
)
scan_CT_box
=
du
.
extract_volume
(
scan_CT_box
,
start_mm
,
stop_mm
)
scan_PT_box
=
du
.
extract_volume
(
scan_PT_box
,
start_mm
,
stop_mm
)
scan_PT_box
=
du
.
extract_volume
(
scan_PT_box
,
start_mm
,
stop_mm
)
mask_box
=
du
.
extract_volume
(
mask_box
,
start_mm
,
stop_mm
)
out
=
np
.
stack
([
sitk_to_numpy
(
scan_CT_box
),
sitk_to_numpy
(
scan_PT_box
)],
axis
=
0
)
out_deep
=
np
.
stack
(
[
sitk_to_numpy
(
scan_CT_box
),
sitk_to_numpy
(
scan_PT_box
)],
axis
=
0
)
out_rad
=
np
.
stack
(
[
sitk_to_numpy
(
scan_CT_box
),
sitk_to_numpy
(
scan_PT_box
),
sitk_to_numpy
(
mask_box
),
],
axis
=
0
,
)
# save
# save
np
.
save
(
OUTDIR
/
filename_out
,
out
)
np
.
save
(
OUTDIR_DEEP
/
filename_out
,
out_deep
)
np
.
save
(
OUTDIR_RAD
/
filename_out
,
out_rad
)
del
scan_CT_box
,
scan_PT_box
,
segmentation
,
out
del
scan_CT_box
,
scan_PT_box
,
segmentation
,
mask_box
,
out_deep
,
out_rad
gc
.
collect
()
gc
.
collect
()
except
Exception
as
e
:
except
Exception
as
e
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment