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.
Data for "plot" only contain the coordinates information, while data for "make_nii" need intensity value which is assumed to be distributed on a grid with its coordinates from 1 to the dimention of the grid. In addition, unlike plot, coordinates for images contain only the integer. Therefore, you cannot directly extract the data from a plot and make it to an image.
Export your plot data to an image would be an easy alternative. I think you already did good. All you have to do is to hide the background image and the axes before you export the plot to an image. Here's how to do so:
1. Before export, use mouse click your plot (make it active);
2. Hide the axes by running:
3. Hide the background image by running:
h = get(gca,'child');
4. Export the plot to an image. Now it does not have the background and axes.
Thank you very much for this useful product. I do have a question, if anyone could help me out...
I loaded a .nii file, did some processing and have a new plot that I would like to extract data from and ultimately save as .nii. It is a simple plot that was a result of finding the boundaries of an object. I extracted the data from the plot and entered it into a cell, but the "make_nii" function does not support this datatype. I tried converting the cell to a .mat, but that did not produce a satisfactory result either. I also tried saving the plot as an image and then using "make_nii," which worked, but the result included the border and axes of the image. I want only the data, without the background or axes. Does anyone have any suggestions?