Skip to content

Commit

Permalink
Use manual seg and labeling (#62)
Browse files Browse the repository at this point in the history
Fixes #54, Fixes #60
  • Loading branch information
jcohenadad authored Jan 17, 2024
1 parent 231990d commit 10dabac
Showing 1 changed file with 23 additions and 14 deletions.
37 changes: 23 additions & 14 deletions data_processing.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"from scipy.interpolate import interp1d\n",
"from scipy.ndimage import uniform_filter1d\n",
"from scipy.stats import f_oneway\n",
"import shutil\n",
"from statsmodels.stats.multicomp import pairwise_tukeyhsd"
]
},
Expand Down Expand Up @@ -170,6 +171,7 @@
"\n",
"path_data = os.getcwd()\n",
"print(f\"path_data: {path_data}\")\n",
"path_labels = os.path.join(path_data, \"derivatives\", \"labels\")\n",
"path_qc = os.path.join(path_data, \"qc\")\n",
"shim_modes = [\"CP\", \"patient\", \"volume\", \"phase\", \"CoV\", \"target\", \"SAReff\"]\n",
"shim_modes_MPRAGE = [\"CP\", \"CoV\"] # TODO: change variable name PEP8\n",
Expand Down Expand Up @@ -198,18 +200,30 @@
"metadata": {},
"outputs": [],
"source": [
"# Run segmentation on CoV_T1w scan\n",
"# Run segmentation on CoV_T1w scan, unless it is already in the derivatives/labels\n",
"\n",
"for subject in subjects:\n",
" os.chdir(os.path.join(path_data, subject, \"anat\"))\n",
" !sct_deepseg_sc -i {subject}_acq-CoV_T1w.nii.gz -c t1 -qc {path_qc}"
" fname_manual_seg = os.path.join(path_labels, subject, \"anat\", f\"{subject}_acq-CoV_T1w_seg.nii.gz\")\n",
" if os.path.exists(fname_manual_seg):\n",
" # Manual segmentation already exists. Copy it to local folder\n",
" print(f\"{subject}: Manual segmentation found\\n\")\n",
" shutil.copyfile(fname_manual_seg, f\"{subject}_acq-CoV_T1w_seg.nii.gz\")\n",
" # Generate QC report to make sure the manual segmentation is correct\n",
" !sct_qc -i {subject}_acq-CoV_T1w.nii.gz -s {subject}_acq-CoV_T1w_seg.nii.gz -p sct_deepseg_sc -qc {path_qc} -qc-subject {subject}\n",
" else:\n",
" # Manual segmentation does not exist. Run automatic segmentation.\n",
" print(f\"{subject}: Manual segmentation not found\")\n",
" !sct_deepseg_sc -i {subject}_acq-CoV_T1w.nii.gz -c t1 -qc {path_qc}"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "663bb98c",
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"# Crop the images for faster processing\n",
Expand All @@ -229,19 +243,14 @@
"source": [
"# Vertebral labeling on the CoV_T1w scan\n",
"\n",
"# Given the low resolution of the GRE scan, the automatic detection of C2-C3 disc is unreliable. Therefore, we \n",
"# need to use the manual disc labels that are part of the dataset.\n",
"for subject in subjects:\n",
" os.chdir(os.path.join(path_data, subject, \"anat\"))\n",
" !sct_label_vertebrae -i {subject}_acq-CoV_T1w_crop.nii.gz -s {subject}_acq-CoV_T1w_crop_seg.nii.gz -c t1 -qc {path_qc}\n",
" \n",
"# TODO: replace by code below\n",
"# https://github.com/shimming-toolbox/rf-shimming-7t/issues/59\n",
"# Given the low resolution of the GRE scan, the automatic detection of C2-C3 disc is unreliable. Therefore we need to use the manual disc labels that are part of the dataset.\n",
"# for subject in subjects:\n",
"# os.chdir(os.path.join(path_data, subject, \"anat\"))\n",
"# fname_label_discs = os.path.join(path_data, \"derivatives\", \"labels\", subject, \"anat\", f\"{subject}_acq-CoV_T2starw_label-discs_dseg.nii.gz\")\n",
"# !sct_label_utils -i {subject}_acq-CoV_T2starw_crop_seg.nii.gz -disc {fname_label_discs} -o {subject}_acq-CoV_T2starw_crop_seg_labeled.nii.gz\n",
"# # Generate QC report to assess labeled segmentation\n",
"# !sct_qc -i {subject}_acq-CoV_T2starw_crop.nii.gz -s {subject}_acq-CoV_T2starw_crop_seg_labeled.nii.gz -p sct_label_vertebrae -qc {path_qc} -qc-subject {subject}"
" fname_label_discs = os.path.join(path_labels, subject, \"anat\", f\"{subject}_acq-CoV_T1w_label-discs_dseg.nii.gz\")\n",
" !sct_label_utils -i {subject}_acq-CoV_T1w_crop_seg.nii.gz -disc {fname_label_discs} -o {subject}_acq-CoV_T1w_crop_seg_labeled.nii.gz\n",
" # Generate QC report to assess labeled segmentation\n",
" !sct_qc -i {subject}_acq-CoV_T1w_crop.nii.gz -s {subject}_acq-CoV_T1w_crop_seg_labeled.nii.gz -p sct_label_vertebrae -qc {path_qc} -qc-subject {subject}"
]
},
{
Expand Down

0 comments on commit 10dabac

Please sign in to comment.