在MATLAB中处理多个nii格式的医学图像文件

Processing multiple medical image files in nii format in MATLAB

我正在尝试处理一个文件夹中的多个图像。 .nii 格式的医学图像大约有 200 张。

 %% setting up the folder
fileFolder = fullfile(pwd ,'\project\data_1');
files = dir(fullfile(fileFolder ,'*.nii'));
fileNames ={files.name};
%%sample 
img =load_untouch_nii('1.nii');
im =img.img;
classJ =class(im);

%%reading the files
I =load_untouch_nii(fullfile(fileFolder,fileNames{1}));
classI =class(I);
sizeI =size(I);
numImages =length(fileNames);

%% Read slices
hwaitbar =waitbar(0,'Reading nii files');

%%Read

for i =length(fileNames):-1:1
    fname =fullfile(fileFolder, fileNames{i});
    x(i) = load_untouch_nii(fname);
    y =x(i).img;
    figure; imshow(y(:,:,70),[]); %viewing the image to the check code
    **My Transformation function**
    waitbar((length(fileNames)-i+1)/length(fileNames));
end
delete(hwaitbar);

img = load_untouch_nii('xyz.nii')

加载 struct{} 中的图像,其中包含 headers、图像和一些其他信息。然后 img.img 提取 256*256*150 uint16 格式的图像。我的问题是转换功能完成后如何将这些图像保存在单独的文件夹中?

由于您似乎拥有 "NIFTI and ANALYZE tools",您可以使用以下方法保存 nifti 文件:

   nii = make_nii(y, {additional arguments, check help make_nii});
   save_nii(nii, 'myfilename.nii')