Skip to content

Design Pattern

Sebastiano Ferraris edited this page Jun 28, 2018 · 16 revisions

Command design pattern:

The code is designed around the command design pattern.

Each core function is designed to act on numpy arrays or nibabel instances, and it is tested (currently not every time) on dummy examples.

The facade methods, acting on paths to the images in nifti format, access the core method and return another image as output.

An instance of the class LabelsManager accesses a nifty image through its path, and applies to its data the selected tool.

For example, to change the labels values from [1, 2, 3, 4, 5, 6] to [2, 3, 4, 5, 6, 7] for a list of segmentations file{1..10}.nii.gz, you can apply the tool relabel under tools.manipulations.relabel as:

lt = LABelsToolkit(<input_folder>, <output_folder>)

for i in range(1, 11):
    input_file_name = 'file{}.nii.gz'.format(i)
    output_file_name = 'file{}.nii.gz'.format(i)
    lt.manipulate.relabel(input_file_name, output_file_name,
                          [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7])
Clone this wiki locally