Search code examples
matlabmedical

Processing multiple medical image files in nii format in MATLAB


i am trying to process multiple images from a folder. There are around 200 medical images in .nii format.

 %% 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);

The

img = load_untouch_nii('xyz.nii')

load the images in struct{} which contain headers , images and some other information. then img.img extract the image which is 256*256*150 uint16 format. My question is once the transformation function is done how can i save those images in separate folder?


Solution

  • As you seem to have the "NIFTI and ANALYZE tools", you can save a nifti file using:

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