Read NIfTI files from an ArrayBuffer
masterTo read a NIfTI file, you must first check if the data is compressed (e.g., .nii.gz) and decompress it if necessary. Once uncompressed, you can verify if it is a valid NIfTI format, read the header, and then extract the image data. You can also optionally read extension data if the header contains extensions.
Workflow:
- Check compression with
isCompressed(data). - Decompress with
decompress(data)if needed. - Verify NIfTI format with
isNIFTI(data). - Parse header with
readHeader(data). - Parse image data with
readImage(niftiHeader, data). - (Optional) Parse extensions with
readExtensionData(niftiHeader, data)ifhasExtension(niftiHeader)is true.
var data = // an ArrayBuffer
var niftiHeader = null,
niftiImage = null,
niftiExt = null;
if (nifti.isCompressed(data)) {
data = nifti.decompress(data);
}
if (nifti.isNIFTI(data)) {
niftiHeader = nifti.readHeader(data);
console.log(niftiHeader.toFormattedString());
niftiImage = nifti.readImage(niftiHeader, data);
if (nifti.hasExtension(niftiHeader)) {
niftiExt = nifti.readExtensionData(niftiHeader, data);
}
}