– Function details can be found here:
http://www.mathworks.com/matlabcentral/fileexchange/8797-tools-for-nifti-and-analyze-image
– Some questions:
Question for image editing
I would like to modify the value of the masks I have created for my ROIs. I have downloaded your package, and successfully load et view one of my NIfTI file, but I don’t know how to change the value of the mask (e.g. from 1 to 2). (22-June-2011, Extracted from Adeline at Laboratoire d’Imagerie Fonctionnelle, France)
Answer
There are two ways to edit voxel value.
1. Using “view_nii.m” program:
You can use “view_nii.m” as an individual program. Navigate to the voxel that you want to change its value, and the crosshair will be moved to that voxel. Click “Edit” menu and then choose “Edit voxel value at crosshair”, the current voxel value will be displayed. Type the new number within the data type range. The data type can be obtained by click “Image Information” under “View” menu. For example, for 8-bit unsigned integer, its data type range is [0 255]. Now, you can see that the voxel gray level is changed. Finally, click “Save displayed image as” under “File” menu, you can have the modified image saved in NIfTI format.
2. Using command line:
Sometimes, you may want to change a lot of voxels to the same value. In this case, it’s better to do it in command line. First, load the original image: nii = load_nii(‘old_image.nii’); Then: nii.img(find(nii.img == old_value)) = new_value will change all old_value to new_value. Finally, save_nii(nii, ‘new_image.nii’) will save the modified image into ‘new_image.nii’.
For your particular case, I suggest you use command line to do so.
– Examples to load, make and save a nii struct:
To load Analyze data or NIFTI data to a structure:
nii = load_nii(NIFTI_file_name, [img_idx], [old_RGB24]);
img_idx is a numerical array of image indices along the temporal axis, which is only available in NIFTI data. After you specify img_idx, only those images indexed by img_idx will be loaded. If there is no img_idx or img_idx is empty, all available images will be loaded.
For RGB image, most people use RGB triple sequentially for each voxel, like [R1 G1 B1 R2 G2 B2 …]. However, some program like Analyze 6.0 developed by AnalyzeDirect uses old RGB24, in a way like [R1 R2 … G1 G2 … B1 B2 …] for each slices. In this case, you can set old_RGB24 flag to 1 and load data correctly:
nii = load_nii(NIFTI_file_name, [], 1);
To get a total number of images along the temporal axis:
num_scan = get_nii_frame(NIFTI_file_name);
You can also load the header extension if it exists:
nii.ext = load_nii_ext(NIFTI_file_name);
You can just load the Analyze or NIFTI header:
(header contains: hk, dime, and hist)
hdr = load_nii_hdr(NIFTI_file_name);
You can also save the structure to a new file: (header extension will be saved if there is nii.ext structure)
save_nii(nii, NIFTI_file_name);
To make the structure from any 3D (or 4D) data:
img = rand(91,109,91); or
img = rand(64,64,21,18);
nii = make_nii(img [, voxel_size, origin, datatype] );
Use “help load_nii”, “help save_nii”, “help make_nii” etc. to get more detail information.
– Examples to plot a nii struct:
(More detail descriptions are available on top of “view_nii.m”)
Simple way to plot a nii struct:
view_nii(nii);
The default colormap will use the Gray if all data values are non-negative; otherwise, the default colormap will use BiPolar. You can choose other colormap, including customized colormap from panel.
To imbed the plot into your existing figure:
h = gcf;
opt.command = ‘init’;
opt.setarea = [0.3 0.1 0.6 0.8];
view_nii(h, nii, opt);
To add a colorbar:
opt.usecolorbar = 1;
view_nii(gcf, opt);
Here, opt.command is implicitly set to ‘update’.
To display in real aspect ratio:
opt.usestretch = 0;
view_nii(gcf, opt);
If you want the data value to be directly used as the index of colormap, instead of scale to the whole colormap:
opt.useimagesc = 0;
view_nii(gcf, opt);
If you modified the data value without changing the dimension, voxel_size, and origin, you can update the display by:
opt.command = ‘updateimg’;
view_nii(gcf, nii.img, opt);
If the data is completely different, display can be updated by:
opt.command = ‘updatenii’;
view_nii(gcf, nii, opt);
This is an example to plot EEG source imaging on top of T1 background:
1. download overlay.zip and unzip it from: http://www.rotman-baycrest.on.ca/~jimmy/NIFTI/overlay.zip
2. T1 = load_nii(‘T1.nii’);
3. EEG = load_nii(‘EEG.nii’);
4. option.setvalue.idx = find(EEG.img);
5. option.setvalue.val = EEG.img(option.setvalue.idx);
6. option.useinterp = 1;
7. option.setviewpoint = [62 48 46];
8. view_nii(T1, option);
– Contrast and Brightness are available under Gray and Bipolar colormap:
Increase contrast in Gray colormap will make high end values more distinguishable by sacrificing the low end values; The minimum contrast (default) will display the whole range.
Increase or decrease contrast in BiPolar colormap will shift the distinguishable position for both positive and negative values.
Increase or decrease brightness in Gray colormap will shift the distinguishable position.
Increase or decrease brightness in BiPolar colormap will make both positive and negative values more distinguishable.
– Required files:
All files in this package.
Great article, I enjoyed reading it.
Very interesting points you have mentioned , thanks for putting up.
Thanks for the something totally new you have revealed in your writing. One thing I
By far the most concise and up to date information I have found on this topic. I am glad that I navigated to your page. I have to say. Actually not often do I encounter a blog that
Great writing. I enjoyed reading this. If you want, check out my website.
Please tell me that youre going to maintain this up! Its so very good and so essential. I cant wait to read much more from you. I just feel like you know so considerably and know the way to make men and women listen to what you’ve got to say. This blog is just too cool to be missed. Fantastic stuff, really. Please, PLEASE keep it up!
Thank you for every other informative web site. Where else may just I am getting that type of info written in such a perfect means? I have a mission that I’m just now working on, and I’ve been at the glance out for such information.
Wonderful post, I will bookmark Tools for NIfTI and ANALYZE image in MATLAB examples | Li, B's Blog.
Tools for NIfTI and ANALYZE image in MATLAB examples | Li, B's Blog is a remarkable share. Thanks for this article.