1

I have used the code below to create an array with the shape of (2, 3, 365, 256, 256) (2, 365, 256, 256) for 3 images however I need my shape to be (2,365, 256, 256, 3) (2, 365, 256, 256) for my model to run, any tips please?

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
Michael Szczesny
  • 4,911
  • 5
  • 15
  • 32

1 Answers1

0

You can try the transpose in NumPy, check this https://numpy.org/doc/stable/reference/generated/numpy.transpose.html

Rime
  • 83
  • 8