Skip to content

Commit

Permalink
nf: some small updates to transmit scl_slope and scl_inter, also allo…
Browse files Browse the repository at this point in the history
…w for int8 as datatype (freesurfer#840)
  • Loading branch information
schoffelen authored Dec 22, 2020
1 parent a50502f commit d9ed621
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions matlab/MRIwrite.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
if(~isfield(mri,'volres'))
mri.volres = sqrt(sum(mri.vox2ras0(1:3,1:3).^2));
end
if(~isfield(mri,'scl_slope')) mri.scl_slope = 0; end
if(~isfield(mri,'scl_inter')) mri.scl_inter = 0; end

[fspec fstem fmt] = MRIfspec(fstring,0); % 0 = turn off checkdisk
if(isempty(fspec))
Expand Down Expand Up @@ -137,6 +139,7 @@
case 'int', hdr.datatype = 8; hdr.bitpix = 8*4;
case 'float', hdr.datatype = 16; hdr.bitpix = 8*4;
case 'double', hdr.datatype = 64; hdr.bitpix = 8*8;
case 'char', hdr.datatype = 256; hdr.bitpix = 8*1;
case 'ushort', hdr.datatype = 512; hdr.bitpix = 8*2;
case 'uint', hdr.datatype = 768; hdr.bitpix = 8*4;
otherwise,
Expand All @@ -149,8 +152,8 @@
hdr.pixdim = [0 mri.volres([2 1 3]) mri.tr]; % physical units
%hdr.pixdim = [0 mri.volres mri.tr]; % physical units
hdr.vox_offset = 348; % will be set again
hdr.scl_slope = 0;
hdr.scl_inter = 0;
hdr.scl_slope = mri.scl_slope;
hdr.scl_inter = mri.scl_inter;

hdr.slice_end = 0;

Expand Down
1 change: 1 addition & 0 deletions matlab/load_nifti.m
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
case 8, dtype = 'int' ;
case 16, dtype = 'float' ;
case 64, dtype = 'double' ;
case 256, dtype = 'int8' ;
case 512, dtype = 'ushort' ;
case 768, dtype = 'uint' ;
otherwise
Expand Down
1 change: 1 addition & 0 deletions matlab/save_nifti.m
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@
case 8, nitemswritten = fwrite(fp,hdr.vol,'int');
case 16, nitemswritten = fwrite(fp,hdr.vol,'float');
case 64, nitemswritten = fwrite(fp,hdr.vol,'double');
case 256, nitemswritten = fwrite(fp,hdr.vol,'int8');
case 512, nitemswritten = fwrite(fp,hdr.vol,'ushort');
case 768, nitemswritten = fwrite(fp,hdr.vol,'uint');
otherwise,
Expand Down

0 comments on commit d9ed621

Please sign in to comment.