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

Support reading and writing JNIfTI files - a JSON wrapper of nifti-1/nifti-2 #284

Open
fangq opened this issue Apr 24, 2020 · 2 comments
Open

Comments

@fangq
Copy link

fangq commented Apr 24, 2020

First, some background:

Last year, I started a new project called OpenJData (http://openjdata.org, https://openjdata.org/wiki/), with a goal to create a simple and extensible data-annotation standard for general scientific data storage. See some of our rationales and examples from the wiki site. More data sample/benchmark can be found in this post.

The goal of this standard is to use the widely supported JSON/UBJSON as the underlying format, and create a semantic layer to encode basic data structures (JData spec), neuroimaging scans (JNIfTI spec, JSNIRF spec for fNIRS), and other domain-specific data, such as JMesh for shapes/geometries, JDICOM/JGifTI etc (to be developed).

Here, I want to bring to your attention the JNIfTI spec because NIfTI-1/2 data have a large presence in neuroimaging software. As you may know, NIfTI files have several limitations, see my post in this thread bids-standard/bids-specification#197 (comment)

JNIfTI is basically a JSON/UBJSON wrapper over the NIfTI-1/2 data, with a header that is 100% compatible with nifti (thus two-way loss-less conversion - nii2jnii/jnii2nii). It directly addresses most of the limitations of NIfTI, making it easy for further extension, supporting internal compression (instead of .nii.gz), making it human readable and easy to integrate with metadata.

To read/write JNIfTI files (.jnii - JSON based JNIfTI files, or .bnii - UBJSON based JNIfTI files), you may use a lightweight toolbox, the JNIfTI toolbox:

https://github.com/fangq/jnifti/tree/master/lib/matlab

which by itself is also a nifti-1/2/Analyze7.5 file reader/writer.

JNIfTI toolbox is already included in the Iso2mesh toolbox. Since BrainStorm has already supported Iso2mesh, you really don't need to do anything else, but to associate the '.jnii' and '.bnii' file to the loadjnifti/savejnifti functions.

Again, similar to my comment here, ZMat is optional if your user mostly uses MATLAB in the GUI mode.

Let me know what you think.

@ftadel
Copy link
Member

ftadel commented Apr 27, 2020

Thank you for this presentation of OpenJData / JNIfTI.
I added it to our (infinite) to-do list: https://neuroimage.usc.edu/brainstorm/Next#Input_.2F_output

Since we have much more implementation requests than available development resources, we tend to give more time to requests that we've already have multiple times. Before working on this implementation, we'll probably wait until OpenJData becomes part of the BIDS specs, or until some users have a specific need for it. Wrapping up our FEM pipeline (including iso2mesh and brain2mesh) is more of a priority for the next few months.

But at least, I am aware of this project and will keep its possibilities in mind.
Thanks!

@fangq
Copy link
Author

fangq commented Apr 27, 2020

JNIfTI is nothing but a JSON file (and its binary counter part). All it needs is JSONLab (and optionally zmat).

JSONLab is very compact (200KB uncompressed including documentations, 70k compressed), highly portable (working with both matlab and octave) with a permissive license.

If you can add JSONLab to BrainStorm as an optional (or required) dependency, supporting JNIfTI is only a matter of a few lines of codes. I will be happy to create a pull request for that.

The only other decision left to be made is whether you want to support binary data compression/decompression. This is done via zmat (https://github.com/fangq/zmat, a mex file about 200k of size uncompressed). But if you already have something in place that supports stream-level compression/decompression, then zmat can be replaced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants