From 511c168f8bc9f5350f4d0f97bba275dbb8b59778 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Benveniste Date: Wed, 2 Aug 2023 09:47:59 -0400 Subject: [PATCH] trying to register M0 to M12 --- .../time_point_lesion_evolution.py | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/lesion_analysis/time_point_lesion_evolution.py b/lesion_analysis/time_point_lesion_evolution.py index c83c049..216cc64 100644 --- a/lesion_analysis/time_point_lesion_evolution.py +++ b/lesion_analysis/time_point_lesion_evolution.py @@ -7,8 +7,8 @@ Args: -i-1, --input-first_image: path to the first image -i-2, --input-second_image: path to the second image - -seg-1, --segmentation-first_image: path to the segmentation of the first image - -seg-2, --segmentation-second_image: path to the segmentation of the second image + -seg-1, --segmentation-first_image: path to the lesion segmentation of the first image + -seg-2, --segmentation-second_image: path to the lesion segmentation of the second image -o, --output_folder: path to the output folder --plot: whether to plot the results or not @@ -17,6 +17,7 @@ Example: python time_point_lesion_evolution.py -i-1 path/to/first/image -i-2 path/to/second/image -seg-1 path/to/first/segmentation -seg-2 path/to/second/segmentation -o path/to/output/folder + python3 lesion_analysis/time_point_lesion_evolution.py -i-1 /Users/plbenveniste/Desktop/lesion_comparison_copy/sub-cal072_ses-M0_STIR.nii.gz -i-2 /Users/plbenveniste/Desktop/lesion_comparison_copy/sub-cal072_ses-M12_STIR.nii.gz -seg-1 /Users/plbenveniste/Desktop/lesion_comparison_copy/M0_inference_results.nii.gz -seg-2 /Users/plbenveniste/Desktop/lesion_comparison_copy/M12_inference_results.nii.gz -o /Users/plbenveniste/Desktop/lesion_comparison_copy/output To do: * @@ -49,13 +50,13 @@ def get_parser(): parser.add_argument('-i-2', '--input-second_image', required=True, help='Path to the second image') parser.add_argument('-seg-1', '--segmentation-first_image', required=True, - help='Path to the segmentation of the first image') + help='Path to the lesion segmentation of the first image') parser.add_argument('-seg-2', '--segmentation-second_image', required=True, - help='Path to the segmentation of the second image') + help='Path to the lesion segmentation of the second image') parser.add_argument('-o', '--output_folder', required=True, help='Path to the output folder') - parser.add_argument('--plot', action='store_true', - help='Whether to plot the results or not') + parser.add_argument('--show', action='store_true', + help='Whether to show the results or not') return parser def main(): @@ -75,12 +76,18 @@ def main(): #get the images and the segmentations first_image = nib.load(args.input_first_image) second_image = nib.load(args.input_second_image) - first_segmentation = nib.load(args.segmentation_first_image) - second_segmentation = nib.load(args.segmentation_second_image) + first_lesion_segmentation = nib.load(args.segmentation_first_image) + second_lesion_segmentation = nib.load(args.segmentation_second_image) - #first we perform a registration of the images and the segmentations - #we use the first image and the first segmentation as the reference - + #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') + + #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 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