Skip to content

Design Pattern

Sebastiano Ferraris edited this page Aug 21, 2018 · 16 revisions

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 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 10 segmentations file{1..10}.nii.gz, you can apply the tool relabel under tools.manipulations.relabel as:

from nilabel.main import Nilabel as NiL


lt = NiL(<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