Skip to content

Commit 5b8eb89

Browse files
committed
replace all saveubjson by savebj, clarify row-major/column-major conversion
1 parent 54a9cb3 commit 5b8eb89

8 files changed

Lines changed: 27 additions & 15 deletions

File tree

JNIfTI_specification.md

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ is listed below
436436
|*NIFTI code for ppm* | |
437437
| `NIFTI_UNITS_PPM 40 `| `"ppm"` |
438438
|*NIFTI code for radians per second* | |
439-
| `NIFTI_UNITS_RADS 48 `| `"rad"` |
439+
| `NIFTI_UNITS_RADS 48 `| `"rad/s" |
440440

441441

442442
#### Intent (NIFTI-1 header: `intent_code`)
@@ -629,9 +629,21 @@ One can also apply data compression to reduce file sizes. In this case
629629
```
630630

631631
Please note that all composite data types (marked by "\*" in Table 2)
632-
can not be stored in the direct form and therefore must be stored using the annotated array format.
633-
634-
All three of the above forms are valid JSON formats, and thus can be converted to the corresponding
632+
can not be stored in the direct form and therefore must be stored using
633+
the annotated array format.
634+
635+
NIfTI-1/2 stores raw data values in the column-major element order (meaning
636+
that the left-most index (`dim[1]`) is the fastest index while the right-most index
637+
is the slowest) while JData `_ArrayData_` construct by default stores data elements
638+
in the row-major order (i.e. the right-most index is the fastest index). As a result,
639+
if one has to directly copy the NIfTI data buffer to the `_ArrayData_` element,
640+
one must add `"_ArrayOrder_" : "c"` or `"_ArrayOrder_" : "col"` before `_ArrayData_`
641+
or `_ArrayZipData_` entries in the above annotated `NIFTIData` forms.
642+
Alternatively, if `_ArrayOrder_` is not specified (which suggests "row-major" order),
643+
one must perform an N-D transpose operation to the NIfTI image data buffer before
644+
serializing those to `_ArrayData_`.
645+
646+
All three of the above forms are valid JSON formats, and thus can be converted to the corresponding
635647
BJData formats when a binary JNIfTI file is desired. Using the optimized N-D array
636648
header defined in the JData specification, the binary storage of the direct-form
637649
array can be efficiently written as

lib/matlab/loadjnifti.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
% *.jnii for text JNIfTI file
1616
% *.nii for NIFTI-1/2 files
1717
% options: (optional) if loading from a .bnii file, please see the options for
18-
% loadubjson.m (part of JSONLab); if loading from a .jnii, please see the
18+
% loadbj.m (part of JSONLab); if loading from a .jnii, please see the
1919
% supported options for loadjson.m (part of JSONLab).
2020
%
2121
% output:
@@ -51,7 +51,7 @@
5151
elseif(regexp(filename,'\.jnii$'))
5252
jnii=loadjson(filename,varargin{:});
5353
elseif(regexp(filename,'\.bnii$'))
54-
jnii=loadubjson(filename,varargin{:});
54+
jnii=loadbj(filename,varargin{:});
5555
else
5656
error('file suffix must be .jnii for text JNIfTI, .bnii for binary JNIfTI or .nii for NIFTI-1/2 files');
5757
end

lib/matlab/nii2jnii.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
% file name - *.jnii for text-based JNIfTI, or *.bnii for the
2626
% binary version
2727
% options: (optional) if saving to a .bnii file, please see the options for
28-
% saveubjson.m (part of JSONLab); if saving to .jnii, please see the
28+
% savebj.m (part of JSONLab); if saving to .jnii, please see the
2929
% supported options for savejson.m (part of JSONLab).
3030
%
3131
% output:
@@ -338,7 +338,7 @@
338338
if(regexp(format,'\.jnii$'))
339339
savejson('',nii,'FileName',format,varargin{:});
340340
elseif(regexp(format,'\.bnii$'))
341-
saveubjson('',nii,'FileName',format,varargin{:});
341+
savebj('',nii,'FileName',format,varargin{:});
342342
else
343343
error('file suffix must be .jnii for text JNIfTI or .bnii for binary JNIfTI');
344344
end

lib/matlab/savebnii.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ function savebnii(jnii, filename, varargin)
2020
% jnii.NIFTIExtension - a cell array contaiing the extension data buffers
2121
% filename: the output file name to the binary-JNIfTI file (.bnii)
2222
% options: (optional) if saving to .bnii, please see the
23-
% supported options for saveubjson.m (part of JSONLab).
23+
% supported options for savebj.m (part of JSONLab).
2424
%
2525
% example:
2626
% jnii=jnifticreate(uint8(magic(10)),'Name','10x10 magic matrix');
@@ -36,8 +36,8 @@ function savebnii(jnii, filename, varargin)
3636
error('you must provide data and output file name');
3737
end
3838

39-
if(~exist('saveubjson','file'))
39+
if(~exist('savebj','file'))
4040
error('you must first install JSONLab from http://github.com/fangq/jsonlab/');
4141
end
4242

43-
saveubjson('',jnii,'FileName',filename,varargin{:});
43+
savebj('',jnii,'FileName',filename,varargin{:});

lib/matlab/savejnifti.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ function savejnifti(jnii, filename, varargin)
2222
% *.bnii for binary JNIfTI file
2323
% *.jnii for text JNIfTI file
2424
% options: (optional) if saving to a .bnii file, please see the options for
25-
% saveubjson.m (part of JSONLab); if saving to .jnii, please see the
25+
% savebj.m (part of JSONLab); if saving to .jnii, please see the
2626
% supported options for savejson.m (part of JSONLab).
2727
%
2828
% example:

0 commit comments

Comments
 (0)