You can use "load_untouch_nii / save_untouch_nii" pair. Here's an example:
nii = load_untouch_nii('avg152T1_LR_nifti.nii');
nii.hdr.hist.descrip = 'Mengye';
Unless you touch nii.img by yourself, e.g. nii.img(1)=0, it will not be changed, although it is also loaded and saved. Only the header (nii.hdr) is edited in the way you make the change.
In addition, if the input file is in Analyze 7.5 format, the output will be kept in Analyze 7.5 format. If the input is in NIfTI format, the output will be kept in NIfTI format.
That is why I have "load_untouch_" as well as "load_" feature. However, in most case, you want to use "load_" feature, since you don't want to interpret affine matrix in the header, and make all sorts of flipping and rotation by yourself, do you?
Are there ways to load, edit and save .hdr without doing things to .img? Because I found SPM changed my source files headers every time doing co-registration, and I want to change it back. It seems save_nii_hdr() is an internal function and I tried using it but broke my nifti files.
Great Submission! However, I also can't get the SiemensInfo to work. This creates problems when trying to write the Dicom files. Has anyone figured out how to fix this yet? I get errors:
Attempted to access name(0); index must be a positive integer or logical.
Error in SiemensInfo (line 21)
while(name(end)==' '); name=name(1:end-1); end
Working pretty well, so far. Thanks.
I was a bit tripped up at the beginning on the difference between dicom_folder_info and dicom_read_header, since both functions can accept a folder name as input. It could be worthwhile adding a word of emphasis in the documentation about the differences between the two...