Skip to content

Commit

Permalink
Adjust default nifti header creation regarding ‘pixdim’ field, respon…
Browse files Browse the repository at this point in the history
…sible for shifting xform origin coords

new default behavior: grab 'pixdim' from original nifti header if it exists OR, fallback: set default pixdim field to [... 3 1 1 1] (previously [... 0 0 0 0])
  • Loading branch information
austinchkuo committed Feb 16, 2023
1 parent 6d14e7f commit eecfb1b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions mrUtilities/File/mlrImage/mlrImageGetNiftiHeader.m
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
hdr.dim = hdr.dim(:);
hdr.dim = hdr.dim(1:8);
hdr.pixdim = [h.nDim h.pixdim];
hdr.pixdim(end+1:8) = 0;
hdr.pixdim(end+1) = 3; % specify ndims of origin
hdr.pixdim(end+1:8) = 1; % specify origin; nifti headers seem to default to [1 1 1]
hdr.pixdim = hdr.pixdim(:);
hdr.pixdim = hdr.pixdim(1:8);

Expand Down Expand Up @@ -70,11 +71,10 @@
% seem a bit strange (why recreate the nifti header if
% it already exists as a field) but this is done so that
% we can get a clean header
fieldsToCopyFromOriginalNiftiHeader = {'datatype','endian','bitpix','vox_offset','xyzt_units'};
fieldsToCopyFromOriginalNiftiHeader = {'datatype','endian','bitpix','vox_offset','xyzt_units','pixdim'};
for iField = 1:length(fieldsToCopyFromOriginalNiftiHeader)
if isfield(h.hdr,fieldsToCopyFromOriginalNiftiHeader{iField})
hdr.(fieldsToCopyFromOriginalNiftiHeader{iField}) = h.hdr.(fieldsToCopyFromOriginalNiftiHeader{iField});
end
end
end

end

0 comments on commit eecfb1b

Please sign in to comment.