Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NIfTI-2 Support #96

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
331 changes: 331 additions & 0 deletions resources/cifti/ODC_PDDL.rtf

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions resources/cifti/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
These CIFTI files and the README files are originally gathered and distributed in the CiftiLib
https://github.com/Washington-University/CiftiLib, including the following section of the readme file

-----

These files are intended for testing CIFTI-2 reading code, identical to the ones in the v1.x zip files from https://www.nitrc.org/projects/cifti/. There are 5 CIFTI-2 files, the other data files that were in the zip have been removed to save space, as they were in different (but related) formats.

The files:

Conte69.MyelinAndCorrThickness.32k_fs_LR.dscalar.nii
Conte69.MyelinAndCorrThickness.32k_fs_LR.dtseries.nii

contain the same data, which are two fairly smooth maps, with somewhat different value distributions (MyelinMap_BC_decurv ranges from 1 to 2, while corrThickness ranges from 1 to 4.8). If you see a pattern that alternates from one vertex to the next, you have probably read the data matrix incorrectly, which may happen if you previously read data from CIFTI-1, and used the same code. The CIFTI-2 matrix data should be read as a standard NIFTI-2 file, it does not require the special treatment that CIFTI-1 needed.

The "ones.dscalar.nii" is the only cifti file in the zip that contains voxel data. All of the data values are 1. The various volume components should align well with subcortical structures in "Conte69_AverageT1w_restore.nii.gz" from any of the v1.x zip files from https://www.nitrc.org/projects/cifti/.

The files:

Conte69.MyelinAndCorrThickness.32k_fs_LR.ptseries.nii
Conte69.parcellations_VGD11b.32k_fs_LR.dlabel.nii

should have the first map of the .dlabel.nii file align with the areas in the .ptseries.nii file that have values. The values in the .ptseries.nii file should match the vertex averages over the regions they cover, from the same-index map in "Conte69.MyelinAndCorrThickness.32k_fs_LR.dtseries.nii".

These files are provided under the Open Data Commons Public Domain Dedication and Licence (PDDL), see ODC_PDDL.rtf and/or http://opendatacommons.org/licenses/pddl/1.0/ for details.
Binary file added resources/cifti/ones.dscalar.nii
Binary file not shown.
2 changes: 1 addition & 1 deletion src/affine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ where
///
/// We get the translations from the center of the image (implied by `shape`).
#[rustfmt::skip]
pub(crate) fn shape_zoom_affine(shape: &[u16], spacing: &[f32]) -> Matrix4<f64> {
pub(crate) fn shape_zoom_affine(shape: &[u64], spacing: &[f64]) -> Matrix4<f64> {
// Get translations from center of image
let origin = Vector3::new(
(shape[0] as f64 - 1.0) / 2.0,
Expand Down
16 changes: 13 additions & 3 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ quick_error! {
/// The field `dim` is in an invalid state, as a consequence of
/// `dim[0]` or one of the elements in `1..dim[0] + 1` not being
/// positive.
InconsistentDim(index: u8, value: u16) {
InconsistentDim(index: u8, value: u64) {
display("Inconsistent value `{}` in header field dim[{}] ({})", value, index, match index {
0 if *value > 7 => "must not be higher than 7",
_ => "must be positive"
})
}
/// Attempted to read volume outside boundaries.
OutOfBounds(coords: Vec<u16>) {
OutOfBounds(coords: Vec<u64>) {
display("Out of bounds access to volume: {:?}", &coords[..])
}
/// Attempted to read a volume over a volume's unexistent dimension.
Expand Down Expand Up @@ -69,9 +69,19 @@ quick_error! {
display("Description length ({} bytes) is greater than 80 bytes.", len)
}
/// Header contains a code which is not valid for the given attribute
InvalidCode(typename: &'static str, code: i16) {
InvalidCode(typename: &'static str, code: i32) {
display("invalid code `{}` for header field {}", code, typename)
}
/// Integer field size is not large enough to hold assigned value
FieldSize(err: std::num::TryFromIntError) {
from()
source(err)
}
/// Invalid header size. Header size must be 540 for NIfTI-2 or 348 for
/// NIfTI-1.
InvalidHeaderSize(sizeof_hdr: i32) {
display("Invalid header size {} must eb 540 for NIfTI-2 or 348 for NIfTI-1.", sizeof_hdr)
}
/// Could not reserve enough memory for volume data
ReserveVolume(bytes: usize, err: std::collections::TryReserveError) {
display("Could not reserve {} bytes of memory for volume data", bytes)
Expand Down
2 changes: 1 addition & 1 deletion src/extension.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! This module contains definitions for the extension and related types.
//! This module contains definitions for the extension and related typ&es.
//! Extensions are optional data frames sitting before the voxel data.
//! When present, an extender frame of 4 bytes is also present at the
//! end of the NIFTI-1 header, with the first byte set to something
Expand Down
Loading