import matplotlib.pyplot as pyplot
import numpy as np
n = 1
for i in range (30):
img_path = './321/2/%d.npy' % n
image = np.load(img_path)
n = n+1
pyplot.imshow(image[0, :, :], cmap=pyplot.cm.bone)
pyplot.show()
import matplotlib.pyplot as pyplot
import SimpleITK as sitk
import numpy as np
n = 1
for i in range (30):
img_path = './321/2/%d.dcm' % n
im_A = sitk.ReadImage(img_path)
im_A_npy = np.array(sitk.GetArrayFromImage(im_A))
np.save('./321/3/%d.npy' % n, im_A_npy)
n = n+1
pyplot.imshow(im_A_npy[0, :, :], cmap=pyplot.cm.bone)
pyplot.show()
读取.mat
import scipy.io as scio
import numpy as np #导入矩阵处理库
from PIL import Image
import SimpleITK as sitk
import matplotlib.pyplot as pyplot
def nii_maskto2D():
image_train = []
data = scio.loadmat('./ktrans_pj_5-P015216.mat')
image_array = np.array(data['x'])
image_array = np.flip(image_array, axis=2)
print(len(image_array.shape))
print(image_array.shape)
w,h,c = image_array.shape
total_slices = c # 总切片数
slice_counter = 0 # 从第几个切片开始
n = 0
# iterate through slices
for current_slice in range(slice_counter, total_slices):
# alternate slices
if (slice_counter % 1) == 0:
data = image_array[:, :, current_slice] # 保存该切片,可以选择不同方向。
data = np.fliplr(data)
# data = np.rot90(data)
pyplot.imshow(data, cmap=pyplot.cm.bone)
pyplot.show()
image_train.append(data)
np.save('./321/%d.npy' % int(n+1), image_train[n:n+1])
n = n + 1
print('Finished converting images')
print(nii_maskto2D())
版权声明:本文为qq_60742456原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。