Computer Vision News - November 2021

59 Pythonscripting for 3D Slicer cd /usr/local/Slice r-X.XX -XXXXXXXX-linux-amd64 ./Slicer --no-main-window --python-script /home/user/Desktop/batchreg_3dslicer.py The following python script is created to automatize the task we manually performed in the previous article. This consisted in selecting landmark points to register two images, and then save them to re-apply a rigid registration between the segmentation and the reference image. This can be very useful in itself, but what if we need to do it for multiple files or an entire folder? Of course, the first part - extraction of landmarks - needs to be manual, but, assuming we already have the landmark points saved in a specific directory, this python script can handle the interaction with 3D Slicer to automatically replicate all steps and save the new registered images. def batch_reg (filename_dir,transform_dir): # exclude missing cases N = 100 #number of cases for i in range( 1 , N ): if (i == 11 or i == 12 ): continue itemCT_filename = filename_dir + 'data/non_registered_cts/ ct'+str(i)+'.nii' itemMR_filename = filename_dir + 'data/non_registered_mrs/ mr'+str(i)+'.nii' itemSEG_filename = filename_dir + 'data/non_registered_segs/seg'+str(i)+'.nii' itemTransform_filename = filename_dir + \ '/case' + str(i) + '/Transform.h5' itemMR = slicer.util.loadVolume(itemMR_filename) itemSEG = slicer.util.loadVolume(itemSEG_filename) itemCT = slicer.util.loadVolume(itemCT_filename) itemTransform = slicer.util.loadTransform(itemTransform_filename) outputSEG_filename = filename_dir+'registered_segs/seg + str(i) + '.nii' SEGresampledNode = slicer.vtkSlicerVolumesLogic().CloneVolumeGeneric(slicer.mrmlS cene, itemSEG, 'out', True) SEGparameters = {'inputVolume': itemSEG,

RkJQdWJsaXNoZXIy NTc3NzU=