如何使用numpy python读取多个3D图像并将它们存储在4D数组中?

问题描述 投票:0回答:1

我使用下面的代码为 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
python numpy machine-learning keras
1个回答
0
投票

您可以尝试在 NumPy 中进行转置,请检查此 https://numpy.org/doc/stable/reference/ generated/numpy.transpose.html

© www.soinside.com 2019 - 2024. All rights reserved.