v2.0.0
Loading...
Searching...
No Matches
mri_nifti_io.h File Reference

NIfTI-1 single-file (.nii / .nii.gz) volume reader producing the same per-slice layout as the MGH reader. More...

#include "mri_global.h"
#include "mri_vol_data.h"
#include <QString>
Include dependency graph for mri_nifti_io.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  MRILIB::MriNiftiIO
 Stateless decoder for NIfTI-1 single-file volumes (.nii and .nii.gz). More...

Namespaces

namespace  MRILIB
 Volume I/O, voxel geometry and slice resampling for structural MRI data inside mne-cpp.

Detailed Description

NIfTI-1 single-file (.nii / .nii.gz) volume reader producing the same per-slice layout as the MGH reader.

SPDX-License-Identifier: BSD-3-Clause Copyright (c) 2026 MNE-CPP Authors

Author
Christoph Dinh chris.nosp@m.toph.nosp@m..dinh.nosp@m.@mne.nosp@m.-cpp..nosp@m.org
Since
2.2.1
Date
May 2026

NIfTI-1 is the standard exchange container used by FSL, AFNI, SPM, nibabel and essentially every neuroimaging toolchain outside the FreeSurfer ecosystem; adding it to MRILIB lets mne-cpp consume preprocessed structurals produced by any of those pipelines (e.g. BIDS subjects whose anatomicals never pass through recon-all) without requiring an external conversion step. The reader stays surface-compatible with MriMghIO so the slicing, rendering and COR.fif export paths downstream do not need to branch on source format.

The header is 348 bytes; image data starts at vox_offset (typically 352 for single-file .nii). All scalar fields are little-endian by default; big-endian files are detected via the sizeof_hdr magic and the whole header is byte-swapped up-front. The .nii.gz variant is decompressed in memory via zlib's MAX_WBITS+16 mode, mirroring the MGZ path.

Transform extraction follows the NIfTI-1 priority rule used by nibabel and FSL: prefer sform (3 affine rows directly in voxel\u2192RAS mm), fall back to qform (unit quaternion + offset, expanded into a rotation matrix), and as a last resort build a diagonal transform from pixdim centred at the volume origin. This ordering is encoded once in MriNiftiIO::read so every caller gets the same RAS regardless of how the source file was authored.

Format reference: https://nifti.nimh.nih.gov/nifti-1

Definition in file mri_nifti_io.h.