[英]Copy one Nifti header to another
我在matlab中有一個“ prob_map”變量(一個概率圖),我想將其保存為“ .nii”格式。 我用兩行代碼做到了:
nii = make_nii(prob_map);
save_nii(nii,'prob.nii');
此操作已成功完成,但是標頭信息與我的原始CT圖像“ img.nii”不兼容(因此,在ITK-SNAP軟件中無法將prob_map覆蓋在圖像上)。 我想在保存之前將img.nii的頭復制到'prob.nii'頭。 實際上,我想盡可能復制一個人的標題。 例如,不能復制標題大小,而可以復制方向和其他信息。 有什么功能可以在保存nii之前將其標頭復制到另一個標頭? 必須復制哪些信息才能使兩個nii保持相同?
您可以嘗試使用spm matlab庫
# 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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.