atlannot.atlas.align module

Functions related to atlas alignment.

atlannot.atlas.align.get_misalignment(data_1, data_2, fg_only=False)[source]

Compute misalignment between annotation data.

Parameters:
  • data_1 (np.ndarray) – The first annotation data. Can have any shape.

  • data_2 (np.ndarray) – The second annotation data. Shape should match that of data_1.

  • fg_only (bool, optional) – If true then only the foreground is considered for the evaluation. Foreground pixels are complimentary to background. Background is where both data arrays are zero.

Returns:

misalignment – The misalignment between the annotation data.

Return type:

float

Raises:

ValueError – If the shapes of the data don’t match.

atlannot.atlas.align.specific_label_iou(data_1, data_2, specific_label)[source]

Compute intersection over union for a given label.

Parameters:
  • data_1 (np.ndarray) – The first annotation data. Can have any shape.

  • data_2 (np.ndarray) – The second annotation data. Shape should match that of data_1.

  • specific_label (int) – Label for which it is wanted to compute the IOU.

Returns:

iou – The IOU for the given label.

Return type:

float

Raises:

ValueError – If the shapes of the data don’t match.

atlannot.atlas.align.unfurl_regions(atlas, meta, progress_bar=None)[source]

Separate regions by hierarchy level.

Each slice of the brain atlas is expanded into multiple copies with each subsequent copy having the last hierarchy level of the previous copy removed.

For example, if a given slice has the region hierarchy up to depth 2, i. e. it has regions at level 0 (= the background), level 1, and level 2, then the slice will be expanded into 3 slices:

  • The original slice

  • The slice with regions at level 2 removed

  • The slice with regions at levels 2 and 1 removed (leaving just the background)

Parameters:
  • atlas (np.ndarray) – An annotation atlas volume with shape (n_slices, height, width).

  • meta (atlannot.region_meta.RegionMeta) – The region metadata. Holds the information about the region hierarchy in the atlas.

  • progress_bar (callable, optional) – A progress bar function that maps an iterable onto itself and produces a progress bar as a side effect. Notable examples are tqdm.tqdm and tqdm.notebook.tqdm.

Returns:

unfurled_atlas – The unfurled atlas. It will have the shape (n_levels, n_slices, height, width) where n_levels is the maximal region hierarchy level across all slices.

Return type:

np.ndarray

atlannot.atlas.align.warp(atlas, df_per_slice)[source]

Warp the atlas with displacement fields.

Parameters:
  • atlas (iterable of np.ndarray) – An annotation atlas. Can be an np.ndarray of shape (n_slices, …) or any iterable over atlas slices.

  • df_per_slice (iterable of atldld.base.DisplacementField) – The displacement fields for each brain slice.

Returns:

warped_atlas – The warped atlas.

Return type:

np.ndarray