From b7bcb2bba6a6e221a2526eb9a0e26e2d9bbfdebc Mon Sep 17 00:00:00 2001 From: Qianqian Fang Date: Fri, 5 Aug 2022 17:10:03 -0400 Subject: [PATCH] use Octave styled comment, NeuroJSON/jnifti#7 --- loadnifti.m | 36 ++++---- memmapstream.m | 84 +++++++++---------- nifticreate.m | 40 ++++----- niftiinfo.m | 68 +++++++-------- niftiread.m | 72 ++++++++-------- niftiwrite.m | 72 ++++++++-------- nii2jnii.m | 218 ++++++++++++++++++++++++------------------------- niicodemap.m | 76 ++++++++--------- niiformat.m | 218 ++++++++++++++++++++++++------------------------- savenifti.m | 68 +++++++-------- 10 files changed, 476 insertions(+), 476 deletions(-) diff --git a/loadnifti.m b/loadnifti.m index 5fd281e..57d42a5 100644 --- a/loadnifti.m +++ b/loadnifti.m @@ -1,21 +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 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 -% +# +# 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 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{:}); diff --git a/memmapstream.m b/memmapstream.m index 29c6859..225f8da 100644 --- a/memmapstream.m +++ b/memmapstream.m @@ -1,46 +1,46 @@ function outstruct = memmapstream(bytes, format, varargin) -% -% 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 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 -% +# +# 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 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'); diff --git a/nifticreate.m b/nifticreate.m index 3faa078..acff4bd 100644 --- a/nifticreate.m +++ b/nifticreate.m @@ -1,24 +1,24 @@ function header = nifticreate(img, format) -% -% header=nifticreate(img) -% or -% header=nifticreate(img,format) -% -% Create a default NIfTI header -% -% author: Qianqian Fang (q.fang 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 -% +# +# header=nifticreate(img) +# or +# header=nifticreate(img,format) +# +# Create a default NIfTI header +# +# author: Qianqian Fang (q.fang 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'; diff --git a/niftiinfo.m b/niftiinfo.m index 56bde0d..af765f8 100644 --- a/niftiinfo.m +++ b/niftiinfo.m @@ -1,28 +1,28 @@ -%% Copyright (C) 2019 Qianqian Fang -%% -%% This program is free software; you can redistribute it and/or modify it under -%% the terms of the GNU General Public License as published by the Free Software -%% Foundation; either version 3 of the License, or (at your option) any later -%% version. -%% -%% This program is distributed in the hope that it will be useful, but WITHOUT -%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -%% details. -%% -%% You should have received a copy of the GNU General Public License along with -%% this program; if not, see . +## Copyright (C) 2019 Qianqian Fang +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . -%% -*- texinfo -*- -%% @deftypefn {Function File} {} niftiinfo (@var{filename}) -%% Read the metadata from a NIfTI-1/2 and Analyze7.5 formatted image file -%% -%% Parsing the metadata in a NIfTI-1/2 file or a two-part NIfTI -%% or Analyze7.5 header file specified by @var{filename}. The -%% accepted file suffixes include .nii, .nii.gz, .hdr, and .hdr.gz. -%% -%% @seealso{niftiread, niftiwrite} -%% @end deftypefn +## -*- texinfo -*- +## @deftypefn {Function File} {} niftiinfo (@var{filename}) +## Read the metadata from a NIfTI-1/2 and Analyze7.5 formatted image file +## +## Parsing the metadata in a NIfTI-1/2 file or a two-part NIfTI +## or Analyze7.5 header file specified by @var{filename}. The +## accepted file suffixes include .nii, .nii.gz, .hdr, and .hdr.gz. +## +## @seealso{niftiread, niftiwrite} +## @end deftypefn function nii = niftiinfo (filename, varargin) @@ -101,14 +101,14 @@ endfunction; -% !demo -% ! %% Reading a -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! header=niftiinfo('minimal.nii'); +# !demo +# ! ## Reading a +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! header=niftiinfo('minimal.nii'); -% !test -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! header=niftiinfo('minimal.nii'); -% ! assert (header.ImageSize,[64 64 10]); +# !test +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! header=niftiinfo('minimal.nii'); +# ! assert (header.ImageSize,[64 64 10]); diff --git a/niftiread.m b/niftiread.m index 19a7350..71ae921 100644 --- a/niftiread.m +++ b/niftiread.m @@ -1,30 +1,30 @@ -%% Copyright (C) 2019 Qianqian Fang -%% -%% This program is free software; you can redistribute it and/or modify it under -%% the terms of the GNU General Public License as published by the Free Software -%% Foundation; either version 3 of the License, or (at your option) any later -%% version. -%% -%% This program is distributed in the hope that it will be useful, but WITHOUT -%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -%% details. -%% -%% You should have received a copy of the GNU General Public License along with -%% this program; if not, see . +## Copyright (C) 2019 Qianqian Fang +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . -%% -*- texinfo -*- -%% @deftypefn {Function File} {} niftiread (@var{filename}) -%% @deftypefnx {Function File} {} niftiread (@var{headerfile}, @var{imagefile}) -%% @deftypefnx {Function File} {} niftiread (@var{info}) -%% Read image data from a NIfTI-1/2 and Analyze7.5 formatted image file -%% -%% Loading a NIfTI-1/2 file specified by @var{filename}, or a two-part NIfTI -%% or Analyze7.5 files using @var{headerfile} and @var{imagefile}. The -%% accepted file suffixes include .nii, .nii.gz, .hdr, .hdr.gz, .img, img.gz -%% -%% @seealso{niftiinfo, niftiwrite} -%% @end deftypefn +## -*- texinfo -*- +## @deftypefn {Function File} {} niftiread (@var{filename}) +## @deftypefnx {Function File} {} niftiread (@var{headerfile}, @var{imagefile}) +## @deftypefnx {Function File} {} niftiread (@var{info}) +## Read image data from a NIfTI-1/2 and Analyze7.5 formatted image file +## +## Loading a NIfTI-1/2 file specified by @var{filename}, or a two-part NIfTI +## or Analyze7.5 files using @var{headerfile} and @var{imagefile}. The +## accepted file suffixes include .nii, .nii.gz, .hdr, .hdr.gz, .img, img.gz +## +## @seealso{niftiinfo, niftiwrite} +## @end deftypefn function img = niftiread (filename, varargin) @@ -42,14 +42,14 @@ endfunction; -% !demo -% ! %% Reading a -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! img=niftiread('minimal.nii'); +# !demo +# ! ## Reading a +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! img=niftiread('minimal.nii'); -% !test -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! img=niftiread('minimal.nii'); -% ! assert (size(img),[64 64 10]); +# !test +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! img=niftiread('minimal.nii'); +# ! assert (size(img),[64 64 10]); diff --git a/niftiwrite.m b/niftiwrite.m index 985a499..a4227f0 100644 --- a/niftiwrite.m +++ b/niftiwrite.m @@ -1,30 +1,30 @@ -%% Copyright (C) 2019 Qianqian Fang -%% -%% This program is free software; you can redistribute it and/or modify it under -%% the terms of the GNU General Public License as published by the Free Software -%% Foundation; either version 3 of the License, or (at your option) any later -%% version. -%% -%% This program is distributed in the hope that it will be useful, but WITHOUT -%% ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -%% FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more -%% details. -%% -%% You should have received a copy of the GNU General Public License along with -%% this program; if not, see . +## Copyright (C) 2019 Qianqian Fang +## +## This program is free software; you can redistribute it and/or modify it under +## the terms of the GNU General Public License as published by the Free Software +## Foundation; either version 3 of the License, or (at your option) any later +## version. +## +## This program is distributed in the hope that it will be useful, but WITHOUT +## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more +## details. +## +## You should have received a copy of the GNU General Public License along with +## this program; if not, see . -%% -*- texinfo -*- -%% @deftypefn {Function File} {} niftiwrite (@var{img}, @var{filename}) -%% @deftypefnx {Function File} {} niftiwrite (@var{img}, @var{filename}, @var{info}) -%% @deftypefnx {Function File} {} niftiwrite (@var{img}, @var{filename}, @var{info},...) -%% Write image data and metadata to a NIfTI-1/2 and Analyze7.5 formatted image file -%% -%% Writing image data @var{img} and metadata @var{info} to a NIfTI-1 -%% file or a two-part NIfTI or Analyze7.5 files specified by @var{filename}. -%% The accepted file suffixes include .nii and .nii.gz. -%% -%% @seealso{niftiinfo, niftiread} -%% @end deftypefn +## -*- texinfo -*- +## @deftypefn {Function File} {} niftiwrite (@var{img}, @var{filename}) +## @deftypefnx {Function File} {} niftiwrite (@var{img}, @var{filename}, @var{info}) +## @deftypefnx {Function File} {} niftiwrite (@var{img}, @var{filename}, @var{info},...) +## Write image data and metadata to a NIfTI-1/2 and Analyze7.5 formatted image file +## +## Writing image data @var{img} and metadata @var{info} to a NIfTI-1 +## file or a two-part NIfTI or Analyze7.5 files specified by @var{filename}. +## The accepted file suffixes include .nii and .nii.gz. +## +## @seealso{niftiinfo, niftiread} +## @end deftypefn function niftiwrite (img, filename, varargin) @@ -63,14 +63,14 @@ function niftiwrite (img, filename, varargin) endfunction; -% !demo -% ! %% Reading a -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! header=niftiinfo('minimal.nii'); +# !demo +# ! ## Reading a +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! header=niftiinfo('minimal.nii'); -% !test -% ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') -% ! gunzip ('minimal.nii.gz'); -% ! header=niftiinfo('minimal.nii'); -% ! assert (header.ImageSize,[64 64 10]); +# !test +# ! urlwrite('https://nifti.nimh.nih.gov/nifti-1/data/minimal.nii.gz','minimal.nii.gz') +# ! gunzip ('minimal.nii.gz'); +# ! header=niftiinfo('minimal.nii'); +# ! assert (header.ImageSize,[64 64 10]); diff --git a/nii2jnii.m b/nii2jnii.m index 1fbc1bb..6d21f4e 100644 --- a/nii2jnii.m +++ b/nii2jnii.m @@ -1,74 +1,74 @@ function nii = nii2jnii(filename, format, varargin) -% -% nii=nii2jnii(niifile, format, options) -% or -% nii2jnii(niifile, jniifile, options) -% nii=nii2jnii(niifile) -% -% A fast and portable NIFTI-1/2 and Analyze7.5 file parser and converter -% to the text and binary JNIfTI formats defined in JNIfTI specification: -% https://github.com/fangq/jnifti -% -% This function is compatible with both MATLAB and GNU Octave. -% It accepts .nii, .nii.gz, .hdr/.img and .hdr.gz/.img.gz input files -% -% author: Qianqian Fang (q.fang neu.edu) -% -% input: -% fname: the file name to the .nii, .nii.gz, .hdr/.img or .hdr.gz/.img.gz file -% format:'nii' for reading the NIfTI-1/2/Analyze files; -% 'jnii' to convert the nii data into an in-memory JNIfTI structure. -% 'niiheader' return only the nii header without the image data -% -% if format is not listed above and nii2jnii is called without -% an output, format must be a string specifying the output JNIfTI -% file name - *.jnii for text-based JNIfTI, or *.bnii for the -% binary version -% options: (optional) if saving to a .bnii file, please see the options for -% savebj.m (part of JSONLab); if saving to .jnii, please see the -% supported options for savejson.m (part of JSONLab). -% -% output: -% if the output is a JNIfTI data structure, it has the following subfield: -% nii.NIFTIHeader - a structure containing the 1-to-1 mapped NIFTI-1/2 header -% nii.NIFTIData - the main image data array -% nii.NIFTIExtension - a cell array contaiing the extension data buffers -% -% when calling as nii=nii2jnii(file,'nii'), the output is a NIFTI object containing -% nii.img: the data volume read from the nii file -% nii.datatype: the data type of the voxel, in matlab data type string -% nii.datalen: data count per voxel - for example RGB data has 3x -% uint8 per voxel, so datatype='uint8', datalen=3 -% nii.voxelbyte: total number of bytes per voxel: for RGB data, -% voxelbyte=3; also voxelbyte=header.bitpix/8 -% nii.hdr: file header info, a structure has the full nii header -% key subfileds include -% -% sizeof_hdr: must be 348 (for NIFTI-1) or 540 (for NIFTI-2) -% dim: short array, dim(2: dim(1)+1) defines the array size -% datatype: the type of data stored in each voxel -% bitpix: total bits per voxel -% magic: must be 'ni1\0' or 'n+1\0' -% -% For the detailed nii header, please see -% https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h -% -% dependency: -% No external dependency if reading .nii/.hdr/.img files; -% -% To load gzipped input files (.nii.gz/.hdr.gz/.img.gz), one must -% install the ZMat Toolbox (http://github.com/fangq/zmat) and -% JSONLab Toolbox (http://github.com/fangq/jsonlab); -% -% To save files into the text/binary JNIfTI formatted files, one -% need to install JSONLab (http://github.com/fangq/jsonlab). -% -% this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m -% -% this file is part of JNIfTI specification: https://github.com/fangq/jnifti -% -% License: Apache 2.0, see https://github.com/fangq/jnifti for details -% +# +# nii=nii2jnii(niifile, format, options) +# or +# nii2jnii(niifile, jniifile, options) +# nii=nii2jnii(niifile) +# +# A fast and portable NIFTI-1/2 and Analyze7.5 file parser and converter +# to the text and binary JNIfTI formats defined in JNIfTI specification: +# https://github.com/fangq/jnifti +# +# This function is compatible with both MATLAB and GNU Octave. +# It accepts .nii, .nii.gz, .hdr/.img and .hdr.gz/.img.gz input files +# +# author: Qianqian Fang (q.fang neu.edu) +# +# input: +# fname: the file name to the .nii, .nii.gz, .hdr/.img or .hdr.gz/.img.gz file +# format:'nii' for reading the NIfTI-1/2/Analyze files; +# 'jnii' to convert the nii data into an in-memory JNIfTI structure. +# 'niiheader' return only the nii header without the image data +# +# if format is not listed above and nii2jnii is called without +# an output, format must be a string specifying the output JNIfTI +# file name - *.jnii for text-based JNIfTI, or *.bnii for the +# binary version +# options: (optional) if saving to a .bnii file, please see the options for +# savebj.m (part of JSONLab); if saving to .jnii, please see the +# supported options for savejson.m (part of JSONLab). +# +# output: +# if the output is a JNIfTI data structure, it has the following subfield: +# nii.NIFTIHeader - a structure containing the 1-to-1 mapped NIFTI-1/2 header +# nii.NIFTIData - the main image data array +# nii.NIFTIExtension - a cell array contaiing the extension data buffers +# +# when calling as nii=nii2jnii(file,'nii'), the output is a NIFTI object containing +# nii.img: the data volume read from the nii file +# nii.datatype: the data type of the voxel, in matlab data type string +# nii.datalen: data count per voxel - for example RGB data has 3x +# uint8 per voxel, so datatype='uint8', datalen=3 +# nii.voxelbyte: total number of bytes per voxel: for RGB data, +# voxelbyte=3; also voxelbyte=header.bitpix/8 +# nii.hdr: file header info, a structure has the full nii header +# key subfileds include +# +# sizeof_hdr: must be 348 (for NIFTI-1) or 540 (for NIFTI-2) +# dim: short array, dim(2: dim(1)+1) defines the array size +# datatype: the type of data stored in each voxel +# bitpix: total bits per voxel +# magic: must be 'ni1\0' or 'n+1\0' +# +# For the detailed nii header, please see +# https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h +# +# dependency: +# No external dependency if reading .nii/.hdr/.img files; +# +# To load gzipped input files (.nii.gz/.hdr.gz/.img.gz), one must +# install the ZMat Toolbox (http://github.com/fangq/zmat) and +# JSONLab Toolbox (http://github.com/fangq/jsonlab); +# +# To save files into the text/binary JNIfTI formatted files, one +# need to install JSONLab (http://github.com/fangq/jsonlab). +# +# this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m +# +# this file is part of JNIfTI specification: https://github.com/fangq/jnifti +# +# License: Apache 2.0, see https://github.com/fangq/jnifti for details +# hdrfile = filename; isnii = -1; @@ -126,7 +126,7 @@ nii.hdr.sizeof_hdr = swapbytes(nii.hdr.sizeof_hdr); end -if (nii.hdr.sizeof_hdr == 540) % NIFTI-2 format +if (nii.hdr.sizeof_hdr == 540) # NIFTI-2 format niftiheader = niiformat('nifti2'); if (exist('gzdata', 'var')) nii.hdr = memmapstream(gzdata, niftiheader); @@ -156,47 +156,47 @@ end type2byte = [ - 0 0 % unknown % - 1 0 % binary (1 bit/voxel) % - 2 1 % unsigned char (8 bits/voxel) % - 4 2 % signed short (16 bits/voxel) % - 8 4 % signed int (32 bits/voxel) % - 16 4 % float (32 bits/voxel) % - 32 8 % complex (64 bits/voxel) % - 64 8 % double (64 bits/voxel) % - 128 3 % RGB triple (24 bits/voxel) % - 255 0 % not very useful (?) % - 256 1 % signed char (8 bits) % - 512 2 % unsigned short (16 bits) % - 768 4 % unsigned int (32 bits) % - 1024 8 % long long (64 bits) % - 1280 8 % unsigned long long (64 bits) % - 1536 16 % long double (128 bits) % - 1792 16 % double pair (128 bits) % - 2048 32 % long double pair (256 bits) % - 2304 4 % 4 byte RGBA (32 bits/voxel) % + 0 0 # unknown # + 1 0 # binary (1 bit/voxel) # + 2 1 # unsigned char (8 bits/voxel) # + 4 2 # signed short (16 bits/voxel) # + 8 4 # signed int (32 bits/voxel) # + 16 4 # float (32 bits/voxel) # + 32 8 # complex (64 bits/voxel) # + 64 8 # double (64 bits/voxel) # + 128 3 # RGB triple (24 bits/voxel) # + 255 0 # not very useful (?) # + 256 1 # signed char (8 bits) # + 512 2 # unsigned short (16 bits) # + 768 4 # unsigned int (32 bits) # + 1024 8 # long long (64 bits) # + 1280 8 # unsigned long long (64 bits) # + 1536 16 # long double (128 bits) # + 1792 16 # double pair (128 bits) # + 2048 32 # long double pair (256 bits) # + 2304 4 # 4 byte RGBA (32 bits/voxel) # ]; type2str = { - 'uint8' 0 % unknown % - 'uint8' 0 % binary (1 bit/voxel) % - 'uint8' 1 % unsigned char (8 bits/voxel) % - 'uint16' 1 % signed short (16 bits/voxel) % - 'int32' 1 % signed int (32 bits/voxel) % - 'single' 1 % float (32 bits/voxel) % - 'single' 2 % complex (64 bits/voxel) % - 'double' 1 % double (64 bits/voxel) % - 'uint8' 3 % RGB triple (24 bits/voxel) % - 'uint8' 0 % not very useful (?) % - 'int8' 1 % signed char (8 bits) % - 'uint16' 1 % unsigned short (16 bits) % - 'uint32' 1 % unsigned int (32 bits) % - 'int64' 1 % long long (64 bits) % - 'uint64' 1 % unsigned long long (64 bits) % - 'uint8' 16 % long double (128 bits) % - 'uint8' 16 % double pair (128 bits) % - 'uint8' 32 % long double pair (256 bits) % - 'uint8' 4 % 4 byte RGBA (32 bits/voxel) % + 'uint8' 0 # unknown # + 'uint8' 0 # binary (1 bit/voxel) # + 'uint8' 1 # unsigned char (8 bits/voxel) # + 'uint16' 1 # signed short (16 bits/voxel) # + 'int32' 1 # signed int (32 bits/voxel) # + 'single' 1 # float (32 bits/voxel) # + 'single' 2 # complex (64 bits/voxel) # + 'double' 1 # double (64 bits/voxel) # + 'uint8' 3 # RGB triple (24 bits/voxel) # + 'uint8' 0 # not very useful (?) # + 'int8' 1 # signed char (8 bits) # + 'uint16' 1 # unsigned short (16 bits) # + 'uint32' 1 # unsigned int (32 bits) # + 'int64' 1 # long long (64 bits) # + 'uint64' 1 # unsigned long long (64 bits) # + 'uint8' 16 # long double (128 bits) # + 'uint8' 16 # double pair (128 bits) # + 'uint8' 32 # long double pair (256 bits) # + 'uint8' 4 # 4 byte RGBA (32 bits/voxel) # }; typeidx = find(type2byte(:, 1) == nii.hdr.datatype); diff --git a/niicodemap.m b/niicodemap.m index e93448b..a76d717 100644 --- a/niicodemap.m +++ b/niicodemap.m @@ -1,41 +1,41 @@ function newval = niicodemap(name, value) -% -% newval=niicodemap(name, value) -% -% Bi-directional conversion from NIFTI codes to human-readable JNIfTI -% header string values -% -% author: Qianqian Fang (q.fang neu.edu) -% -% input: -% name: a header name as a string, currently support the below nii -% headers: 'intent_code', 'slice_code', 'datatype', 'qform', -% 'sform' and 'xyzt_units' and their corresponding JNIfTI -% headers: -% 'Intent','SliceType','DataType','QForm','SForm','Unit' -% value:the current header value, if it is a code, newval will -% output the string version; if it is a string, newval will -% return the code -% -% output: -% newval: the converted header value -% -% For the detailed nii header codes, please see -% https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h -% -% example: -% newval=niicodemap('slice_code', '') -% newval=niicodemap('datatype', 'uint64') -% newval=niicodemap('datatype', 2) -% -% this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m -% -% this file is part of JNIfTI specification: https://github.com/fangq/jnifti -% -% License: Apache 2.0, see https://github.com/fangq/jnifti for details -% +# +# newval=niicodemap(name, value) +# +# Bi-directional conversion from NIFTI codes to human-readable JNIfTI +# header string values +# +# author: Qianqian Fang (q.fang neu.edu) +# +# input: +# name: a header name as a string, currently support the below nii +# headers: 'intent_code', 'slice_code', 'datatype', 'qform', +# 'sform' and 'xyzt_units' and their corresponding JNIfTI +# headers: +# 'Intent','SliceType','DataType','QForm','SForm','Unit' +# value:the current header value, if it is a code, newval will +# output the string version; if it is a string, newval will +# return the code +# +# output: +# newval: the converted header value +# +# For the detailed nii header codes, please see +# https://nifti.nimh.nih.gov/pub/dist/src/niftilib/nifti1.h +# +# example: +# newval=niicodemap('slice_code', '') +# newval=niicodemap('datatype', 'uint64') +# newval=niicodemap('datatype', 2) +# +# this file was initially developed for the MCX project: https://github.com/fangq/mcx/blob/master/utils/mcxloadnii.m +# +# this file is part of JNIfTI specification: https://github.com/fangq/jnifti +# +# License: Apache 2.0, see https://github.com/fangq/jnifti for details +# -% code to name look-up-table +# code to name look-up-table if (~exist('containers.Map')) newval = value; @@ -68,7 +68,7 @@ lut.slicetype = lut.slice_code; lut.intent = lut.intent_code; -% inverse look up table +# inverse look up table tul.intent_code = containers.Map(values(lut.intent_code), keys(lut.intent_code)); tul.slice_code = containers.Map(values(lut.slice_code), keys(lut.slice_code)); @@ -81,7 +81,7 @@ tul.intent = tul.intent_code; tul.unit = tul.xyzt_units; -% map from code to name, or frmo name to code +# map from code to name, or frmo name to code if (~isfield(lut, lower(name))) error('property can not be found'); diff --git a/niiformat.m b/niiformat.m index fd9ee3d..bb6927e 100644 --- a/niiformat.m +++ b/niiformat.m @@ -1,118 +1,118 @@ function niiheader = niiformat(format) -% -% niiheader=niiformat(format) -% -% Return a NIfTI header format descriptor as an Nx3 cell array -% -% author: Qianqian Fang (q.fang neu.edu) -% -% input: -% format:'nifti1' - return the header descriptor for NIfTI-1 format -% 'nifti2' - return the header descriptor for NIfTI-2 format -% -% output: -% niiheader: an Nx3 cell array in the format similar to the 'Format' -% specifier of the memmapfile.m function 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' -% column 2: an integer vector denoting the size of the data -% column 3: a string denoting the fieldname in the output struct -% -% this file is part of JNIfTI specification: https://github.com/fangq/jnifti -% -% License: Apache 2.0, see https://github.com/fangq/jnifti for details -% +# +# niiheader=niiformat(format) +# +# Return a NIfTI header format descriptor as an Nx3 cell array +# +# author: Qianqian Fang (q.fang neu.edu) +# +# input: +# format:'nifti1' - return the header descriptor for NIfTI-1 format +# 'nifti2' - return the header descriptor for NIfTI-2 format +# +# output: +# niiheader: an Nx3 cell array in the format similar to the 'Format' +# specifier of the memmapfile.m function 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' +# column 2: an integer vector denoting the size of the data +# column 3: a string denoting the fieldname in the output struct +# +# this file is part of JNIfTI specification: https://github.com/fangq/jnifti +# +# License: Apache 2.0, see https://github.com/fangq/jnifti for details +# header.nifti1 = { ... - 'int32' [1 1] 'sizeof_hdr' % !< MUST be 348 % % int sizeof_hdr; % ... - 'int8' [1 10] 'data_type' % !< ++UNUSED++ % % char data_type[10]; % ... - 'int8' [1 18] 'db_name' % !< ++UNUSED++ % % char db_name[18]; % ... - 'int32' [1 1] 'extents' % !< ++UNUSED++ % % int extents; % ... - 'int16' [1 1] 'session_error' % !< ++UNUSED++ % % short session_error; % ... - 'int8' [1 1] 'regular' % !< ++UNUSED++ % % char regular; % ... - 'int8' [1 1] 'dim_info' % !< MRI slice ordering. % % char hkey_un0; % ... - 'uint16' [1 8] 'dim' % !< Data array dimensions.% % short dim[8]; % ... - 'single' [1 1] 'intent_p1' % !< 1st intent parameter. % % short unused8/9; % ... - 'single' [1 1] 'intent_p2' % !< 2nd intent parameter. % % short unused10/11; % ... - 'single' [1 1] 'intent_p3' % !< 3rd intent parameter. % % short unused12/13; % ... - 'int16' [1 1] 'intent_code' % !< NIFTI_INTENT_* code. % % short unused14; % ... - 'int16' [1 1] 'datatype' % !< Defines data type! % % short datatype; % ... - 'int16' [1 1] 'bitpix' % !< Number bits/voxel. % % short bitpix; % ... - 'int16' [1 1] 'slice_start' % !< First slice index. % % short dim_un0; % ... - 'single' [1 8] 'pixdim' % !< Grid spacings. % % float pixdim[8]; % ... - 'single' [1 1] 'vox_offset' % !< Offset into .nii file % % float vox_offset; % ... - 'single' [1 1] 'scl_slope' % !< Data scaling: slope. % % float funused1; % ... - 'single' [1 1] 'scl_inter' % !< Data scaling: offset. % % float funused2; % ... - 'int16' [1 1] 'slice_end' % !< Last slice index. % % float funused3; % ... - 'int8' [1 1] 'slice_code' % !< Slice timing order. % ... - 'int8' [1 1] 'xyzt_units' % !< Units of pixdim[1..4] % ... - 'single' [1 1] 'cal_max' % !< Max display intensity % % float cal_max; % ... - 'single' [1 1] 'cal_min' % !< Min display intensity % % float cal_min; % ... - 'single' [1 1] 'slice_duration' % !< Time for 1 slice. % % float compressed; % ... - 'single' [1 1] 'toffset' % !< Time axis shift. % % float verified; % ... - 'int32' [1 1] 'glmax' % !< ++UNUSED++ % % int glmax; % ... - 'int32' [1 1] 'glmin' % !< ++UNUSED++ % % int glmin; % ... - 'int8' [1 80] 'descrip' % !< any text you like. % % char descrip[80]; % ... - 'int8' [1 24] 'aux_file' % !< auxiliary filename. % % char aux_file[24]; % ... - 'int16' [1 1] 'qform_code' % !< NIFTI_XFORM_* code. % %-- all ANALYZE 7.5 --- % ... - 'int16' [1 1] 'sform_code' % !< NIFTI_XFORM_* code. % %below here are replaced% ... - 'single' [1 1] 'quatern_b' % !< Quaternion b param. % ... - 'single' [1 1] 'quatern_c' % !< Quaternion c param. % ... - 'single' [1 1] 'quatern_d' % !< Quaternion d param. % ... - 'single' [1 1] 'qoffset_x' % !< Quaternion x shift. % ... - 'single' [1 1] 'qoffset_y' % !< Quaternion y shift. % ... - 'single' [1 1] 'qoffset_z' % !< Quaternion z shift. % ... - 'single' [1 4] 'srow_x' % !< 1st row affine transform. % ... - 'single' [1 4] 'srow_y' % !< 2nd row affine transform. % ... - 'single' [1 4] 'srow_z' % !< 3rd row affine transform. % ... - 'int8' [1 16] 'intent_name' % !< 'name' or meaning of data. % ... - 'int8' [1 4] 'magic' % !< MUST be "ni1\0" or "n+1\0". % ... - 'int8' [1 4] 'extension' % !< header extension % ... + 'int32' [1 1] 'sizeof_hdr' # !< MUST be 348 # # int sizeof_hdr; # ... + 'int8' [1 10] 'data_type' # !< ++UNUSED++ # # char data_type[10]; # ... + 'int8' [1 18] 'db_name' # !< ++UNUSED++ # # char db_name[18]; # ... + 'int32' [1 1] 'extents' # !< ++UNUSED++ # # int extents; # ... + 'int16' [1 1] 'session_error' # !< ++UNUSED++ # # short session_error; # ... + 'int8' [1 1] 'regular' # !< ++UNUSED++ # # char regular; # ... + 'int8' [1 1] 'dim_info' # !< MRI slice ordering. # # char hkey_un0; # ... + 'uint16' [1 8] 'dim' # !< Data array dimensions.# # short dim[8]; # ... + 'single' [1 1] 'intent_p1' # !< 1st intent parameter. # # short unused8/9; # ... + 'single' [1 1] 'intent_p2' # !< 2nd intent parameter. # # short unused10/11; # ... + 'single' [1 1] 'intent_p3' # !< 3rd intent parameter. # # short unused12/13; # ... + 'int16' [1 1] 'intent_code' # !< NIFTI_INTENT_* code. # # short unused14; # ... + 'int16' [1 1] 'datatype' # !< Defines data type! # # short datatype; # ... + 'int16' [1 1] 'bitpix' # !< Number bits/voxel. # # short bitpix; # ... + 'int16' [1 1] 'slice_start' # !< First slice index. # # short dim_un0; # ... + 'single' [1 8] 'pixdim' # !< Grid spacings. # # float pixdim[8]; # ... + 'single' [1 1] 'vox_offset' # !< Offset into .nii file # # float vox_offset; # ... + 'single' [1 1] 'scl_slope' # !< Data scaling: slope. # # float funused1; # ... + 'single' [1 1] 'scl_inter' # !< Data scaling: offset. # # float funused2; # ... + 'int16' [1 1] 'slice_end' # !< Last slice index. # # float funused3; # ... + 'int8' [1 1] 'slice_code' # !< Slice timing order. # ... + 'int8' [1 1] 'xyzt_units' # !< Units of pixdim[1..4] # ... + 'single' [1 1] 'cal_max' # !< Max display intensity # # float cal_max; # ... + 'single' [1 1] 'cal_min' # !< Min display intensity # # float cal_min; # ... + 'single' [1 1] 'slice_duration' # !< Time for 1 slice. # # float compressed; # ... + 'single' [1 1] 'toffset' # !< Time axis shift. # # float verified; # ... + 'int32' [1 1] 'glmax' # !< ++UNUSED++ # # int glmax; # ... + 'int32' [1 1] 'glmin' # !< ++UNUSED++ # # int glmin; # ... + 'int8' [1 80] 'descrip' # !< any text you like. # # char descrip[80]; # ... + 'int8' [1 24] 'aux_file' # !< auxiliary filename. # # char aux_file[24]; # ... + 'int16' [1 1] 'qform_code' # !< NIFTI_XFORM_* code. # #-- all ANALYZE 7.5 --- # ... + 'int16' [1 1] 'sform_code' # !< NIFTI_XFORM_* code. # #below here are replaced# ... + 'single' [1 1] 'quatern_b' # !< Quaternion b param. # ... + 'single' [1 1] 'quatern_c' # !< Quaternion c param. # ... + 'single' [1 1] 'quatern_d' # !< Quaternion d param. # ... + 'single' [1 1] 'qoffset_x' # !< Quaternion x shift. # ... + 'single' [1 1] 'qoffset_y' # !< Quaternion y shift. # ... + 'single' [1 1] 'qoffset_z' # !< Quaternion z shift. # ... + 'single' [1 4] 'srow_x' # !< 1st row affine transform. # ... + 'single' [1 4] 'srow_y' # !< 2nd row affine transform. # ... + 'single' [1 4] 'srow_z' # !< 3rd row affine transform. # ... + 'int8' [1 16] 'intent_name' # !< 'name' or meaning of data. # ... + 'int8' [1 4] 'magic' # !< MUST be "ni1\0" or "n+1\0". # ... + 'int8' [1 4] 'extension' # !< header extension # ... }; header.nifti2 = { ... - 'int32' [1 1] 'sizeof_hdr' % !< MUST be 540 % % int sizeof_hdr; % ... - 'int8' [1 8] 'magic' % !< MUST be "ni2\0" or "n+2\0". % ... - 'int16' [1 1] 'datatype' % !< Defines data type! % % short datatype; % ... - 'int16' [1 1] 'bitpix' % !< Number bits/voxel. % % short bitpix; % ... - 'int64' [1 8] 'dim' % !< Data array dimensions.% % short dim[8]; % ... - 'double' [1 1] 'intent_p1' % !< 1st intent parameter. % % short unused8/9; % ... - 'double' [1 1] 'intent_p2' % !< 2nd intent parameter. % % short unused10/11; % ... - 'double' [1 1] 'intent_p3' % !< 3rd intent parameter. % % short unused12/13; % ... - 'double' [1 8] 'pixdim' % !< Grid spacings. % % float pixdim[8]; % ... - 'int64' [1 1] 'vox_offset' % !< Offset into .nii file % % float vox_offset; % ... - 'double' [1 1] 'scl_slope' % !< Data scaling: slope. % % float funused1; % ... - 'double' [1 1] 'scl_inter' % !< Data scaling: offset. % % float funused2; % ... - 'double' [1 1] 'cal_max' % !< Max display intensity % % float cal_max; % ... - 'double' [1 1] 'cal_min' % !< Min display intensity % % float cal_min; % ... - 'double' [1 1] 'slice_duration' % !< Time for 1 slice. % % float compressed; % ... - 'double' [1 1] 'toffset' % !< Time axis shift. % % float verified; % ... - 'int64' [1 1] 'slice_start' % !< First slice index. % % short dim_un0; % ... - 'int64' [1 1] 'slice_end' % !< Last slice index. % % float funused3; % ... - 'int8' [1 80] 'descrip' % !< any text you like. % % char descrip[80]; % ... - 'int8' [1 24] 'aux_file' % !< auxiliary filename. % % char aux_file[24]; % ... - 'int32' [1 1] 'qform_code' % !< NIFTI_XFORM_* code. % %-- all ANALYZE 7.5 --- % ... - 'int32' [1 1] 'sform_code' % !< NIFTI_XFORM_* code. % %below here are replaced% ... - 'double' [1 1] 'quatern_b' % !< Quaternion b param. % ... - 'double' [1 1] 'quatern_c' % !< Quaternion c param. % ... - 'double' [1 1] 'quatern_d' % !< Quaternion d param. % ... - 'double' [1 1] 'qoffset_x' % !< Quaternion x shift. % ... - 'double' [1 1] 'qoffset_y' % !< Quaternion y shift. % ... - 'double' [1 1] 'qoffset_z' % !< Quaternion z shift. % ... - 'double' [1 4] 'srow_x' % !< 1st row affine transform. % ... - 'double' [1 4] 'srow_y' % !< 2nd row affine transform. % ... - 'double' [1 4] 'srow_z' % !< 3rd row affine transform. % ... - 'int32' [1 1] 'slice_code' % !< Slice timing order. % ... - 'int32' [1 1] 'xyzt_units' % !< Units of pixdim[1..4] % ... - 'int32' [1 1] 'intent_code' % !< NIFTI_INTENT_* code. % % short unused14; % ... - 'int8' [1 16] 'intent_name' % !< 'name' or meaning of data. % ... - 'int8' [1 1] 'dim_info' % !< MRI slice ordering. % % char hkey_un0; % ... - 'int8' [1 15] 'reserved' % !< unused buffer % ... - 'int8' [1 4] 'extension' % !< header extension % ... + 'int32' [1 1] 'sizeof_hdr' # !< MUST be 540 # # int sizeof_hdr; # ... + 'int8' [1 8] 'magic' # !< MUST be "ni2\0" or "n+2\0". # ... + 'int16' [1 1] 'datatype' # !< Defines data type! # # short datatype; # ... + 'int16' [1 1] 'bitpix' # !< Number bits/voxel. # # short bitpix; # ... + 'int64' [1 8] 'dim' # !< Data array dimensions.# # short dim[8]; # ... + 'double' [1 1] 'intent_p1' # !< 1st intent parameter. # # short unused8/9; # ... + 'double' [1 1] 'intent_p2' # !< 2nd intent parameter. # # short unused10/11; # ... + 'double' [1 1] 'intent_p3' # !< 3rd intent parameter. # # short unused12/13; # ... + 'double' [1 8] 'pixdim' # !< Grid spacings. # # float pixdim[8]; # ... + 'int64' [1 1] 'vox_offset' # !< Offset into .nii file # # float vox_offset; # ... + 'double' [1 1] 'scl_slope' # !< Data scaling: slope. # # float funused1; # ... + 'double' [1 1] 'scl_inter' # !< Data scaling: offset. # # float funused2; # ... + 'double' [1 1] 'cal_max' # !< Max display intensity # # float cal_max; # ... + 'double' [1 1] 'cal_min' # !< Min display intensity # # float cal_min; # ... + 'double' [1 1] 'slice_duration' # !< Time for 1 slice. # # float compressed; # ... + 'double' [1 1] 'toffset' # !< Time axis shift. # # float verified; # ... + 'int64' [1 1] 'slice_start' # !< First slice index. # # short dim_un0; # ... + 'int64' [1 1] 'slice_end' # !< Last slice index. # # float funused3; # ... + 'int8' [1 80] 'descrip' # !< any text you like. # # char descrip[80]; # ... + 'int8' [1 24] 'aux_file' # !< auxiliary filename. # # char aux_file[24]; # ... + 'int32' [1 1] 'qform_code' # !< NIFTI_XFORM_* code. # #-- all ANALYZE 7.5 --- # ... + 'int32' [1 1] 'sform_code' # !< NIFTI_XFORM_* code. # #below here are replaced# ... + 'double' [1 1] 'quatern_b' # !< Quaternion b param. # ... + 'double' [1 1] 'quatern_c' # !< Quaternion c param. # ... + 'double' [1 1] 'quatern_d' # !< Quaternion d param. # ... + 'double' [1 1] 'qoffset_x' # !< Quaternion x shift. # ... + 'double' [1 1] 'qoffset_y' # !< Quaternion y shift. # ... + 'double' [1 1] 'qoffset_z' # !< Quaternion z shift. # ... + 'double' [1 4] 'srow_x' # !< 1st row affine transform. # ... + 'double' [1 4] 'srow_y' # !< 2nd row affine transform. # ... + 'double' [1 4] 'srow_z' # !< 3rd row affine transform. # ... + 'int32' [1 1] 'slice_code' # !< Slice timing order. # ... + 'int32' [1 1] 'xyzt_units' # !< Units of pixdim[1..4] # ... + 'int32' [1 1] 'intent_code' # !< NIFTI_INTENT_* code. # # short unused14; # ... + 'int8' [1 16] 'intent_name' # !< 'name' or meaning of data. # ... + 'int8' [1 1] 'dim_info' # !< MRI slice ordering. # # char hkey_un0; # ... + 'int8' [1 15] 'reserved' # !< unused buffer # ... + 'int8' [1 4] 'extension' # !< header extension # ... }; if (nargin < 1) diff --git a/savenifti.m b/savenifti.m index 7a62f65..d2c5ed2 100644 --- a/savenifti.m +++ b/savenifti.m @@ -1,38 +1,38 @@ function bytestream = savenifti(img, filename, varargin) -% -% savenifti(img, filename) -% or -% savenifti(img, filename, rawhdr) -% savenifti(img, filename, 'nifti2') -% bytestream=savenifti(img) -% -% Write an image to a NIfTI (*.nii) or compressed NIfTI file (.nii.gz) -% -% author: Qianqian Fang (q.fang neu.edu) -% -% input: -% img: this is a numerical array to be stored in the NIfTI file -% filename: output file name, can have a suffix of '.nii' or '.nii.gz' -% if a .gz suffix is used, this function needs the JSONLab -% (http://gitlab.com/fangq/jsonlab) and ZMat (http://gitlab.com/fangq/zmat) -% to perform the compression. -% rawhdr (optional): a struct, as a pre-created/loaded NIfTI header data structure -% if rawhdr is 'nifti1' or 'nifti2', this function calls -% nifticreate to create a default header. -% output: -% bytestream (optional): the output file byte stream. it only returns this output if -% no filename is given. -% -% example: -% a=single(rand(10,20,30)); -% savenifti(a,'randnii.nii'); -% savenifti(a,'randnii2.nii.gz','nifti2'); % needs zmat -% -% -% this file is part of JNIfTI specification: https://github.com/fangq/jnifti -% -% License: Apache 2.0, see https://github.com/fangq/jnifti for details -% +# +# savenifti(img, filename) +# or +# savenifti(img, filename, rawhdr) +# savenifti(img, filename, 'nifti2') +# bytestream=savenifti(img) +# +# Write an image to a NIfTI (*.nii) or compressed NIfTI file (.nii.gz) +# +# author: Qianqian Fang (q.fang neu.edu) +# +# input: +# img: this is a numerical array to be stored in the NIfTI file +# filename: output file name, can have a suffix of '.nii' or '.nii.gz' +# if a .gz suffix is used, this function needs the JSONLab +# (http://gitlab.com/fangq/jsonlab) and ZMat (http://gitlab.com/fangq/zmat) +# to perform the compression. +# rawhdr (optional): a struct, as a pre-created/loaded NIfTI header data structure +# if rawhdr is 'nifti1' or 'nifti2', this function calls +# nifticreate to create a default header. +# output: +# bytestream (optional): the output file byte stream. it only returns this output if +# no filename is given. +# +# example: +# a=single(rand(10,20,30)); +# savenifti(a,'randnii.nii'); +# savenifti(a,'randnii2.nii.gz','nifti2'); # needs zmat +# +# +# 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 (~isempty(varargin)) if (isstruct(varargin{1}))