Skip to content

Examples

Sebastiano Ferraris edited this page Aug 20, 2018 · 11 revisions

Miscellaneous examples

Erase all the labels of the segmentation 'my_segm.nii.gz' but the label 203:

from LABelsToolkit.main import LABelsToolkit as LaB

la = LaB()
la.manipulate_labels.keep_one_label('my_segm.nii.gz', 'my_segm_only203.nii.gz', 203)

Get a report with the numbers of connected components of the segmentation 'my_segm.nii.gz' in the log text file 'log.txt'.

from LABelsToolkit.main import LABelsToolkit as LaB

la = LaB()
la.check.number_connected_components_per_label('my_segm.nii.gz',
                                               where_to_save_the_log_file='log.txt')

Given a segmentation of the left side of a symmetric anatomy, create the other half through flipping and rigid registration. The input anatomy is 'my_anatomy.nii.gz' and its segmentation is 'my_segm.nii.gz' labels in the centre are [1, 2, 3, 4, 5], labels in the left side are [6, 8, 10, 12, 14] and corresponding labels on the other side are [7, 9, 11, 13, 15]. Output is saved under 'my_segm_SYM.nii.gz' and intermediate files are saved in the folder 'z_tmp'

from LABelsToolkit.main import LABelsToolkit as LaB

la = LaB()
la.symmetrize.symmetrise_with_registration('my_anatomy.nii.gz',
                                           'my_segm.nii.gz',
                                           labels_sym_left=[1, 2, 3, 4, 5] + [6, 8, 10, 12, 14],
                                           'my_segm_SYM.nii.gz',
                                           results_folder_path=z_tmp,
                                           list_labels_transformed=[1, 2, 3, 4, 5] + [7, 9, 11, 13, 15],
                                           coord='z')
Clone this wiki locally