[英]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.