%step 1: get the names of the files
files=dir('*.png');
file_names={files.name}';
%step 2: sort the files
%extract the numbers
%Here, the format of the name shoul be enterd and %d should replate the
%number, this is so that the files will be load in the right order
filenum = cellfun(@(x)sscanf(x,'%d.png'), file_names);
% sort them, and get the sorting order
[~,Sidx] = sort(filenum) ;
% use to this sorting order to sort the filenames
SortedFilenames = file_names(Sidx);
%step 3: combine images to single matrix:
%get number of files
num_of_files=numel(SortedFilenames);
for i=1:num_of_files
nifti_mat(:,:,i)=imread(SortedFilenames{i});
end
%step 4: conver to nifti and save:
filename='here_goes_the_name_of_the_file';
niftiwrite(nifti_mat,filename);
希望这有帮助
严格的回答是不,你做不到。因为png文件不包含NIfTI文件所需的信息。在
但是,如果不关心坐标和左右信息是否正确,则可能生成一个假的nii文件。您可以使用
for
循环读取png文件(我想它们具有相同的维度):可以使用MatlabNIfTI tool创建nii文件:
^{pr2}$相关问题 更多 >
编程相关推荐