Matlab R2016a software reads, displays and saves nii images

Recently, when I was doing medical image processing, I encountered reading, displaying, and saving .nii images through software. I checked a lot of information on the Internet, and I felt very vague. I finally found a solution. Therefore, it is organized here to facilitate learning again.

The first step is to download the Tools for NIfTI (ANALYZE) MR image toolkit

Insert picture description here

After the download is complete, unzip the file and place it in the toolbox of the Matlab R2016a installation path.
Insert picture description here
Insert picture description here

The second step is to load the toolkit path in MATLAB.

In the "Home" panel, select the "Set Path" option;
Insert picture description here
add in the "Set Path" pageNIfTI_20140122path of. Add a folder and save.
Insert picture description here

The third step is to create a new .m file, read, display and save the image

In Matlab R2016a, read the .nii image.

cd(‘nii所在文件夹’)
%nii = load_nii( filedir )
nii = load_nii('***.nii')
img = nii.img;

.nii image ( AD_015.nii )
extraction code: 4mv2
data source: ADNI|MRI analysis

%读取nii图像
clc
clear
cd('C:\Users\Administrator\Documents\MATLAB\dcu\AD_nii')
nii = load_nii('AD_015.nii')

In the command line window, you can see the specific information of the .nii image.
Insert picture description here

view_nii (nii);% display nii image

%读取nii图像
clc
clear
cd('C:\Users\Administrator\Documents\MATLAB\dcu\AD_nii')
nii = load_nii('AD_015.nii')
%显示nii图像
view_nii (nii);

show result
Insert picture description here

Save nii image
nii = make_nii( img );
save_nii (nii, dstdir );

%读取nii图像
clc
clear
cd('C:\Users\Administrator\Documents\MATLAB\dcu\AD_nii')
nii = load_nii('AD_015.nii')
img = nii.img;
%显示nii图像
view_nii (nii);
%保存为01.nii
nii = make_nii( img );
save_nii (nii,'01.nii');  %保存为01.nii

Refer to
1. Matlab 2018b to view nii images
2. Matlab nii file reading
3. Matlab to achieve NIfTI (ANALYZE) NMR image reading and writing

Guess you like

Origin blog.csdn.net/weixin_45656790/article/details/108981640