Skip to content

Commit 70d273d

Browse files
committed
upgrade all bnii samples to BJD Draft 2, add _DataInfo_, fix #2, fix #3
1 parent 5b8eb89 commit 70d273d

13 files changed

Lines changed: 298 additions & 215 deletions

lib/matlab/jnifticreate.m

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
%
2727

2828

29-
jnii=struct('NIFTIHeader',struct(), 'NIFTIData', []);
29+
jnii=struct(encodevarname('_DataInfo_'),struct(),'NIFTIHeader',struct(), 'NIFTIData', []);
3030

3131
% jnii.NIFTIHeader.NIIHeaderSize= 0;
3232
% jnii.NIFTIHeader.A75DataTypeName= 'uint8';
@@ -76,6 +76,20 @@
7676
jnii.NIFTIHeader.NIIFormat= 'jnifti';
7777
% jnii.NIFTIHeader.NIIExtender= [0,0,0,0];
7878

79+
datainfo.JNIFTIVersion='0.5';
80+
datainfo.Comment='Created by JNIFTY Toolbox (https://github.com/NeuroJSON/jnifty)';
81+
datainfo.AnnotationFormat='https://github.com/NeuroJSON/jnifti/blob/master/JNIfTI_specification.md';
82+
datainfo.SerialFormat='http://json.org';
83+
datainfo.Parser=struct('Python',[], ...
84+
'MATLAB',[], ...
85+
'JavaScript', 'https://github.com/NeuroJSON/jsdata',...
86+
'CPP', 'https://github.com/NeuroJSON/json',...
87+
'C', 'https://github.com/NeuroJSON/ubj');
88+
datainfo.Parser.Python={'https://pypi.org/project/jdata','https://pypi.org/project/bjdata'};
89+
datainfo.Parser.MATLAB={'https://github.com/NeuroJSON/jnifty','https://github.com/NeuroJSON/jsonlab'};
90+
datainfo.JNIFTIVersion='0.5';
91+
jnii.(encodevarname('_DataInfo_'))=datainfo;
92+
7993
if(nargin==0)
8094
return;
8195
end

lib/matlab/memmapstream.m

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function outstruct=memmapstream(bytes, format)
1+
function outstruct=memmapstream(bytes, format, varargin)
22
%
33
% outstruct=memmapstream(bytes, format)
44
%
@@ -58,13 +58,24 @@
5858

5959
datatype=struct('int8',1,'int16',2,'int32',4,'int64',8,'uint8',1,'uint16',2,'uint32',4,'uint64',8,'single',4,'double',8);
6060

61-
outstruct=struct();
61+
opt=varargin2struct(varargin{:});
62+
opt.usemap=jsonopt('usemap',0,opt) && exist('containers.Map');
63+
64+
if(opt.usemap)
65+
outstruct=containers.Map();
66+
else
67+
outstruct=struct();
68+
end
6269
len=1;
6370
for i=1:size(format,1)
6471
bytelen=datatype.(format{i,1})*prod(format{i,2});
65-
outstruct.(format{i,3})=reshape(typecast(uint8(bytes(len:bytelen+len-1)),format{i,1}),format{i,2});
72+
if(opt.usemap)
73+
outstruct(format{i,3})=reshape(typecast(uint8(bytes(len:bytelen+len-1)),format{i,1}),format{i,2});
74+
else
75+
outstruct.(format{i,3})=reshape(typecast(uint8(bytes(len:bytelen+len-1)),format{i,1}),format{i,2});
76+
end
6677
len=len+bytelen;
6778
if(len>length(bytes))
6879
break;
6980
end
70-
end
81+
end

samples/basic/mousehead.bnii

537 Bytes
Binary file not shown.

samples/basic/mousehead.jnii

Lines changed: 66 additions & 47 deletions
Large diffs are not rendered by default.

samples/basic/mousehead_gzip.bnii

537 Bytes
Binary file not shown.

samples/basic/mousehead_lzma.jnii

