欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

png转nii

时间:2023-05-19

import SimpleITK as sitkimport globimport numpy as npfrom PIL import Imageimport cv2def save_array_as_nii_volume(data, filename, reference_name=None): img = sitk.GetImageFromArray(data) if (reference_name is not None): img_ref = sitk.ReadImage(reference_name) img.CopyInformation(img_ref) sitk.WriteImage(img, filename)image_path = './1/DICOM_anon/Ground/Liver'image_arr = glob.glob(str(image_path) + str("/*"))image_arr.sort()print(image_arr)# print(image_arr[0].shape)print(len(image_arr))allImg = []allImg = np.zeros([len(image_arr), 256, 256], dtype='uint8')for i in range(len(image_arr)): single_image_name = image_arr[i] img_as_img = Image.open(single_image_name) # img_as_img.show() img_as_np = np.asarray(img_as_img) img_as_np.squeeze(2) allImg[i, :, :] = img_as_np# np.transpose(allImg,[2,0,1])save_array_as_nii_volume(allImg, './S1/1.nii')print(np.shape(allImg))img = allImg[:, :, 55]

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。