Crates.io | neuroformats |
lib.rs | neuroformats |
version | 0.2.4 |
source | src |
created_at | 2021-03-03 16:05:31.291218 |
updated_at | 2024-04-24 10:04:02.201374 |
description | Handling of structural neuroimaging file formats. The focus is on surface-based brain morphometry data and FreeSurfer file formats. |
homepage | https://github.com/dfsp-spirit/neuroformats-rs |
repository | https://github.com/dfsp-spirit/neuroformats-rs |
max_upload_size | |
id | 363247 |
size | 103,719 |
Handling of structural neuroimaging file formats for Rust.
The neuroformats
crate provides access to structural neuroimaging data in Rust by implementing parsers for various file formats. The focus is on surface-based brain morphometry data, as produced from 3D or 4D magnetic resonance imaging (MRI) data by neuroimaging software suites like FreeSurfer, CAT12 and others.
In surface-based neuroimaging, basically meshes representing the 3D structure of the human cortex are reconstructed from a segmented 3D brain image. Then properties of the human brain, like the thickness of the cortex at a specific position, are computed from the reconstruction and stored as per-vertex data for the mesh.
Fig. 1 A mesh representing the white surface of a human brain, with cortical thickness values mapped onto it using the viridis colormap. Different magnifications are displayed, and the triangles and vertex positions can be identified in the last one.
The neuroformats
crate is on crates.io.
To use the library in your project, add it as a dependency in your Cargo.toml
file, e.g.:
[dependencies]
neuroformats = "0.2.3"
subject/surf/lh.thickness
): functions neuroformats::read_curv
and write_curv
subject/surf/lh.white
): read_surf
and write_surf
subject/label/lh.cortex.label
): read_label
and write_label
subject/label/lh.aparc.annot
): read_annot
read_mgh
and write_mgh
Various utility functions are implemented for performing common computations on the returned structs, e.g. computing the vox2ras matrix from the MGH header data or finding all vertices in a brain surface parcellation that belong to a certain brain atlas region.
The neuroformats
API docs can be found at docs.rs/neuroformats.
Read vertex-wise cortical thickness computed by FreeSurfer:
use neuroformats::read_curv;
let curv = read_curv("subjects_dir/subject1/surf/lh.thickness").unwrap();
let thickness_at_vertex_0 : f32 = curv.data[0];
You now have a Vec<f32>
with the cortical thickness values in curv.data
. The order of the values matches the vertex order of the respective brain surface reconstruction (e.g., the white surface mesh of the left brain hemisphere in subjects_dir/subject1/surf/lh.white
).
There is a small command line demo application that loads a brain surface mesh and raytraces an image based on the mesh to a PNG file available in the ./examples/brain_rpt directory. The demo uses the rpt crate by Eric Zhang and Alexander Morozov to do the raytracing.
See the neuroformats API docs and the unit tests in the source code for more examples.
Please see the README_DEV file.
The neuroformats
crate is free software, dual-licensed under the MIT or APACHE-2 licenses.
Contributions are very welcome. Please get in touch before making major changes to avoid wasted effort.
If you want to discuss something, need help or found a bug, please open an issue here on Github.
The neuroformats
crate was written by Tim Schäfer. You can find my email address on my website if you need to contact me.