Skip to content

Commit

Permalink
trying to register M0 to M12
Browse files Browse the repository at this point in the history
  • Loading branch information
plbenveniste committed Aug 2, 2023
1 parent db106a4 commit 511c168
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions lesion_analysis/time_point_lesion_evolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
*
Expand Down Expand Up @@ -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():
Expand All @@ -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

Expand Down

0 comments on commit 511c168

Please sign in to comment.