Python 将.png文件转换为.nii(NiFti文件)
我目前在一个项目中工作,该项目处理Python 将.png文件转换为.nii(NiFti文件),python,matlab,conv-neural-network,file-format,Python,Matlab,Conv Neural Network,File Format,我目前在一个项目中工作,该项目处理神经图像中的.nii文件。我将该文件转换为80个.png文件。现在我需要再次将这80个.png文件合并到.nii文件中 请帮忙 谢谢 严格的回答是不,你不能这么做。因为png文件不包含NIfTI文件所需的信息 但是,如果您不关心坐标和左右信息是否正确,您可能会生成一个假的nii文件。您可以使用for循环读取png文件(我想它们具有相同的维度): for i = 1:numberOfPNG_file img(:,:,i) = imread(png_File
神经图像
中的.nii
文件。我将该文件转换为80个.png
文件。现在我需要再次将这80个.png
文件合并到.nii
文件中
请帮忙
谢谢 严格的回答是不,你不能这么做。因为png文件不包含NIfTI文件所需的信息 但是,如果您不关心坐标和左右信息是否正确,您可能会生成一个假的nii文件。您可以使用
for
循环读取png文件(我想它们具有相同的维度):
for i = 1:numberOfPNG_file
img(:,:,i) = imread(png_Files{i});
end
您可以使用Matlab创建nii文件:
nii = nii_tool('init', img);
nii_tool('save', nii, 'my_nii.nii');
希望这有帮助
%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);
请使用必要的标签。并分享一些关于如何将.nii文件转换为.png文件的代码。另外,请清楚您使用的是python还是matlab??我在matlab中将.nii文件转换为80.png文件。但是我需要一种在python或Matlab中合并它们的方法,这是从nii到2d。我需要将这些转换后的2d文件合并回niiYou可以从显示将.nii文件转换为.png文件的代码片段开始。