|
50 | 50 | We can create brain models covering the left cortex and left thalamus using:
|
51 | 51 |
|
52 | 52 | >>> from nibabel import cifti2
|
53 |
| ->>> bm_cortex = cifti2.BrainModelAxis.from_mask(cortex_mask, |
54 |
| -... brain_structure='cortex_left') # doctest: +SKIP |
55 |
| ->>> bm_thal = cifti2.BrainModelAxis.from_mask(thalamus_mask, affine=affine, |
56 |
| -... brain_structure='thalamus_left') # doctest: +SKIP |
| 53 | +>>> import numpy as np |
| 54 | +>>> bm_cortex = cifti2.BrainModelAxis.from_mask([True, False, True, True], |
| 55 | +... name='cortex_left') |
| 56 | +>>> bm_thal = cifti2.BrainModelAxis.from_mask(np.ones((2, 2, 2)), affine=np.eye(4), |
| 57 | +... name='thalamus_left') |
| 58 | +
|
| 59 | +In this very simple case ``bm_cortex`` describes a left cortical surface skipping the second |
| 60 | +out of four vertices. ``bm_thal`` contains all voxels in a 2x2x2 volume. |
57 | 61 |
|
58 | 62 | Brain structure names automatically get converted to valid CIFTI-2 indentifiers using
|
59 | 63 | :meth:`BrainModelAxis.to_cifti_brain_structure_name`.
|
@@ -332,6 +336,8 @@ def from_mask(cls, mask, name='other', affine=None):
|
332 | 336 | affine = np.asanyarray(affine)
|
333 | 337 | if affine.shape != (4, 4):
|
334 | 338 | raise ValueError("Affine transformation should be a 4x4 array or None, not %r" % affine)
|
| 339 | + |
| 340 | + mask = np.asanyarray(mask) |
335 | 341 | if mask.ndim == 1:
|
336 | 342 | return cls.from_surface(np.where(mask != 0)[0], mask.size, name=name)
|
337 | 343 | elif mask.ndim == 3:
|
|
0 commit comments