Skip to content

Commit 905f87e

Browse files
committed
[release] update all units for v0.8 release
1 parent 1faaf18 commit 905f87e

21 files changed

Lines changed: 324 additions & 125 deletions

DESCRIPTION

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
Name: jnifti
2-
Version: 0.6.1
3-
Date: 2020-15-06
4-
Title: fast NIfTI-1/2 reader and NIfTI-to-JNIfTI converter for MATLAB/Octave
1+
Name: jnifty
2+
Version: 0.8.0
3+
Date: 2025-23-03
4+
Title: Fast NIfTI-1/2 reader/writer and NIfTI-to-JNIfTI converter for MATLAB/Octave
55
Author: Qianqian Fang <fangqq@gmail.com>
66
Maintainer: Qianqian Fang <fangqq@gmail.com>
77
Description: JNIfTI Toolbox is a fully functional NIfTI-1/2 reader/writer that supports both
@@ -10,7 +10,7 @@ Description: JNIfTI Toolbox is a fully functional NIfTI-1/2 reader/writer that s
1010
files (.hdr/.img and .hdr.gz/.img.gz).
1111
More importantly, this is a toolbox that converts NIfTI data to its JSON-based
1212
replacement, JNIfTI (.jnii for text-based and .bnii for binary-based), defined
13-
by the JNIfTI specification (http://github.com/NeuroJSON/jnifti). JNIfTI is a
13+
by the JNIfTI specification (https://github.com/NeuroJSON/jnifty). JNIfTI is a
1414
much more flexible, human-readable and extensible file format compared to the
1515
more rigid and opaque NIfTI format, making the data much easier to manipulate
1616
and share.

INDEX

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
jnifti >> JNIfTI
2-
JNIfTI
3-
jnifticreate
4-
loadjnifti
5-
loadnifti
6-
memmapstream
7-
nifticreate
8-
niftiread
9-
niftiinfo
10-
niftiwrite
11-
nii2jnii
12-
jnii2nii
13-
niicodemap
14-
niiformat
15-
savebnii
16-
savejnifti
17-
savejnii
18-
savenifti
1+
jnifty >> JNIFTY
2+
JNIFTY
3+
gzipdecode.m
4+
gzipencode.m
5+
jnifticreate.m
6+
jnii2nii.m
7+
loadjnifti.m
8+
loadnifti.m
9+
memmapstream.m
10+
nifticreate.m
11+
nii2jnii.m
12+
niicodemap.m
13+
niiformat.m
14+
niiheader2jnii.m
15+
octavezmat.m
16+
savebnii.m
17+
savejnifti.m
18+
savejnii.m
19+
savenifti.m

LICENSE_GPLv3.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
===============================================================================
2-
= Monte Carlo eXtreme (MCX) -- CUDA =
2+
= JNIfTI -- Fast and portable NIfTI-1/2 reader/writer for MATLAB and Octave =
33
===============================================================================
44

5-
Copyright (c) 2010-2019 Qianqian Fang <q.fang at neu.edu>
5+
Copyright (c) 2019-2025 Qianqian Fang <q.fang at neu.edu>
66

77
-------------------------------------------------------------------------------
88

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
# JNIfTI Toolbox - Fast and portable NIfTI-1/2 reader and NIfTI-to-JNIfTI converter
1+
![image](https://neurojson.org/wiki/upload/neurojson_banner_long.png)
22

3-
* Copyright (C) 2019-2024 Qianqian Fang <q.fang at neu.edu>
3+
# JNIfTI Toolbox - Fast and portable NIfTI-1/2 reader/writer for MATLAB and Octave
4+
5+
* Copyright (C) 2019-2025 Qianqian Fang <q.fang at neu.edu>
46
* License: GNU General Public License version 3 (GPL v3) or Apache License 2.0, see License*.txt
5-
* Version: 0.6 (Epica)
6-
* URL: http://github.com/NeuroJSON/jnifti
7+
* Version: 0.8 (Tree of Life)
8+
* URL: https://github.com/NeuroJSON/jnifty
9+
* Compatibility: MATLAB R2008a or newer, or Octave 4.0 and newer
10+
* JNIfTI Specification Version: V1 Draft-2 (https://neurojson.org/jnifti/draft2)
11+
* Acknowledgement: This project is supported by US National Institute of Health (NIH)
12+
grant [U24-NS124027 (NeuroJSON)](https://reporter.nih.gov/project-details/10308329)
713

814
## Overview
915

@@ -14,7 +20,7 @@ files (`.hdr/.img` and `.hdr.gz/.img.gz`).
1420

1521
More importantly, this is a toolbox that converts NIfTI data to its JSON-based
1622
replacement, JNIfTI (`.jnii` for text-based and `.bnii` for binary-based), defined
17-
by the JNIfTI specification (http://github.com/NeuroJSON/jnifti). JNIfTI is a
23+
by the JNIfTI specification (https://github.com/NeuroJSON/jnift). JNIfTI is a
1824
much more flexible, human-readable and extensible file format compared to the
1925
more rigid and opaque NIfTI format, making the data much easier to manipulate
2026
and share.
@@ -24,25 +30,20 @@ and share.
2430
The JNIfTI toolbox includes a stand-alone NIfTI-1/2 parser that works on both
2531
MATLAB and GNU Octave without needing additional components. To just reading and
2632
writing the un-compressed NIfTI and Analyze7.5 files (.nii, .hdr/.img), one
27-
only needs to run `addpath('/path/to/jnifti')`. For MATLAB, JNIfTI toolbox
33+
only needs to run `addpath('/path/to/jnifty')`. For MATLAB, JNIfTI toolbox
2834
utilizes `memmapfile`-based disk-reading, making it very fast. For Octave,
2935
`memmapfile` is currently not implemented, so, a full reading is required.
3036

3137
The JNIfTI toolbox is also capable of reading/writing gzip-compressed NIfTI and
3238
Analyze7.5 files (`.nii.gz, .hdr.gz, .img.gz`). This feature is supported in MATLAB
3339
directly without needing another toolbox (MATLAB must be in the JVM-enabled mode).
3440

35-
To process gzip-compressed NIfTI/Analyze files in Octave and MATLAB with `-nojvm`,
36-
one need to install the open-source JSONLab and ZMat toolboxes, both supporting
37-
MATLAB and Octave. They can be downloaded at
38-
39-
* JSONLab: http://github.com/NeuroJSON/jsonlab
40-
* ZMat: http://github.com/NeuroJSON/zmat
41-
4241
To save NIfTI-1/2 data as JNIfTI files, one needs to install JSONLab. The JNIfTI
4342
data format supports internal compression (as oppose to external compression such
44-
as `*.gz` files). To create or read compressed JNIfTI files in Octave, one must
45-
install the ZMat toolbox, as listed above.
43+
as `*.gz` files).
44+
45+
To create or read compressed NIfTI/JNIfTI files in Octave, one may install the
46+
ZMat toolbox (https://github.com/NeuroJSON/zmat), although it is optional.
4647

4748
## Usage
4849

@@ -63,29 +64,29 @@ Example:
6364
### `savenifti` - To write an image as NIfTI-1/2 (.nii or .nii.gz) file
6465
Example:
6566
```
66-
savenifti(img,'test.nii.gz'); % save an array img to a compressed nifti file
67+
savenifti(img, 'test.nii.gz'); % save an array img to a compressed nifti file
6768
savenifti(img, 'test.nii', 'nifti2'); % save an array img to a nifti-2 file file
6869
savenifti(img, 'test.nii', header); % save an array img with an existing header
6970
```
7071
### `loadjnifti` - To read a JNIfTI (.jnii or .bnii) file
7172
Example:
7273
```
73-
jnii=nii2jnii('test.nii.gz');
74-
savejnifti(jnii, 'magic10.bnii','Compression','gzip');
75-
newjnii=loadjnifti('magic10.bnii');
74+
jnii = nii2jnii('test.nii.gz');
75+
savejnifti(jnii, 'magic10.bnii', 'Compression', 'gzip');
76+
newjnii = loadjnifti('magic10.bnii');
7677
```
7778
### `savejnifti` - To write a JNIfTI structure into a file (.jnii or .bnii)
7879
Example:
7980
```
80-
jnii=jnifticreate(uint8(magic(10)),'Name','10x10 magic matrix');
81+
jnii = jnifticreate(uint8(magic(10)), 'Name', '10x10 magic matrix');
8182
savejnifti(jnii, 'magic10.jnii');
82-
savejnifti(jnii, 'magic10_debug.bnii','Compression','gzip');
83+
savejnifti(jnii, 'magic10_debug.bnii', 'Compression', 'gzip');
8384
```
8485
### `jnii2nii` - To convert a JNIfTI file or data structure to a NIfTI-1/2 file
8586
Example:
8687
```
87-
nii=jnii2nii('test.jnii'); % read a .jnii file as an nii structure
88-
nii=jnii2nii('test.bnii'); % read a .bnii file as an nii structure
88+
nii = jnii2nii('test.jnii'); % read a .jnii file as an nii structure
89+
nii = jnii2nii('test.bnii'); % read a .bnii file as an nii structure
8990
jnii2nii('test.jnii', 'newdata.nii.gz'); % read a text-JNIfTI file to an .nii.gz file
90-
jnii2nii('test.bnii', 'newdata.nii'); % read a text-JNIfTI file to an .nii file
91+
jnii2nii('test.bnii', 'newdata.nii'); % read a text-JNIfTI file to an .nii file
9192
```

gzipdecode.m

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
%
77
% Decompressing a GZIP-compressed byte-stream to recover the original data
88
% This function depends on JVM in MATLAB or, can optionally use the ZMat
9-
% toolbox (http://github.com/NeuroJSON/zmat)
9+
% toolbox (https://github.com/NeuroJSON/zmat)
1010
%
1111
% Copyright (c) 2012, Kota Yamaguchi
1212
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities
@@ -36,15 +36,19 @@
3636
if (nargin == 0)
3737
error('you must provide at least 1 input');
3838
end
39-
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
39+
40+
nozmat = getvarfrom({'caller', 'base'}, 'NO_ZMAT');
41+
42+
if ((exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3) && (isempty(nozmat) || nozmat == 0))
4043
if (nargin > 1)
4144
[varargout{1:nargout}] = zmat(varargin{1}, varargin{2:end});
4245
else
4346
[varargout{1:nargout}] = zmat(varargin{1}, 0, 'gzip', varargin{2:end});
4447
end
4548
return
4649
elseif (isoctavemesh)
47-
error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave');
50+
[varargout{1:nargout}] = octavezmat(varargin{1}, 0, 'gzip');
51+
return
4852
end
4953
error(javachk('jvm'));
5054

gzipencode.m

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
% Compress a string or numerical array using the GZIP-compression
88
%
99
% This function depends on JVM in MATLAB or, can optionally use the ZMat
10-
% toolbox (http://github.com/NeuroJSON/zmat)
10+
% toolbox (https://github.com/NeuroJSON/zmat)
1111
%
1212
% Copyright (c) 2012, Kota Yamaguchi
1313
% URL: https://www.mathworks.com/matlabcentral/fileexchange/39526-byte-encoding-utilities
@@ -35,20 +35,28 @@
3535
error('you must provide at least 1 input');
3636
end
3737

38-
if (exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3)
38+
nozmat = getvarfrom({'caller', 'base'}, 'NO_ZMAT');
39+
40+
if ((exist('zmat', 'file') == 2 || exist('zmat', 'file') == 3) && (isempty(nozmat) || nozmat == 0))
3941
[varargout{1:nargout}] = zmat(varargin{1}, 1, 'gzip');
4042
return
4143
elseif (isoctavemesh)
42-
error('You must install the ZMat toolbox (http://github.com/NeuroJSON/zmat) to use this function in Octave');
44+
[varargout{1:nargout}] = octavezmat(varargin{1}, 1, 'gzip');
45+
return
4346
end
4447

4548
error(javachk('jvm'));
4649

47-
if (ischar(varargin{1}))
48-
varargin{1} = uint8(varargin{1});
50+
input = varargin{1}(:)';
51+
if (ischar(input))
52+
input = uint8(input);
53+
elseif (isa(input, 'string'))
54+
input = uint8(char(input));
55+
else
56+
input = typecast(input, 'uint8');
4957
end
5058

51-
input = typecast(varargin{1}(:)', 'uint8');
59+
input = typecast(input, 'uint8');
5260

5361
buffer = java.io.ByteArrayOutputStream();
5462
gzip = java.util.zip.GZIPOutputStream(buffer);

jnifticreate.m

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
% input:
1313
% img: set the jnii.NIFTIData section
1414
% 'header_i': the header subfield name defined in the JNIfTI
15-
% specification, see https://github.com/NeuroJSON/jnifti
15+
% specification, see https://github.com/NeuroJSON/jnifty
1616
% value_i: set the value for the specified JNIfTI header field
1717
%
1818
% output:
1919
% jnii: without any input, jnii gives the default jnii header
2020
% if img is given, jnii also includes the NIFTIData field
2121
%
2222
%
23-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
23+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
2424
%
25-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
25+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
2626
%
2727

2828
jnii = struct(encodevarname('_DataInfo_'), struct(), 'NIFTIHeader', struct(), 'NIFTIData', []);
@@ -59,9 +59,9 @@
5959
% jnii.NIFTIHeader.A75GlobalMax= 255;
6060
% jnii.NIFTIHeader.A75GlobalMin= 0;
6161
jnii.NIFTIHeader.Description = '';
62-
% jnii.NIFTIHeader.AuxFile= '';
63-
jnii.NIFTIHeader.QForm = 0;
64-
jnii.NIFTIHeader.SForm = 1;
62+
% jnii.NIFTIHeader.AuxFile= '';
63+
jnii.NIFTIHeader.QForm = '';
64+
jnii.NIFTIHeader.SForm = 'scanner_anat';
6565
jnii.NIFTIHeader.Quatern.b = 0;
6666
jnii.NIFTIHeader.Quatern.c = 0;
6767
jnii.NIFTIHeader.Quatern.d = 0;
@@ -77,8 +77,8 @@
7777

7878
datainfo.JNIFTIVersion = '0.5';
7979
datainfo.Comment = 'Created by JNIFTY Toolbox (https://github.com/NeuroJSON/jnifty)';
80-
datainfo.AnnotationFormat = 'https://github.com/NeuroJSON/jnifti/blob/master/JNIfTI_specification.md';
81-
datainfo.SerialFormat = 'http://json.org';
80+
datainfo.AnnotationFormat = 'https://neurojson.org/jnifti/draft2';
81+
datainfo.SerialFormat = 'https://json.org';
8282
datainfo.Parser = struct('Python', [], ...
8383
'MATLAB', [], ...
8484
'JavaScript', 'https://github.com/NeuroJSON/jsdata', ...

jnii2nii.m

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,12 @@
4545
% dependency:
4646
%
4747
% To load a JNIfTI file with compression or niifile ends with (.nii.gz/.hdr.gz/.img.gz),
48-
% one must install the ZMat Toolbox (http://github.com/NeuroJSON/zmat) and
49-
% JSONLab Toolbox (http://github.com/NeuroJSON/jsonlab);
48+
% one must install the ZMat Toolbox (https://github.com/NeuroJSON/zmat) and
49+
% JSONLab Toolbox (https://github.com/NeuroJSON/jsonlab);
5050
%
51-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
51+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
5252
%
53-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
53+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
5454
%
5555

5656
if (nargin <= 0)
@@ -96,11 +96,11 @@
9696
nii.hdr.intent_p2 = bytematch(jnii.NIFTIHeader, 'Param2', nii.hdr.intent_p2);
9797
nii.hdr.intent_p3 = bytematch(jnii.NIFTIHeader, 'Param3', nii.hdr.intent_p3);
9898

99-
if (ischar(jnii.NIFTIHeader.Intent))
99+
if (isfield(jnii.NIFTIHeader, 'Intent') && ischar(jnii.NIFTIHeader.Intent))
100100
jnii.NIFTIHeader.Intent = niicodemap('intent', jnii.NIFTIHeader.Intent);
101101
end
102102
nii.hdr.intent_code = bytematch(jnii.NIFTIHeader, 'Intent', nii.hdr.intent_code);
103-
if (ischar(jnii.NIFTIHeader.DataType))
103+
if (isfield(jnii.NIFTIHeader, 'DataType') && ischar(jnii.NIFTIHeader.DataType))
104104
jnii.NIFTIHeader.DataType = niicodemap('datatype', jnii.NIFTIHeader.DataType);
105105
end
106106

@@ -114,14 +114,14 @@
114114
nii.hdr.scl_inter = bytematch(jnii.NIFTIHeader, 'ScaleOffset', nii.hdr.scl_inter);
115115
nii.hdr.slice_end = bytematch(jnii.NIFTIHeader, 'LastSliceID', nii.hdr.slice_end);
116116

117-
if (ischar(jnii.NIFTIHeader.SliceType))
117+
if (isfield(jnii.NIFTIHeader, 'SliceType') && ischar(jnii.NIFTIHeader.SliceType))
118118
jnii.NIFTIHeader.SliceType = niicodemap('slicetype', jnii.NIFTIHeader.SliceType);
119119
end
120120
nii.hdr.slice_code = bytematch(jnii.NIFTIHeader, 'SliceType', nii.hdr.slice_code);
121-
if (ischar(jnii.NIFTIHeader.Unit.L))
121+
if (isfield(jnii.NIFTIHeader, 'Unit') && isfield(jnii.NIFTIHeader.Unit, 'L') && ischar(jnii.NIFTIHeader.Unit.L))
122122
jnii.NIFTIHeader.Unit.L = niicodemap('unit', jnii.NIFTIHeader.Unit.L);
123123
end
124-
if (ischar(jnii.NIFTIHeader.Unit.T))
124+
if (isfield(jnii.NIFTIHeader, 'Unit') && isfield(jnii.NIFTIHeader.Unit, 'T') && ischar(jnii.NIFTIHeader.Unit.T))
125125
jnii.NIFTIHeader.Unit.T = niicodemap('unit', jnii.NIFTIHeader.Unit.T);
126126
end
127127

@@ -140,6 +140,13 @@
140140
nii.hdr.descrip = bytematch(jnii.NIFTIHeader, 'Description', nii.hdr.descrip);
141141
nii.hdr.aux_file = bytematch(jnii.NIFTIHeader, 'AuxFile', nii.hdr.aux_file);
142142

143+
if (isfield(jnii.NIFTIHeader, 'QForm') && ischar(jnii.NIFTIHeader.QForm))
144+
jnii.NIFTIHeader.QForm = niicodemap('qform_code', jnii.NIFTIHeader.QForm);
145+
end
146+
if (isfield(jnii.NIFTIHeader, 'SForm') && ischar(jnii.NIFTIHeader.SForm))
147+
jnii.NIFTIHeader.SForm = niicodemap('sform_code', jnii.NIFTIHeader.SForm);
148+
end
149+
143150
nii.hdr.qform_code = bytematch(jnii.NIFTIHeader, 'QForm', nii.hdr.qform_code);
144151
nii.hdr.sform_code = bytematch(jnii.NIFTIHeader, 'SForm', nii.hdr.sform_code);
145152
nii.hdr.quatern_b = bytematch(jnii.NIFTIHeader, 'Quatern.b', nii.hdr.quatern_b);
@@ -181,7 +188,6 @@
181188

182189
function dat = bytematch(jobj, key, orig)
183190
dtype = class(orig);
184-
dat = orig;
185191
if (isfield(jobj, key))
186192
dat = cast(jobj.(key), dtype);
187193
else

loadjnifti.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
% jnii=loadjnifti(inputfile, 'Param1',value1, 'Param2',value2,...)
66
%
77
% Load a standard NIFTI-1/2 file or text or binary JNIfTI file with
8-
% format defined in JNIfTI specification: https://github.com/NeuroJSON/jnifti
8+
% format defined in JNIfTI specification: https://github.com/NeuroJSON/jnifty
99
%
1010
% author: Qianqian Fang (q.fang <at> neu.edu)
1111
%
@@ -33,17 +33,17 @@
3333
% savejnifti(jnii, 'magic10.jnii')
3434
% newjnii=loadjnifti('magic10.jnii');
3535
%
36-
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifti
36+
% this file is part of JNIfTI specification: https://github.com/NeuroJSON/jnifty
3737
%
38-
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifti for details
38+
% License: Apache 2.0, see https://github.com/NeuroJSON/jnifty for details
3939
%
4040

4141
if (nargin < 1)
4242
error('you must provide data and output file name');
4343
end
4444

4545
if (~exist('savejson', 'file'))
46-
error('you must first install JSONLab from http://github.com/NeuroJSON/jsonlab/');
46+
error('you must first install JSONLab from https://github.com/NeuroJSON/jsonlab/');
4747
end
4848

4949
if (regexp(filename, '\.nii$'))

0 commit comments

Comments
 (0)