|14 Feb 2014||Tools for NIfTI and ANALYZE image Load, save, make, reslice, view (and edit) both NIfTI and ANALYZE data on any platform||Jimmy Shen||
you can't do it. check faq.pdf when you need load_untouch_nii or load_nii
|12 Feb 2014||Tools for NIfTI and ANALYZE image Load, save, make, reslice, view (and edit) both NIfTI and ANALYZE data on any platform||Jimmy Shen||
because it's not the business of view_nii to interpret and apply header info.
|31 Dec 2013||Tools for NIfTI and ANALYZE image Load, save, make, reslice, view (and edit) both NIfTI and ANALYZE data on any platform||Jimmy Shen||
Nicolas, please tell me what is the exact "clues" or "messages" that confuse you. In addition, please tell me what you try to do.
|19 Nov 2013||Jimmy Shen||
You can use "load_untouch_nii / save_untouch_nii" pair. Here's an example:
nii = load_untouch_nii('avg152T1_LR_nifti.nii');
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?
|11 Nov 2013||Resampling volume or image with affine matrix Use affine matrix to convert 3D vol or 2D img to orthogonal one with corresponding affine matrix.||Jimmy Shen||
The output volume is determined by the original volume, the affine matrix, and the new voxel_size that you choose. If any of the above inputs change, the output will also change. Otherwise, the output should be consistent.
The difference in dimension between output volume and original one is obvious. Just think about a unit square in 2D plane with dimension of [1 1]. If you rotate it 45 degree, you have to use a dimension of [1.414 1.414] to hold the same square. However, the distance from origin to edges are still 1.
In order to properly crop the transformed volume, you need to keep in mind that we are focusing on the unit of distance from the originator based on the affine matrix (e.g. millimeter), and don't worry about voxel size or its dimension. Since I have not used it for registration, I don't have detail procedure for you.
|08 Nov 2013||Resampling volume or image with affine matrix Use affine matrix to convert 3D vol or 2D img to orthogonal one with corresponding affine matrix.||Jimmy Shen||
The new_img is interpolated from the old_img. Therefore, there is no exact mapping between old point and new point. I agree with your thoughts. However, keep in mind that we are talking about voxels (little cubic, with voxel_size) rather than points (with no size). Otherwise, you don't need this program, and a plot3 is enough to do affine transformation for points.
|30 Aug 2013||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
No, it is not a typo.
"bit_depth" value -16 & -32 were designed to expand datatype to "16-bit unsigned integer" & "32-bit signed integer".
If "bit_depth" is -8, it will be treated as 8 anyway, since only abstract value is considered. However, if it is 1 or -1, according to TIFF Revision 6.0 (Final-June 3, 1992), "SampleFormat" field has to be set to "undefined data format", since it is binary monochrome data.
If you look further down a little bit to line 932, you will find how I write data strip based on "bit_depth" value.
|07 Aug 2013||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
Please check: http://research.baycrest.org/~jimmy/geotiffwrite
You need to add:
option.ColorMap [Nx3 array]
Where N = 2^bit_depth, and bit_depth can only be 8 or 16. Values in option.ColorMap range from 0 to 65535, and value 0 in image points to the first row in the ColorMap. Columns in option.ColorMap are [R G B]. Black is represented by [0 0 0], and white is represented by [65535 65535 65535].
|05 Jul 2013||Jimmy Shen||
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.
|14 May 2013||Jimmy Shen||
"collapse_nii_scan" is used to integrate multiple single-volume NIfTI or ANALYZE files into one multiple-volume NIfTI file. In your case, if you want to concatenate two 4D NIfTI images into one 4D NIfTI images, you should apply "expand_nii_scan" to your both 4D images. All volumes must be in the same folder, and make sure the file name is correctly renamed (i.e. from 001~999 instead of 1~999). Then, apply "collapse_nii_scan" to all those expanded volumes in the specific folder, and you will get a concatenated 4D NIfTI image file.
|14 Sep 2012||Jimmy Shen||
"collapse_nii_scan.m" will do the job.
This tool can not be used to extract spinal cord. However, once you extracted it and saved into another Analyze/NIfTI file, this tool can load the data into MATLAB for further processing.
|11 Jul 2012||Jimmy Shen||
Received the image, and it is a special RGB data type one. The nii.img ranges from 0 to 1 as usual, but the output value needs to be scaled by (glmax-glmin)+glmin.
|10 Jul 2012||Jimmy Shen||
Would you please send me this image, so I can take a look into it for you tomorrow afternoon.
|30 Apr 2012||Jimmy Shen||
Sure Mark. You need a reference image by the way, so you can see what will happen before and after you apply the transformation matrix. Here's the example:
1. Download "avg152T1_RL_nifti.nii" from NIfTI site. I use it as reference image.
2. View how the reference image looks like: nii=load_nii('avg152T1_RL_nifti.nii');
3. Assume that I have a Transformation Matrix, which will let the reference image turn 30 degree counter-clockwise on XY plane, here will be the matrix: T=[cos(pi/6) -sin(pi/6) 0; sin(pi/6) cos(pi/6) 0; 0 0 1];
4. Get old_xyz from reference image: rl=load_untouch_nii('avg152T1_RL_nifti.nii');
5. Apply your transformation matrix, and save new_xyz into a new image: new_xyz=T*old_xyz; rl.hdr.hist.srow_x(1:3)=new_xyz(1,:); rl.hdr.hist.srow_y(1:3)=new_xyz(2,:); rl.hdr.hist.srow_z(1:3)=new_xyz(3,:); save_untouch_nii(rl, 'rl30.nii'); Now you already have the "rl30.nii", which is a transformed NIfTI image can be used anywhere.
6. In order to view this image using my toolbox, you need to reslice it: reslice_nii('rl30.nii', 'rl30b.nii'); Now, you can load and view the rotated image: rl30b=load_nii('rl30b.nii'); view_nii(rl30b);
Hopefully this answers your questions.
|26 Apr 2012||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
You need to use MATLAB's geotiffread to read L7 file into matrix, with all attributes. Then find out the index of your sub-region, and assign the sub-region to a new matrix. You can now use the make_option option in my package to select optional fields. However, you need to match the attributes that you read, and select the correct fields by yourself in order to create the optional fields to be used in my geotiffwrite. Since I don't have Mapping toolbox, I am afraid that I cannot provide you with more details.
|26 Apr 2012||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
My geotiffwrite can only write a rectangular dataset into the file. As long as your sub-region is a rectangular dataset, you should be able to write it into a separate file.
|19 Apr 2012||Jimmy Shen||
To reply your first comment: The problem is that you mixed "make_nii" with "_untouch_" version. If you use "make_nii" to get NIfTI structure, it has to be saved using "save_nii".
To reply your second comment: If you know NIfTI structure well, sure you can modify it and then use "save_nii" to save it. You can even save "non-orthogonal" NIfTI structure to the file with "save_nii".
The reason that I interpret the header with "load_nii" and limit it to "orthogonal" transformation is all about convenience, at least for my work.
BTW, if you take the original NIfTI file, and bring it to other software to display (e.g. SPM), they will also reslice it for you.
Thank you very much for your rating!
|28 Mar 2012||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
MATLAB finally has its own "geotiffwrite" function. So I suggest you use its geotiffread / geotiffwrite pair to load your Antarctica background, and superimpose your ship track data on top, and then re-write the entire data into GeoTIFF format using Matlab's geotiffwrite function.
I am currently no longer working in GeoScience field, so I am afraid that I cannot provide you with more useful advise.
|01 Mar 2012||Jimmy Shen||
Got your data, and did the following test using "analyze75read" "load_untouch_nii" and "load_nii", here the results:
You told me that you got a voxel value of 1.089e+12 using "analyze75read". I cannot duplicate your result.
|29 Feb 2012||Jimmy Shen||
Without more detail, I cannot duplicate your problem. Please send me your data that indicates it. On the other hand, I wish you could take a look at my web page to better understand this tool. In order to display, you must use "load_nii" instead of "load_untouch_nii". i.e. your data is interpreted properly (touched). There could be many cases, e.g. scale factor is specified in the header file, your data has different orientation, etc. However, in no situation it treats double datatype differently.
|16 Feb 2012||Resampling volume or image with affine matrix Use affine matrix to convert 3D vol or 2D img to orthogonal one with corresponding affine matrix.||Jimmy Shen||
I think you mean that the dimension of the output matrix is different from the input matrix, which is correct.
Think about you have a cubic, and you rotate it 45 degree along Z axis. If we the element size the same, the dimension of X & Y should be at least sqrt(2) larger than the original X & Y dimension, since the new X & Y dimension is equal to the old diagonal.
In addition, there will be some extra elements in the new corner, which will be assigned a value of [bg], which is 0 by default.
Please let me know if you still have difficulty to understand this.
|17 Jan 2012||Jimmy Shen||
I never have such a function called "read_nii_img". Please read all functions and usages from:
|19 Dec 2011||Jimmy Shen||
It seems that "load_nii_hdr" in "apply_fsl_transformation_matrix" has been modified. It should look like this "function [hdr, filetype, fileprefix, machine] = load_nii_hdr(fileprefix)". i.e. It should have 4 output arguments, which is exactly the same amount as "load_untouch_nii" asked for.
|16 Dec 2011||Jimmy Shen||
NIfTI supports both ".nii" and ".img/.hdr" file extension. If you do not provide any file extension, it will look for ".img/.hdr" files by default. Therefore, you can easily solve your problem by provide appropriate file extension. e.g. nii = load_nii('filtered_func_data.nii');
|22 Nov 2011||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
Please notice that the values in colormap range from 0 to 65535 (instead of from 0 to 1). So black is represented by [0 0 0], and white is represented by [65535 65535 65535]. If you put [1 1 1], it will be black. Please see more details from my web site: http://www.rotman-baycrest.on.ca/~jimmy/geotiffwrite
|20 Oct 2011||Jimmy Shen||
I assume that you have a series of 3D NIfTI (or Analyze) files with the same header information (i.e. same dimension, voxel size, originator, ... etc.), and you want to integrate it into a single 4D file with time series in the file.
If this is the case, you can use my "collapse_nii_scan.m" to do so. Type help collapse_nii_scan to get more information.
For file extension, this function will follow whatever you have. i.e. you will still get a single .hdr/.img file afterwards.
Since all NIfTI compatible software should be able to load a 4D NIfTI (or Analyze) file, we do not support any conversion from .hdr/img to .nii file.
|31 Aug 2011||Jimmy Shen||
You are not supposed to use "load_nii_hdr.m" & "load_nii_img.m". Both are internal functions, and are not supported when you call them directly.
If you want to take look at the header information, please use "load_untouch_header_only.m".
If you would like to change the voxel value, please use "load_nii.m" to load the NIfTI file, and then use "view_nii.m" to edit voxel value at crosshair (under "Edit" tab), and then click "Save displayed image" under "File" tab.
The reason of inconsistency in your case is caused by the scaling factor in the header that was not properly interpreted by yourself.
|30 Aug 2011||Jimmy Shen||
This is because those parameters & scaling have been interpreted & applied to the image. It is what NIfTI loader supposed to do.
If you want to interpret header by yourself, feel free to try the following commands:
x = load_untouch_nii('b0.hdr');
For more details, please carefully read all the instructions through, which can be found on my web page:
|30 Jul 2011||Jimmy Shen||
First, when you use 'save_nii.m', the file that you saved will always be in NIfTI instead of Analyze format.
Second, use 'load_untouch_nii' to load both original Analyze file and saved NIfTI file, and check what is the dimension size and data type of '.img' field.
Finally, I have tested to use 'load_nii.m' to load many Analyze and NIfTI files and then use 'save_nii.m' to save into NIfTI files. I did not find data size "increase remarkably". If it is possible, please upload your original Analyze data to somewhere that I can access, and email me the link (DO NOT USE EMAIL ATTACHMENT), so I can try to duplicate your problem.
By the way, I will not be available until Aug 2.
|05 Jul 2011||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
If Model Type is "projected", you cannot use "bbox" variable directly, and you have to use "make_option.m" program to generate "option" variable.
|28 Jun 2011||Jimmy Shen||
First, both "load_nii" & "load_untouch_nii" support SPM NIfTI images. As a matter of fact, there is only one NIfTI standard, all NIfTI compatible software should comply with that standard.
Second, in order to duplicate the error, please upload that image onto anywhere that I can have read access. PLEASE DO NOT SEND BY EMAIL ATTACHMENT.
As you have noticed, NIfTI images can be in any spatial orientation, while "load_nii" can only have 48 orthogonal orientations. In that case, the program will prompt you to use "reslice_nii" to interpolate the image. Since you did not get the appropriate prompt, I am interested to take a look at the image that you are loading.
Please check my NIfTI web page for more details:
|20 May 2011||Jimmy Shen||
Have you read:
As you can see, "origin" in NIfTI is expressed in sform or qform. When you use "load_nii", you should find it under: hdr.hist.originator(1:3)
Sometimes, with old ANALYZE image, the value is [0 0 0] which does not make sense, then you have no choice but use: hdr.dime.dim(2:4)/2.
Hope this helps.
|20 May 2011||Jimmy Shen||
The start positions for x, y, z are all 1. i.e. XYZvoxal=[1 1 1] is the place to start.
Please also check NIfTI header fields at:
and let me know whether I understand your question correctly.
|13 Apr 2011||Jimmy Shen||
Here's an example:
|23 Feb 2011||Load BIOPAC ACQ (AcqKnowledge for PC) data Load BIOPAC's *.acq file (AcqKnowledge for Windows data format).||Jimmy Shen||
Thijs, thanks to the open Python source code provided by Nathan Vack, this program can now load both ACQ4.0 and ACQ4.1. However, there is no documentation about ACQ 4 data format from BIOPAC.
|14 Feb 2011||Load BIOPAC ACQ (AcqKnowledge for PC) data Load BIOPAC's *.acq file (AcqKnowledge for Windows data format).||Jimmy Shen||
The latest release of file format by BIOPAC is up to AcqKnowledge 3.9:
|22 Nov 2010||Load BIOPAC ACQ (AcqKnowledge for PC) data Load BIOPAC's *.acq file (AcqKnowledge for Windows data format).||Jimmy Shen||
There are 4 places that are using 'dec2hex' command. They are: dec2hex(hdr.color_major_grid), dec2hex(hdr.color_minor_grid), dec2hex(hdr.rgb_color), dec2hex(hdr.active_seg_color).
Those values in ACQ file header are not supposed to be negative.
Since none of those values will affect the channel data, you can replace them with ' ' if you believe your ACQ data have no other problem.
|13 Sep 2010||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
SRTM (Shuttle Radar Topography Mission) data are nothing but Big-Endian, 16-bit Signed Integer binary numbers with either in 1201x1201 (SRTM3) or in 3601x3601 (SRTM1) dimension. You can simply use the following script to do the job:
Please let me know if you encounter any problem.
|17 Aug 2010||geotiffwrite Write a 2D or 3D array to a single or multi-band GeoTIFF file||Jimmy Shen||
Thanks for you comments and rating.
Yes, you can use some of the fields contents returned by geotiffinfo to provide information for my option struct when you run the "make_option.m" program. However, please be careful, since my struct fields are DIRECTLY correspond to GeoTIFF Format Specification (like IDL software does); while struct fields from geotiffinfo in MATLAB software are NOT DIRECTLY correspond to GeoTIFF Format Specification. Here's a simple example: you can use geotiffinfo.TiePoints.WorldPoints for TiepointXYZ; but you cannot use geotiffinfo.TiePoints.ImagePoints for TiepointIJK.
I have just submitted 1-bit GeoTIFF support, so please come back in 2~3 days to see if they make my program available for you.
|03 Aug 2010||Jimmy Shen||
You may not notice the tolerance argument in "load_nii". By default, we allow no more than 10% of distortion. You can set it to 0, you will be prompted to use "reslice_nii" to interpolate the image.
If you just want to change negative value and NAN value to 0, you can simply use "load_untouch_nii" and "save_untouch_nii" pair to do the job.
|17 Jun 2010||Jimmy Shen||
First, you don't have to use "make_nii", which just creates a NIfTI struct for you based on your N-D matrix.
Second, make_nii supports float data. Type help make_nii for more details. Did you receive any error message?
|15 Jun 2010||Jimmy Shen||
You can check "Question about overlay" category under:
You said that you have the x,y and z directions of each voxel. The x,y and z directions must be converted into the index regarding to the first voxel. Probably, you already have the brain region that represents the eigen image. Let's assume that you have it in a binary image called "brain_mask.nii", while the anatomical image is called "ana.nii". Here's what you can try:
1. Use "ana = load_nii(ana.nii)" to load the anatomical image, and make sure that variable "ana.img" is either in "single" or "double". If not, use step 2 to convert it.
2. To convert variable "ana.img" to "single", you need to use "make_nii" command: "ana = make_nii(single(ana.img), ana.hdr.dime.pixdim(2:4), ana.hdr.hist.originator(1:3))".
3. Use "mask = load_nii(brain_mask.nii)" to load the brain
4. Add other values to "opt" struct: "opt.command = 'init'; opt.useinterp = 0;".
5. Plot eigen image with underlaid background by command: "view_nii(ana, opt);".
6. Don't click "interp on/off" menu. It doesn't work properly. If you would like to see the interpolated one, use: "opt.useinterp = 1; view_nii(ana, opt);" instead.
If you still have question, please feel free to ask me.
|04 Jun 2010||Jimmy Shen||
1) That's right, it does not support .avw format. So please save it in .hdr/.img or .nii format before you open them in MATLAB.
2) 300 slices should be okay on many new computers. If your computer cannot hold this much data in its memory, you may want to take 1 or several slices at a time to analyze. This feature was implemented on Jan. 6, 2010.
|14 Apr 2010||Jimmy Shen||
Theoretically, the changes that you suggested will increase the speed. However, it doesn't seem to speed up, after I tried several datasets.
Anyway, thank you very much for the feedback, and I will make the change in the next version.
|26 Jan 2010||Jimmy Shen||
Don't worry. The following tips will give you some more help.
If you did not see difference after using "expend_nii_scan', it means that you only have 1 scan (1 volume) in your file. Since you said "...look at the nifti images separatley...", I thought you have several images (volumes or scans) in 1 file, and would like to treat them separately.
The first step you need to do is to load your image into MATLAB by "load_nii" command (Please look at "help load_nii" before using it).
Let's say you have an image "file1.nii" (or "file1.img/hdr"). By command:
You mentioned that you would like to change the image into another datatype. Here's how:
You can either change the header information directly (if you are familiar with the NIfTI header) then use "save_nii", or to use "make_nii" to create a new NIfTI structure (like nii).
If you have a MATLAB algorithm that you made by yourself as you mentioned, I think you will be more interested in the img matrix ("nii.img"). The "nii.hdr" is the header information to describe how "nii.img" is oriented, what is the voxel size, and originator, and many more.
Finally, I have to correct you that "make_nii" will not convert image to any extension. It only makes a NIfTI structure from N-D matrix and some other parameters (voxel size, originator, data type, etc.). Please double check the help, and make sure that you know how to use it.
If you have further question, please be more specific (e.g. make a point list), so I know how to help you.
|25 Jan 2010||Jimmy Shen||
No questions are stupid.
Yes. You can use my tool to look at NIfTI images separately and also convert them to another datatype.
Since NIfTI supports both img/hdr and nii extensions, so my tool supports any of them.
Most help can be obtained by using help command. e.g. help make_nii.
There are several other resources that you can get help:
Command "expand_nii_scan" is used to break a multiple-scan NIfTI file into multiple single-scan NIfTI files, so you can look at them separately.
If you want to convert img data type, you can use "save_nii" after use "make_nii" command. If you are familiar with NIfTI structure, you can modify "hdr.dime" directly, and then use "save_nii" to save.
If you have further question, please make it more specific, so I can help you.
|06 Jan 2010||Jimmy Shen||
I just got chance to look into this issue.
Since it is too complicated to modify "load_nii.m" to load specific slices of NIfTI and Analyze formats, I modified "load_untouch_nii.m" only. That means, you will take care of image orientation based on its header information, because "load_untouch_nii.m" does not apply any changes to the IMG matrix that is indicated in the HDR.
I hope this could still somehow help you to load large dataset.
|10 Nov 2009||Jimmy Shen||
First, I am wondering how you could simply rename an .img file to a .nii file. NIfTI supports both extensions, but for .img extension, you need to save the header separately in .hdr file. So there is no way for people to just "... rename the .img file to .nii file ..." like you said.
Second, I looked into Francesca's data, and the size of the image data does not match the size that is indicated in the header. For such a file, I cannot image any software can process it.
I am glad to take a look at your samples. Would you please upload them onto your server, and post the link here?
|09 Nov 2009||Jimmy Shen||
Thanks for the rate.
When you use "load_untouch_nii.m", it just load the img and hdr, but does not apply any changes (e.g. scl_slope, affine matrix, etc) indicated in the header. Therefore, I always suggest people to use "load_nii.m" in most cases. Please check the description of "load_untouch_nii.m" & "load_nii.m" on http://www.rotman-baycrest.on.ca/~jimmy/NIfTI.
You are right, the unexpected value was caused by the "scl_slope" parameter, which is properly applied when you use "load_nii.m". However, I am not sure whether you have noticed that this is a radiological image, i.e. Right on LHS and Left on RHS. Here, L/RHS means Left/RightHandSide.
When you use "load_nii.m", it will do all the proper flipping and rotation according to the affine matrix in the header, and the img will always be in RAS orientation (i.e. x: L->R, y: P->A, z: I->S). In your particular case, instead of use [32 32 23], you should use [33 32 23], since x axis is flipped, i.e. new_x = max_x(64) - old_x(32) + 1 = 33.
Other software may choose to do so with proper labeling around Axial / Sagittal / Coronal view, e.g. FSL does so.
Please feel free to let me know if you have further question.
|06 Nov 2009||Jimmy Shen||
First, thank you very much for the rating, and I really appreciate it.
It seems that "lCC_19850624TRTN_2x2x2_b1000_a_fa.nii'" is corrupted. Have you tried to open it successfully under MRIcro? If so, please upload this file and let me take a look at it?
In addition, from the error message that you posted, it seems that you are using a very old version of my tools. I noticed this by the line number showing the error. However, I still believe that the error is caused by the corrupted image.
Please let me know,