cedalion.io.anatomy
Functions for reading and processing anatomical data.
Functions
|
Get the coordinates of each voxel in the transformed mask. |
|
Read parcel RGB colors from a JSON file. |
|
Read parcellation labels from a json file. |
|
Read segmentation masks from NIFTI files. |
|
Load freesurfer surfaces as a cdc.TrimeshSurface object. |
- cedalion.io.anatomy.read_segmentation_masks(
- basedir: str,
- mask_files: Dict[str, str] = {'csf': 'csf.nii', 'gm': 'gm.nii', 'scalp': 'scalp.nii', 'skull': 'skull.nii', 'wm': 'wm.nii'},
Read segmentation masks from NIFTI files.
- Parameters:
basedir (str) – Directory containing the mask files
mask_files (Dict[str, str]) – Dictionary mapping segmentation types to filenames
- Returns:
masks (xr.DataArray): Concatenated segmentation masks with a new dimension segmentation_type.
affine (np.ndarray): Affine transformation matrix associated with the NIFTI files.
- Return type:
Tuple[xr.DataArray, np.ndarray]
- cedalion.io.anatomy.cell_coordinates(mask, affine, units='mm', center=False)[source]
Get the coordinates of each voxel in the transformed mask.
- Parameters:
mask (xr.DataArray) – A binary mask of shape (i, j, k).
affine (np.ndarray) – Affine transformation matrix.
units (str) – Units of the output coordinates.
center – if true the cells’ center positions are returned. Otherwise it is the position of the lower-left corner of the voxel.
- Returns:
Coordinates of the center of each voxel in the mask.
- Return type:
xr.DataArray
- cedalion.io.anatomy.read_parcellations(parcel_file: str | Path) DataFrame[source]
Read parcellation labels from a json file.
- Parameters:
parcel_file – The parcels file name
- Returns:
Contains vertices’ labels, their appropriate colors
- Return type:
pd.DataFrame
- cedalion.io.anatomy.read_parcel_colors(parcel_colors_file: str | Path) dict[str, list][source]
Read parcel RGB colors from a JSON file.
- Parameters:
parcel_colors_file – Path to the JSON file mapping parcel names to RGB color lists.
- Returns:
Dictionary mapping parcel label strings to RGB color lists.
- cedalion.io.anatomy.trimesh_from_freesurfer(
- lh: str | Path,
- rh: str | Path,
- crs: str,
- units: str,
- offset_hemispheres: bool = True,
Load freesurfer surfaces as a cdc.TrimeshSurface object.
- Parameters:
lh – path of the left hemisphere surface file.
rh – path of the right hemisphere surface file.
crs – label of the coordinate reference system
units – units of vertex coordinates
offset_hemispheres – If True, offset the hemispheres along the x-axis such that the left hemisphere’s maximum x-coordinate aligns with the right hemisphere’s minimum x-coordinate, removing the overlap that occurs with inflated surfaces.
- Returns:
A single TrimeshSurface containing both hemispheres, with left-hemisphere vertices preceding right-hemisphere vertices in the vertex array.