Skip to content

Commit

Permalink
problem with registration with vert levels
Browse files Browse the repository at this point in the history
  • Loading branch information
plbenveniste committed Aug 3, 2023
1 parent 511c168 commit 6e70cb1
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions lesion_analysis/time_point_lesion_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,28 @@ def main():
second_lesion_segmentation = nib.load(args.segmentation_second_image)

#first we segment the spinal cord on the two images using sct_deepseg_sc
os.system('sct_deepseg_sc -i ' + args.input_first_image + ' -c t2 -o ' + args.output_folder + '/first_image_sc_segmentation.nii.gz')
os.system('sct_deepseg_sc -i ' + args.input_second_image + ' -c t2 -o' + args.output_folder + '/second_image_sc_segmentation.nii.gz')
#os.system('sct_deepseg_sc -i ' + args.input_first_image + ' -c t2 -o ' + args.output_folder + '/first_image_sc_segmentation.nii.gz')
#os.system('sct_deepseg_sc -i ' + args.input_second_image + ' -c t2 -o' + args.output_folder + '/second_image_sc_segmentation.nii.gz')

#then we register the images and the segmentations with the first image as reference using sct_register_multimodal
os.system('sct_register_multimodal -i ' + args.input_second_image + ' -d ' + args.input_first_image + ' -iseg ' + args.output_folder + '/second_image_sc_segmentation.nii.gz' + ' -dseg ' + args.output_folder + '/first_image_sc_segmentation.nii.gz' + ' -o ' + args.output_folder + '/second_image_registered.nii.gz' + ' -owarp ' + args.output_folder +'/warping_M0_to_M12.nii.gz')
#then we compute the vertebral levels of the images using sct_label_vertebrae
#os.system('sct_label_vertebrae -i ' + args.input_first_image + ' -s ' + args.output_folder + '/first_image_sc_segmentation.nii.gz' + ' -c t2 -qc ' + args.output_folder + '/qc' + ' -ofolder ' + args.output_folder)
#os.system('sct_label_vertebrae -i ' + args.input_second_image + ' -s ' + args.output_folder + '/second_image_sc_segmentation.nii.gz' + ' -c t2 -qc ' + args.output_folder + '/qc' + ' -ofolder ' + args.output_folder)

#then we apply the warping field to the segmentation of the lesions on the second images using sct_apply_transfo
os.system('sct_apply_transfo -i ' + args.segmentation_second_image + ' -d ' + args.segmentation_first_image + ' -w ' + args.output_folder + '/warping_M0_to_M12.nii.gz' + ' -o ' + args.output_folder + '/second_image_lesion_segmentation_registered.nii.gz' + ' -x linear')

#then we register the images and the segmentations with the first image as reference using sct_register_multimodal using both the spinal cord segmentation and the vertebral levels
parameters = 'step=0,type=label,dof=Tx_Ty_Tz:step=1,type=seg,algo=slicereg,poly=5:step=2,type=im,algo=syn,metric=MI,deformation=1x1x1,smooth=3'

This comment has been minimized.

Copy link
@valosekj

valosekj Aug 3, 2023

Member

Is metric=MI the ideal choice in step=2?

See other metrics from sct_register_multimodal -h:

* CC: The cross correlation metric compares the images based on their intensities but with a small normalization. It can be used with images with the same contrast (for ex. T2-w with T2-w). In this case it is very efficient but the computation time can be very long.
* MI: the mutual information metric compares the images based on their entropy, therefore the images need to be big enough to have enough information. It works well for images with different contrasts (for example T2-w with T1-w) but not on segmentations.
* MeanSquares: The mean squares metric compares the images based on their intensities. It can be used only with images that have exactly the same contrast (with the same intensity range) or with segmentations.

This comment has been minimized.

Copy link
@plbenveniste

plbenveniste Aug 3, 2023

Author Collaborator

I had similar results with both.

I decided to use MI because I felt like it was the most robust to changes as it can be used for different contrasts.

Would you suggest CC instead of MI ?

This comment has been minimized.

Copy link
@jcohenadad

jcohenadad Aug 3, 2023

Member

Would you suggest CC instead of MI ?

yes-- MI is sensitive to the number of bins and can crash if not enough voxels in the mask

os.system('sct_register_multimodal -i ' + args.input_second_image + ' -d ' + args.input_first_image + ' -iseg ' + args.output_folder + '/second_image_sc_segmentation.nii.gz'
+ ' -dseg ' + args.output_folder + '/first_image_sc_segmentation.nii.gz' + ' -ilabel ' + args.output_folder + '/second_image_sc_segmentation_labeled.nii.gz'
+ ' -dlabel ' + args.output_folder + '/first_image_sc_segmentation_labeled.nii.gz' + ' -o ' + args.output_folder + '/first_image_registered.nii.gz'
+ ' -owarp ' + args.output_folder +'/warping_M0_to_M0.nii.gz' + ' -param ' + parameters + ' -x linear -qc ' + args.output_folder + '/qc')


# parameters = 'step=1,type=seg,algo=slicereg,poly=5:step=2,type=im,algo=syn,metric=MI,deformation=1x1x1,smooth=3'
# os.system('sct_register_multimodal -i ' + args.input_second_image + ' -d ' + args.input_first_image + ' -iseg ' + args.output_folder + '/second_image_sc_segmentation.nii.gz'
# + ' -dseg ' + args.output_folder + '/first_image_sc_segmentation.nii.gz' + ' -o ' + args.output_folder + '/second_image_registered.nii.gz'
# + ' -owarp ' + args.output_folder +'/warping_M0_to_M12.nii.gz' + ' -param ' + parameters + ' -x linear -qc ' + args.output_folder + '/qc')
# #then we apply the warping field to the segmentation of the lesions on the second images using sct_apply_transfo
# os.system('sct_apply_transfo -i ' + args.segmentation_second_image + ' -d ' + args.segmentation_first_image + ' -w ' + args.output_folder + '/warping_M0_to_M12.nii.gz' + ' -o ' + args.output_folder + '/second_image_lesion_segmentation_registered.nii.gz' + ' -x linear')

return None

Expand Down

0 comments on commit 6e70cb1

Please sign in to comment.