Skip to content

Commit 7b59675

Browse files
committed
DOC: Update ctab documentation, comments
1 parent 10dbdda commit 7b59675

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

nibabel/freesurfer/io.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -333,9 +333,13 @@ def read_annot(filepath, orig_ids=False):
333333
Annotation file format versions 1 and 2 are supported, corresponding to
334334
the "old-style" and "new-style" color table layout.
335335
336+
Note that the output color table ``ctab`` is in RGBT form, where T
337+
(transparency) is 255 - alpha.
338+
336339
See:
337340
* https://surfer.nmr.mgh.harvard.edu/fswiki/LabelsClutsAnnotationFiles#Annotation
338341
* https://github.com/freesurfer/freesurfer/blob/dev/matlab/read_annotation.m
342+
* https://github.com/freesurfer/freesurfer/blob/8b88b34/utils/colortab.c
339343
340344
Parameters
341345
----------
@@ -352,7 +356,7 @@ def read_annot(filepath, orig_ids=False):
352356
Annotation id at each vertex. If a vertex does not belong
353357
to any label and orig_ids=False, its id will be set to -1.
354358
ctab : ndarray, shape (n_labels, 5)
355-
RGBA + label id colortable array.
359+
RGBT + label id colortable array.
356360
names : list of str (python 2), list of bytes (python 3)
357361
The names of the labels. The length of the list is n_labels.
358362
"""
@@ -397,6 +401,9 @@ def read_annot(filepath, orig_ids=False):
397401
def _read_annot_ctab_old_format(fobj, n_entries):
398402
"""Read in an old-style Freesurfer color table from `fobj`.
399403
404+
Note that the output color table ``ctab`` is in RGBT form, where T
405+
(transparency) is 255 - alpha.
406+
400407
This function is used by :func:`read_annot`.
401408
402409
Parameters
@@ -412,7 +419,7 @@ def _read_annot_ctab_old_format(fobj, n_entries):
412419
-------
413420
414421
ctab : ndarray, shape (n_entries, 5)
415-
RGBA colortable array - the last column contains all zeros.
422+
RGBT colortable array - the last column contains all zeros.
416423
names : list of str
417424
The names of the labels. The length of the list is n_entries.
418425
"""
@@ -430,7 +437,7 @@ def _read_annot_ctab_old_format(fobj, n_entries):
430437
name_length = np.fromfile(fobj, dt, 1)[0]
431438
name = np.fromfile(fobj, "|S%d" % name_length, 1)[0]
432439
names.append(name)
433-
# read RGBA for this entry
440+
# read RGBT for this entry
434441
ctab[i, :4] = np.fromfile(fobj, dt, 4)
435442

436443
return ctab, names
@@ -439,6 +446,9 @@ def _read_annot_ctab_old_format(fobj, n_entries):
439446
def _read_annot_ctab_new_format(fobj, ctab_version):
440447
"""Read in a new-style Freesurfer color table from `fobj`.
441448
449+
Note that the output color table ``ctab`` is in RGBT form, where T
450+
(transparency) is 255 - alpha.
451+
442452
This function is used by :func:`read_annot`.
443453
444454
Parameters
@@ -454,7 +464,7 @@ def _read_annot_ctab_new_format(fobj, ctab_version):
454464
-------
455465
456466
ctab : ndarray, shape (n_labels, 5)
457-
RGBA colortable array - the last column contains all zeros.
467+
RGBT colortable array - the last column contains all zeros.
458468
names : list of str
459469
The names of the labels. The length of the list is n_labels.
460470
"""
@@ -480,7 +490,7 @@ def _read_annot_ctab_new_format(fobj, ctab_version):
480490
name_length = np.fromfile(fobj, dt, 1)[0]
481491
name = np.fromfile(fobj, "|S%d" % name_length, 1)[0]
482492
names.append(name)
483-
# RGBA
493+
# RGBT
484494
ctab[idx, :4] = np.fromfile(fobj, dt, 4)
485495

486496
return ctab, names
@@ -489,9 +499,13 @@ def _read_annot_ctab_new_format(fobj, ctab_version):
489499
def write_annot(filepath, labels, ctab, names, fill_ctab=True):
490500
"""Write out a "new-style" Freesurfer annotation file.
491501
502+
Note that the color table ``ctab`` is in RGBT form, where T (transparency)
503+
is 255 - alpha.
504+
492505
See:
493506
* https://surfer.nmr.mgh.harvard.edu/fswiki/LabelsClutsAnnotationFiles#Annotation
494507
* https://github.com/freesurfer/freesurfer/blob/dev/matlab/write_annotation.m
508+
* https://github.com/freesurfer/freesurfer/blob/8b88b34/utils/colortab.c
495509
496510
Parameters
497511
----------
@@ -500,7 +514,7 @@ def write_annot(filepath, labels, ctab, names, fill_ctab=True):
500514
labels : ndarray, shape (n_vertices,)
501515
Annotation id at each vertex.
502516
ctab : ndarray, shape (n_labels, 5)
503-
RGBA + label id colortable array.
517+
RGBT + label id colortable array.
504518
names : list of str
505519
The names of the labels. The length of the list is n_labels.
506520
fill_ctab : {True, False} optional

0 commit comments

Comments
 (0)