[英]How to read multiple 3d images and store them in 4D array using numpy python?
我已经使用下面的代码为 3 张图像创建了一个形状为 (2, 3, 365, 256, 256) (2, 365, 256, 256) 的数组,但是我需要我的形状为 (2,365, 256, 256 , 3) (2, 365, 256, 256) 让我的模型运行,请问有什么提示吗?
def Load_function(path):
f_img= nib.load(path )
img_data= f_img.get_fdata()
return img_data
def __load__(self, id_name):
image_path = os.path.join(self.path, id_name)
## Reading Image
image = np.empty((0,365, 256, 256))
for imname in ["image2B.nii.gz", "image1to2_nlB.nii.gz", "diffFSL.nii.gz"]:
img = Load_function(os.path.join(image_path,imname))
img = resize_data(img)
## Normalizaing
img = img/np.percentile(img,99.5)
#images.append(img)
#images.append(img)
## store into a 4D array that you’ve created above (this will hold all the images you want for one subject)
image = np.append(img[np.newaxis, ...],image, axis=0) # add a new axis to each image and append them to result
## Reading Masks
mask = Load_function(os.path.join(image_path, "ground_truth.nii.gz"))
mask = resize_data(mask)
return image, mask
您可以尝试在 NumPy 中进行转置,检查此https://numpy.org/doc/stable/reference/generated/numpy.transpose.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.