Skip to content

Commit

Permalink
Merge pull request #89 from sct-pipeline/transfo_label
Browse files Browse the repository at this point in the history
Crop around transformed segmentation
  • Loading branch information
PaulBautin authored Oct 31, 2020
2 parents 61436ba + fdd04cd commit c7e6cee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion csa_rescale_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def main():

# add useful columns to dataframe
df_vert['basename'] = list(os.path.basename(path).split('.nii.gz')[0] for path in df_vert['Filename'])
df_vert['rescale'] = list(float(b.split('crop_r')[1].split('_')[0]) for b in df_vert['basename'])
df_vert['rescale'] = list(float(b.split('RPI_r_r')[1].split('_')[0]) for b in df_vert['basename'])
df_vert['slices'] = list(int(slices.split(':')[1]) - int(slices.split(':')[0]) + 1 for slices in df_vert['Slice (I->S)'])

# verify if vertlevels of interest were given in input by user
Expand Down
23 changes: 11 additions & 12 deletions process_data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,6 @@ segment_and_label_if_does_not_exist(){
fi
# Create labels in the Spinal Cord
sct_label_utils -i ${file_seg}_labeled.nii.gz -vert-body 0 -o ${FILELABEL}.nii.gz

# dilate segmentation (for cropping)
sct_maths -i ${file_seg}.nii.gz -dilate 15 -shape cube -o ${file_seg}_dil.nii.gz
FILE_SEG_DIL=${file_seg}_dil
FILE_SEG_LABEL=${file_seg}_labeled
}

Expand Down Expand Up @@ -140,13 +136,6 @@ file_label=${FILE_SEG_LABEL}
end=`date +%s`
runtime=$((end-start))
echo "+++++++++++ TIME: Duration of labelling: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec"

# crop image
sct_crop_image -i ${file}.nii.gz -m ${FILE_SEG_DIL}.nii.gz
file=${file}_crop
# crop labeled segmentation
sct_crop_image -i ${file_label}.nii.gz -m ${FILE_SEG_DIL}.nii.gz
file_label=${file_label}_crop
cd ../


Expand Down Expand Up @@ -184,13 +173,23 @@ for r_coef in ${R_COEFS[@]}; do
runtime=$((end-start))
echo "+++++++++++ TIME: Duration of of image transfo t${i_transfo}: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec"
# transform the labeled segmentation with same transfo values

start=`date +%s`
affine_transfo -i ${file_label}.nii.gz -transfo ${PATH_RESULTS}/transfo_${file} -config $config_script -o _r${r_coef}_t${i_transfo} -r ${r_coef} -interpolation 0
file_label_r_t=${file_label}_r${r_coef}_t${i_transfo}
end=`date +%s`
runtime=$((end-start))
echo "+++++++++++ TIME: Duration of labelling transfo t${i_transfo}: $(($runtime / 3600))hrs $((($runtime / 60) % 60))min $(($runtime % 60))sec"

# dilate labelled segmentation (for cropping)
file_label_dil=${file_label_r_t}_dil
sct_maths -i ${file_label_r_t}.nii.gz -dilate 15 -shape cube -o ${file_label_dil}.nii.gz
# crop image
sct_crop_image -i ${file_r_t}.nii.gz -m ${file_label_dil}.nii.gz
file_r_t=${file_r_t}_crop
# crop labelled segmentation
sct_crop_image -i ${file_label_r_t}.nii.gz -m ${file_label_dil}.nii.gz
file_label_r_t=${file_label_r_t}_crop

# Segment spinal cord (only if it does not exist)
start=`date +%s`
sct_deepseg_sc -i ${file_r_t}.nii.gz -c ${contrast}
Expand Down

0 comments on commit c7e6cee

Please sign in to comment.