Skip to content

Commit

Permalink
Merge branch 'master' of github.com:scilus/scilpy into convert_trks_t…
Browse files Browse the repository at this point in the history
…o_hdf5
  • Loading branch information
frheault committed Jun 18, 2024
2 parents d4ee56e + 070d713 commit 3edad76
Show file tree
Hide file tree
Showing 131 changed files with 3,205 additions and 2,388 deletions.
34 changes: 34 additions & 0 deletions scilpy/image/labels.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
# -*- coding: utf-8 -*-
import importlib.resources as resources
import inspect
import json
import logging
import os

import numpy as np
from scipy.spatial import cKDTree


def load_wmparc_labels():
"""
Load labels dictionary of different parcellations from the Desikan-Killiany
atlas.
"""
lut_package = resources.files('data').joinpath('LUT')
labels_path = lut_package.joinpath('dk_aggregate_structures.json')
with open(labels_path) as labels_file:
labels = json.load(labels_file)
return labels


def get_data_as_labels(in_img):
"""
Get data as label (force type np.uint16), check data type before casting.
Expand All @@ -33,6 +47,26 @@ def get_data_as_labels(in_img):
'image'.format(basename, curr_type))


def get_binary_mask_from_labels(atlas, label_list):
"""
Get a binary mask from labels.
Parameters
----------
atlas: numpy.ndarray
The image will all labels as values (ex, result from
get_data_as_labels).
label_list: list[int]
The labels to get.
"""
mask = np.zeros(atlas.shape, dtype=np.uint16)
for label in label_list:
is_label = atlas == label
mask[is_label] = 1

return mask


def get_lut_dir():
"""
Return LUT directory in scilpy repository
Expand Down
Loading

0 comments on commit 3edad76

Please sign in to comment.