将一个Nifti标题复制到另一个

问题描述 投票:0回答:1

我在matlab(概率图)中有一个'prob_map'变量,我希望以'.nii'格式保存它。我用2行代码做到了:

 nii = make_nii(prob_map); 
 save_nii(nii,'prob.nii');

这已成功完成,但标题信息与我原来的名为'img.nii'的CT图像不兼容(因此在ITK-SNAP软件中,无法在图像上覆盖prob_map)。我想在保存之前将img.nii的标题复制到'prob.nii'标题。事实上,只要有可能,我想复制一个标题。例如,可以复制方向和其他信息时无法复制标题大小。在保存nii之前是否有任何功能可以将一个标题复制到另一个?必须复制哪些信息以保持两个nii相同?

matlab header nifti
1个回答
1
投票

你可以尝试使用spm matlab library

# Grab header from an existing file (and optionally, get the data)
HeaderInfo  = spm_vol('img.nii')          # use spm_vol to read file header
NiftiData   = spm_read_vol(HeaderInfo)    # use spm_read_vol to get data

# Update the header contents to correspond with your new data
HeaderInfo.fname = 'prob.nii';
HeaderInfo.private.dat.fname = HeaderInfo.fname;

# Save the file with the adapted Header
spm_write_vol(HeaderInfo,Data);           # where Data is your image array
© www.soinside.com 2019 - 2024. All rights reserved.