Skip to content

Design Pattern

Sebastiano Ferraris edited this page Nov 19, 2019 · 16 revisions

The code is designed around the facade design pattern.

Each core function is designed to act on numpy arrays or nibabel instances, and it is tested 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 nilabels.App 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 10 segmentations file{1..10}.nii.gz, you can apply the tool relabel under App.manipulate.relabel as:

import nilabels as nil


nil_app = nil.App(<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)
    nil_app.manipulate.relabel(input_file_name, output_file_name,
                               [1, 2, 3, 4, 5, 6], [2, 3, 4, 5, 6, 7])