本文主要是介绍numpy转nii,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
import nibabel as nib
import numpy as np
import matplotlib.pyplot as plt
from tensorflow.keras.layers import (Convolution3DTranspose)if __name__ == '__main__':# 读取niinii_path = "D:/新建文件夹/Segmentation.nii"func = nib.load(nii_path) # 为了得到affine信息img = func.get_fdata()# 转成numpy数组img = np.array(img)print(img.shape)plt.imshow(img[:,:,0])plt.show()# 对图像做一些操作img[:,:,0]=np.zeros(img[:,:,0].shape)plt.imshow(img[:,:,0])plt.show()# 再转回niinew_image = nib.Nifti1Image(img,func.affine)nib.save(new_image,'out.nii')
这篇关于numpy转nii的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!