Reading functions for freesurfer files
read_annot(filepath[, orig_ids]) | Read in a Freesurfer annotation from a .annot file. |
read_geometry(filepath) | Read a triangular format Freesurfer surface mesh. |
read_label(filepath[, read_scalars]) | Load in a Freesurfer .label file. |
read_morph_data(filepath) | Read a Freesurfer morphometry data file. |
write_annot(filepath, labels, ctab, names) | Write out a Freesurfer annotation file. |
write_geometry(filepath, coords, faces[, ...]) | Write a triangular format Freesurfer surface mesh. |
Header and image reading / writing functions for MGH image format
Author: Krish Subramaniam
MGHError | Exception for MGH format related problems. |
MGHHeader([binaryblock, check]) | Class for MGH format header |
MGHImage(dataobj, affine[, header, extra, ...]) | Class for MGH format image |
load | class method to create image from filename filename |
Read in a Freesurfer annotation from a .annot file.
Parameters: | filepath : str
orig_ids : bool
|
---|---|
Returns: | labels : ndarray, shape (n_vertices,)
ctab : ndarray, shape (n_labels, 5)
names : list of str
|
Read a triangular format Freesurfer surface mesh.
Parameters: | filepath : str
|
---|---|
Returns: | coords : numpy array
faces : numpy array
|
Load in a Freesurfer .label file.
Parameters: | filepath : str
read_scalars : bool
|
---|---|
Returns: | label_array : numpy array
scalar_array : numpy array (floats)
|
Read a Freesurfer morphometry data file.
This function reads in what Freesurfer internally calls “curv” file types, (e.g. ?h. curv, ?h.thickness), but as that has the potential to cause confusion where “curv” also refers to the surface curvature values, we refer to these files as “morphometry” files with PySurfer.
Parameters: | filepath : str
|
---|---|
Returns: | curv : numpy array
|
Write out a Freesurfer annotation file.
See: https://surfer.nmr.mgh.harvard.edu/fswiki/LabelsClutsAnnotationFiles#Annotation
Parameters: | filepath : str
labels : ndarray, shape (n_vertices,)
ctab : ndarray, shape (n_labels, 5)
names : list of str
|
---|
Write a triangular format Freesurfer surface mesh.
Parameters: | filepath : str
coords : numpy array
faces : numpy array
create_stamp : str
|
---|
Bases: object
Class for MGH format header
The header also consists of the footer data which MGH places after the data chunk.
Initialize header from binary data block
Parameters: | binaryblock : {None, string} optional
check : bool, optional
|
---|
Initialize header from binary data block
Parameters: | binaryblock : {None, string} optional
check : bool, optional
|
---|
binary block of data as string
Returns: | binaryblock : string
|
---|
Pass. maybe for now
Return copy of header
Read data array from fileobj
Parameters: | fileobj : file-like
|
---|---|
Returns: | arr : ndarray
|
classmethod for loading a MGH fileobject
Class method to create MGH header from another MGH header
Get the affine transform from the header information. MGH format doesn’t store the transform directly. Instead it’s gleaned from the zooms ( delta ), direction cosines ( Mdc ), RAS centers ( Pxyz_c ) and the dimensions.
Get the affine transform from the header information. MGH format doesn’t store the transform directly. Instead it’s gleaned from the zooms ( delta ), direction cosines ( Mdc ), RAS centers ( Pxyz_c ) and the dimensions.
Get the number of bytes per voxel of the data
Get numpy dtype for MGH data
For examples see set_data_dtype
Return offset into data file to read data
Get shape of data
Get the number of bytes the data chunk occupies.
Return offset where the footer resides. Occurs immediately after the data chunk.
return the inverse get_affine()
MGH format does not do scaling?
return the get_affine()
Get the vox2ras-tkr transform. See “Torig” here: https://surfer.nmr.mgh.harvard.edu/fswiki/CoordinateSystems
Get zooms from header
Returns: | z : tuple
|
---|
Return items from header data
Return keys from header data
Set numpy dtype for data from code or dtype or type
Set shape of data
Parameters: | shape : sequence
|
---|
Set zooms into header fields
See docstring for get_zooms for examples
Return values from header data
Write footer to fileobj
Footer data is located after the data chunk. So move there and write.
Parameters: | fileobj : file-like object
|
---|---|
Returns: | None : |
Write header to fileobj
Write starts at the beginning.
Parameters: | fileobj : file-like object
|
---|---|
Returns: | None : |
Bases: nibabel.spatialimages.SpatialImage
Class for MGH format image
Initialize image
The image is a combination of (array, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters: | dataobj : object
affine : None or (4,4) array-like
header : None or mapping or header instance, optional
extra : None or mapping, optional
file_map : mapping, optional
|
---|
Initialize image
The image is a combination of (array, affine matrix, header), with optional metadata in extra, and filename / file-like objects contained in the file_map mapping.
Parameters: | dataobj : object
affine : None or (4,4) array-like
header : None or mapping or header instance, optional
extra : None or mapping, optional
file_map : mapping, optional
|
---|
alias of ArrayProxy
Check for compressed .mgz format, then .mgh format
Load image from file_map
Parameters: | file_map : None or mapping, optional
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
|
---|
class method to create image from filename filename
Parameters: | filename : str
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
|
---|---|
Returns: | img : MGHImage instance |
class method to create image from filename filename
Parameters: | filename : str
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
|
---|---|
Returns: | img : MGHImage instance |
Write image to file_map or contained self.file_map
Parameters: | file_map : None or mapping, optional
|
---|
class method to create image from filename filename
Parameters: | filename : str
mmap : {True, False, ‘c’, ‘r’}, optional, keyword only
|
---|---|
Returns: | img : MGHImage instance |