Skip to content

Commit 7dc2c76

Browse files
committed
new colorize() m ethod of labelled parcellationmaps
1 parent d667b2a commit 7dc2c76

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

siibra/volumes/parcellationmap.py

+32
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,38 @@ def _collect_maps(self, resolution_mm, voi):
527527

528528
return m
529529

530+
def colorize(self, values: dict):
531+
"""Colorize the map with the provided regional values.
532+
533+
Parameters
534+
----------
535+
values : dict
536+
Dictionary mapping regions to values
537+
538+
Return
539+
------
540+
Nifti1Image
541+
"""
542+
543+
# generate empty image
544+
maps = {}
545+
result = None
546+
547+
for region, value in values.items():
548+
indices = self.decode_region(region)
549+
for index in indices:
550+
if index.map not in maps:
551+
# load the map
552+
maps[index.map] = self.fetch(index.map)
553+
thismap = maps[index.map]
554+
if result is None:
555+
# create the empty output
556+
result = np.zeros_like(thismap.get_fdata())
557+
affine = thismap.affine
558+
result[thismap.get_fdata()==index.label] = value
559+
560+
return Nifti1Image(result, affine)
561+
530562
@cached
531563
def assign_coordinates(
532564
self, point: Union[Point, PointSet], sigma_mm=None, sigma_truncation=None

0 commit comments

Comments
 (0)