forked from fangq/iso2mesh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update jsonlab to support lz4, update jnifti toolbox to v0.5
- Loading branch information
Showing
15 changed files
with
601 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
function varargout = loadnifti (varargin) | ||
% | ||
% jnii=loadnifti(filename) | ||
% or | ||
% nii=loadnifti(filename,option) | ||
% | ||
% Read a NIfTI-1/2 (*.nii/.nii.gz) or Analyze 7.5 (*.hdr/*.img/.hdr.gz/.img.gz) | ||
% image file. | ||
% | ||
% author: Qianqian Fang (q.fang <at> neu.edu) | ||
% | ||
% Please run `help nii2jnii` to see the input output outputs. | ||
% This function is an alias to nii2jnii | ||
% | ||
% | ||
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti | ||
% | ||
% License: Apache 2.0, see https://github.com/fangq/jnifti for details | ||
% | ||
|
||
[varargout{1:nargout}]=nii2jnii(varargin{:}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function output = lz4decode(input) | ||
%LZ4DECODE Decompress input bytes using lz4. | ||
% | ||
% output = lz4decode(input) | ||
% | ||
% The function takes a compressed byte array INPUT and returns inflated | ||
% bytes OUTPUT. The INPUT is a result of LZ4DECODE function. The OUTPUT | ||
% is always an 1-by-N uint8 array. | ||
% | ||
% See also lz4encode typecast | ||
% | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
if(nargin==0) | ||
error('you must provide at least 1 input'); | ||
end | ||
if(exist('zmat','file')==2 || exist('zmat','file')==3) | ||
output=zmat(uint8(input),0,'lz4'); | ||
return; | ||
else | ||
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function output = lz4encode(input) | ||
%LZ4ENCODE Compress input bytes with lz4. | ||
% | ||
% output = lz4encode(input) | ||
% | ||
% The function takes a char, int8, or uint8 array INPUT and returns | ||
% compressed bytes OUTPUT as a uint8 array. Note that the compression | ||
% doesn't preserve input dimensions. | ||
% | ||
% See also lz4decode | ||
% | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
if(nargin==0) | ||
error('you must provide at least 1 input'); | ||
end | ||
if(exist('zmat','file')==2 || exist('zmat','file')==3) | ||
output=zmat(uint8(input),1,'lz4'); | ||
return; | ||
else | ||
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function output = lz4hcdecode(input) | ||
%LZ4HCDECODE Decompress input bytes using lz4hc. | ||
% | ||
% output = lz4hcdecode(input) | ||
% | ||
% The function takes a compressed byte array INPUT and returns inflated | ||
% bytes OUTPUT. The INPUT is a result of LZ4HCDECODE function. The OUTPUT | ||
% is always an 1-by-N uint8 array. | ||
% | ||
% See also lz4hcencode typecast | ||
% | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
if(nargin==0) | ||
error('you must provide at least 1 input'); | ||
end | ||
if(exist('zmat','file')==2 || exist('zmat','file')==3) | ||
output=zmat(uint8(input),0,'lz4hc'); | ||
return; | ||
else | ||
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
function output = lz4hcencode(input) | ||
%LZ4HCENCODE Compress input bytes with lz4hc. | ||
% | ||
% output = lz4hcencode(input) | ||
% | ||
% The function takes a char, int8, or uint8 array INPUT and returns | ||
% compressed bytes OUTPUT as a uint8 array. Note that the compression | ||
% doesn't preserve input dimensions. | ||
% | ||
% See also lz4hcdecode | ||
% | ||
% License : BSD, see LICENSE_*.txt | ||
% | ||
|
||
if(nargin==0) | ||
error('you must provide at least 1 input'); | ||
end | ||
if(exist('zmat','file')==2 || exist('zmat','file')==3) | ||
output=zmat(uint8(input),1,'lz4hc'); | ||
return; | ||
else | ||
error('you must install ZMat toolbox to use this feature: http://github.com/fangq/zmat') | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function outstruct=memmapstream(bytes, format) | ||
% | ||
% outstruct=memmapstream(bytes, format) | ||
% | ||
% Map a byte-array (in char array or uint8/int8 array) into a structure | ||
% using a dictionary (format is compatible with memmapfile in MATLAB) | ||
% | ||
% This function is compatible with both MATLAB and GNU Octave. | ||
% | ||
% author: Qianqian Fang (q.fang <at> neu.edu) | ||
% | ||
% input: | ||
% bytes: a char, int8 or uint8 vector or array | ||
% format: a 3-column cell array in the format compatible with the | ||
% 'Format' parameter of memmapfile in MATLAB. It has the | ||
% following structure | ||
% | ||
% column 1: data type string, it can be one of the following | ||
% 'int8','int16','int32','int64', | ||
% 'uint8','uint16','uint32','uint64', | ||
% 'single','double','logical' | ||
% column 2: an integer vector denoting the size of the data | ||
% column 3: a string denoting the fieldname in the output struct | ||
% | ||
% For example format={'int8',[1,8],'key'; 'float',[1,1],'value'} | ||
% reads the first 8 bytes from 'bytes' as the first subfield | ||
% 'key' and the following 4 bytes as the floating point 'value' | ||
% subfield. | ||
% | ||
% output: | ||
% outstruct: a structure containing the required field | ||
% | ||
% example: | ||
% bytestream=['Andy' 5 'JT']; | ||
% format={'uint8', [1,4], 'name', | ||
% 'uint8', [1,1], 'age', | ||
% 'uint8', [1,2], 'school'}; | ||
% data=memmapstream(bytestream,format); | ||
% | ||
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti | ||
% | ||
% License: Apache 2.0, see https://github.com/fangq/jnifti for details | ||
% | ||
|
||
if(nargin<2) | ||
error('must provide bytes and format as inputs'); | ||
end | ||
|
||
if(~ischar(bytes) && ~isa(bytes,'int8') && ~isa(bytes,'uint8') || isempty(bytes)) | ||
error('first input, bytes, must be a char-array or uint8/int8 vector'); | ||
end | ||
|
||
if(~iscell(format) || size(format,2)<3 || size(format,1)==0 || ~ischar(format{1,1})) | ||
error('second input, format, must be a 3-column cell array, in a format described by the memmapfile Format field.'); | ||
end | ||
|
||
bytes=bytes(:)'; | ||
|
||
datatype=struct('int8',1,'int16',2,'int32',4,'int64',8,'uint8',1,'uint16',2,'uint32',4,'uint64',8,'single',4,'double',8); | ||
|
||
outstruct=struct(); | ||
len=1; | ||
for i=1:size(format,1) | ||
bytelen=datatype.(format{i,1})*prod(format{i,2}); | ||
outstruct.(format{i,3})=reshape(typecast(uint8(bytes(len:bytelen+len-1)),format{i,1}),format{i,2}); | ||
len=len+bytelen; | ||
if(len>length(bytes)) | ||
break; | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
function header=nifticreate(img,format) | ||
% | ||
% header=nifticreate(img) | ||
% or | ||
% header=nifticreate(img,format) | ||
% | ||
% Create a default NIfTI header | ||
% | ||
% author: Qianqian Fang (q.fang <at> neu.edu) | ||
% | ||
% input: | ||
% img: the image data matching the header | ||
% format: can only be 'nifti1'. can be ignored | ||
% | ||
% output: | ||
% header: a struct that is byte-wise compatible with NIfTI-1 | ||
% | ||
% this file is part of JNIfTI specification: https://github.com/fangq/jnifti | ||
% | ||
% License: Apache 2.0, see https://github.com/fangq/jnifti for details | ||
% | ||
|
||
if(nargin<2) | ||
format='nifti1'; | ||
end | ||
|
||
datatype=struct('int8',256,'int16',4,'int32',8,'int64',1024,'uint8',2,'uint16',512,'uint32',768,'uint64',1280,'single',16,'double',64); | ||
|
||
if(strcmp(format,'nifti1')) | ||
headerlen=348; | ||
else | ||
headerlen=540; | ||
end | ||
|
||
header=memmapstream(uint8(zeros(1,headerlen+4)),niiformat(format)); | ||
header.sizeof_hdr=cast(headerlen, class(header.sizeof_hdr)); | ||
header.datatype=cast(datatype.(class(img)), class(header.datatype)); | ||
header.dim(1:ndims(img)+1)=cast([ndims(img),size(img)], class(header.dim)); | ||
header.pixdim(1:ndims(img)+1)=cast(1, class(header.pixdim)); | ||
header.vox_offset=cast(headerlen+4, class(header.vox_offset)); | ||
if(header.sizeof_hdr==540) | ||
header.magic(1:3)=cast('ni2',class(header.magic)); | ||
else | ||
header.magic(1:3)=cast('ni1',class(header.magic)); | ||
end | ||
header.srow_x(1)=cast(1, class(header.srow_x)); | ||
header.srow_y(2)=cast(1, class(header.srow_y)); | ||
header.srow_z(3)=cast(1, class(header.srow_z)); | ||
header.sform_code=cast(1, class(header.sform_code)); |
Oops, something went wrong.