Lines changed: 68 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,82 @@
11
{
2-
"NIFTIHeader": {
3-
"DimInfo": {
4-
"Freq": 0,
5-
"Phase": 0,
6-
"Slice": 0
2+
"_DataInfo_":{
3+
"JNIFTIVersion":"0.5",
4+
"Comment":"Created by JNIFTY Toolbox (https:\/\/github.com\/NeuroJSON\/jnifty)",
5+
"AnnotationFormat":"https:\/\/github.com\/NeuroJSON\/jnifti\/blob\/master\/JNIfTI_specification.md",
6+
"SerialFormat":"http:\/\/json.org",
7+
"Parser":{
8+
"Python":[
9+
"https:\/\/pypi.org\/project\/jdata",
10+
"https:\/\/pypi.org\/project\/bjdata"
11+
],
12+
"MATLAB":[
13+
"https:\/\/github.com\/NeuroJSON\/jnifty",
14+
"https:\/\/github.com\/NeuroJSON\/jsonlab"
15+
],
16+
"JavaScript":"https:\/\/github.com\/NeuroJSON\/jsdata",
17+
"CPP":"https:\/\/github.com\/NeuroJSON\/json",
18+
"C":"https:\/\/github.com\/NeuroJSON\/ubj"
19+
}
20+
},
21+
"NIFTIHeader":{
22+
"DimInfo":{
23+
"Freq":0,
24+
"Phase":0,
25+
"Slice":0
726
},
8-
"Dim": [50,53,44],
9-
"Param1": 0,
10-
"Param2": 0,
11-
"Param3": 0,
12-
"Intent": "",
13-
"DataType": "uint8",
14-
"BitDepth": 8,
15-
"FirstSliceID": 1,
16-
"VoxelSize": [1,1,1,1],
17-
"Orientation": {
18-
"x": "r",
19-
"y": "a",
20-
"z": "s"
27+
"Dim":[50,53,44],
28+
"Param1":0,
29+
"Param2":0,
30+
"Param3":0,
31+
"Intent":"",
32+
"DataType":"uint8",
33+
"BitDepth":8,
34+
"FirstSliceID":1,
35+
"VoxelSize":[1,1,1,1],
36+
"Orientation":{
37+
"x":"r",
38+
"y":"a",
39+
"z":"s"
2140
},
22-
"ScaleSlope": 0,
23-
"ScaleOffset": 0,
24-
"LastSliceID": 1,
25-
"SliceType": "",
26-
"Unit": {
27-
"L": "mm",
28-
"T": "s"
41+
"ScaleSlope":0,
42+
"ScaleOffset":0,
43+
"LastSliceID":1,
44+
"SliceType":"",
45+
"Unit":{
46+
"L":"mm",
47+
"T":"s"
2948
},
30-
"MaxIntensity": 1,
31-
"MinIntensity": 0,
32-
"SliceTime": 1,
33-
"TimeOffset": 0,
34-
"Description": "Binary mask of a mouse-head scan",
35-
"QForm": 0,
36-
"SForm": 1,
37-
"Quatern": {
38-
"b": 0,
39-
"c": 0,
40-
"d": 0
49+
"MaxIntensity":1,
50+
"MinIntensity":0,
51+
"SliceTime":1,
52+
"TimeOffset":0,
53+
"Description":"Binary mask of a mouse-head scan",
54+
"QForm":0,
55+
"SForm":1,
56+
"Quatern":{
57+
"b":0,
58+
"c":0,
59+
"d":0
4160
},
42-
"QuaternOffset": {
43-
"x": 0,
44-
"y": 0,
45-
"z": 0
61+
"QuaternOffset":{
62+
"x":0,
63+
"y":0,
64+
"z":0
4665
},
47-
"Affine": [
66+
"Affine":[
4867
[1,0,0,0],
4968
[0,1,0,0],
5069
[0,0,1,0]
5170
],
52-
"Name": "Mouse Head",
53-
"NIIFormat": "jnifti"
71+
"Name":"Mouse Head",
72+
"NIIFormat":"jnifti"
5473
},
55-
"NIFTIData": {
56-
"_ArrayType_": "uint8",
57-
"_ArraySize_": [50,53,44],
58-
"_ArrayZipType_": "lzma",
59-
"_ArrayZipSize_": [1,116600],
60-
"_ArrayZipData_": "XQAAEAB4xwEAAAAAAAAAb/3//6O3/0c+SBVyOWFRuJIo5qOGB/nu5B6C0y/FOjwBS7F+yYqK
74+
"NIFTIData":{
75+
"_ArrayType_":"uint8",
76+
"_ArraySize_":[50,53,44],
77+
"_ArrayZipType_":"lzma",
78+
"_ArrayZipSize_":[1,116600],
79+
"_ArrayZipData_":"XQAAEAB4xwEAAAAAAAAAb/3//6O3/0c+SBVyOWFRuJIo5qOGB/nu5B6C0y/FOjwBS7F+yYqK
6180
TS+jCrjmKYbnrFLW1EyWGtHke96TYmxJ6gLXh0dVMggRVyRxd8jFODkdOfDwZGSo/w4GNQw4
6281
f9HX0Pv+pUHrv5+NFePhdbAxVCrf5+xjSfd8u30SrdbXPpdV02Tcp0MI6toqU90rxpB3OOH9
6382
cM3HJEKPUoAD+ovBVl9QVNuqcduYtyR97+N8UHLAbAUQga5meIRQgW/jGdBJZ6inBCqsM7oO

samples/colin27/colin27_zlib.bnii

537 Bytes
Binary file not shown.

samples/colin27/colin27_zlib.jnii

Lines changed: 71 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,82 @@
11
{
2-
"NIFTIHeader": {
3-
"DimInfo": {
4-
"Freq": 0,
5-
"Phase": 0,
6-
"Slice": 0
2+
"_DataInfo_":{
3+
"JNIFTIVersion":"0.5",
4+
"Comment":"Created by JNIFTY Toolbox (https:\/\/github.com\/NeuroJSON\/jnifty)",
5+
"AnnotationFormat":"https:\/\/github.com\/NeuroJSON\/jnifti\/blob\/master\/JNIfTI_specification.md",
6+
"SerialFormat":"http:\/\/json.org",
7+
"Parser":{
8+
"Python":[
9+
"https:\/\/pypi.org\/project\/jdata",
10+
"https:\/\/pypi.org\/project\/bjdata"
11+
],
12+
"MATLAB":[
13+
"https:\/\/github.com\/NeuroJSON\/jnifty",
14+
"https:\/\/github.com\/NeuroJSON\/jsonlab"
15+
],
16+
"JavaScript":"https:\/\/github.com\/NeuroJSON\/jsdata",
17+
"CPP":"https:\/\/github.com\/NeuroJSON\/json",
18+
"C":"https:\/\/github.com\/NeuroJSON\/ubj"
19+
}
20+
},
21+
"NIFTIHeader":{
22+
"DimInfo":{
23+
"Freq":0,
24+
"Phase":0,
25+
"Slice":0
726
},
8-
"Dim": [181,217,181],
9-
"Param1": 0,
10-
"Param2": 0,
11-
"Param3": 0,
12-
"Intent": "",
13-
"DataType": "uint8",
14-
"BitDepth": 8,
15-
"FirstSliceID": 1,
16-
"VoxelSize": [1,1,1,1],
17-
"Orientation": {
18-
"x": "r",
19-
"y": "a",
20-
"z": "s"
27+
"Dim":[181,217,181],
28+
"Param1":0,
29+
"Param2":0,
30+
"Param3":0,
31+
"Intent":"",
32+
"DataType":"uint8",
33+
"BitDepth":8,
34+
"FirstSliceID":1,
35+
"VoxelSize":[1,1,1,1],
36+
"Orientation":{
37+
"x":"r",
38+
"y":"a",
39+
"z":"s"
2140
},
22-
"ScaleSlope": 0,
23-
"ScaleOffset": 0,
24-
"LastSliceID": 1,
25-
"SliceType": "",
26-
"Unit": {
27-
"L": "mm",
28-
"T": "s"
41+
"ScaleSlope":0,
42+
"ScaleOffset":0,
43+
"LastSliceID":1,
44+
"SliceType":"",
45+
"Unit":{
46+
"L":"mm",
47+
"T":"s"
2948
},
30-
"MaxIntensity": 6,
31-
"MinIntensity": 0,
32-
"SliceTime": 1,
33-
"TimeOffset": 0,
34-
"Description": "Colin27 segmentation, processed by Qianqian Fang",
35-
"QForm": 0,
36-
"SForm": 1,
37-
"Quatern": {
38-
"b": 0,
39-
"c": 0,
40-
"d": 0
49+
"MaxIntensity":6,
50+
"MinIntensity":0,
51+
"SliceTime":1,
52+
"TimeOffset":0,
53+
"Description":"Colin27 segmentation, processed by Qianqian Fang",
54+
"QForm":0,
55+
"SForm":1,
56+
"Quatern":{
57+
"b":0,
58+
"c":0,
59+
"d":0
4160
},
42-
"QuaternOffset": {
43-
"x": 0,
44-
"y": 0,
45-
"z": 0
61+
"QuaternOffset":{
62+
"x":0,
63+
"y":0,
64+
"z":0
4665
},
47-
"Affine": [
48-
[1,0,0,0],
49-
[0,1,0,0],
50-
[0,0,1,0]
66+
"Affine":[
67+
[1,0,0,-91],
68+
[0,1,0,-127],
69+
[0,0,1,-73]
5170
],
52-
"Name": "Colin27",
53-
"NIIFormat": "jnifti"
71+
"Name":"Colin27",
72+
"NIIFormat":"jnifti"
5473
},
55-
"NIFTIData": {
56-
"_ArrayType_": "uint8",
57-
"_ArraySize_": [181,217,181],
58-
"_ArrayZipType_": "zlib",
59-
"_ArrayZipSize_": [1,7109137],
60-
"_ArrayZipData_": "eJzs3YmC6riuBVAgw/9/ch/IZMmy40FW7Oq937t9qiiGFSGcAYhfLwRBEARBEARBEARBEARB
74+
"NIFTIData":{
75+
"_ArrayType_":"uint8",
76+
"_ArraySize_":[181,217,181],
77+
"_ArrayZipType_":"zlib",
78+
"_ArrayZipSize_":[1,7109137],
79+
"_ArrayZipData_":"eJzs3YmC6riuBVAgw/9/ch/IZMmy40FW7Oq937t9qiiGFSGcAYhfLwRBEARBEARBEARBEARB
6180
EARBEARBEARBEARBEARBEARBEARBEARBEAQZOss3r+VpRkYWJ/KfHmHFsniR//gYUIqPPoCR
6281
hXk6EnoJ/OFp6xkR/X1VBpemgwTQoTzN3ZKJ7kPteSjR/+Nz1CtCEWMF7kMtPvHhpugY/Qqu
6382
V7pCh/8Uu+CpnJAETGfoJR3dnnSfs9B/FZ12JYMcxevFk5QdO5T5NaJ5y4hmBAlkyG4eEj0o

samples/colin27/create_jnii.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
load colin27.mat
22

33
jnii=jnifticreate(uint8(colin27),'Name','Colin27','Description','Colin27 segmentation, processed by Qianqian Fang');
4+
jnii.NIFTIHeader.Affine=[1 0 0 -91; 0 1 0 -127; 0 0 1 -73];
45

56
tic;savejnifti(jnii,'colin27.bnii');toc
67
tic;savejnifti(jnii,'colin27_zlib.bnii','compression','zlib');toc

0 commit comments

Comments
 (0)