0

**请记住,只需修改引用的常量,就可以重用此代码为去颅骨和非去颅骨数据创建数据库。 def slices_matrix_2D(img): *''' 将 3D MRI 图像转换为 2D 图像,方法是获取 9 个切片并将它们放置在 4x4 二维网格中。

      All 16 cuts are from a horizontal/axial view. They are selected
      from the 30th to the 60th level of the original 3D image.*
      
      Parameters:
        img -- np.ndarray with the 3D image
        
      Returns:
        np.ndarray -- The resulting 2D image
  '''
  
  # create the final 2D image 
  image_2D = np.empty(IMG_2D_SHAPE)
  
  # set the limits and the step
  TOP = 60
  BOTTOM = 30
  STEP = 2
  N_CUTS = 16
  
  # iterator for the cuts
  cut_it = TOP
  # iterator for the rows of the 2D final image
  row_it = 0
  # iterator for the columns of the 2D final image
  col_it = 0
  
  for cutting_time in range(N_CUTS):
    
    # cut
    cut = img[cut_it, :, :]
    cut_it -= STEP
    
    # reset the row iterator and move the
    # col iterator when needed
    if cutting_time in [4, 8, 12]:
          row_it = 0
          col_it += cut.shape[1]

        # copy the cut to the 2D image
        for i in range(cut.shape[0]):
          for j in range(cut.shape[1]):
            image_2D[i + row_it, j + col_it] = cut[i, j]  (it gives the error here)
        row_it += cut.shape[0]

      # return the final 2D image, with 3 channels
      # this is necessary for working with most pre-trained nets
      return np.repeat(image_2D[None, ...], 3, axis=0).T
      #return image_2D

它在 ----> 1 create_tf_record_2D(training_set, train_tfrec2D, LABELS) 2 create_tf_record_2D(test_set, test_tfrec2D, LABELS) 3 create_tf_record_2D(validation_set, val_tfrec2D, LABELS) 中给出类似 IndexError Traceback (last recent call last)的错误

<ipython-input-145-a58a668df074> in create_tf_record_2D(img_filenames, tf_rec_filename, labels)
     19 
     20     # load the image and label
---> 21     img, label = load_image_2D(meta_data, labels)
     22 
     23     # create a feature

<ipython-input-143-8a6e1c4008a3> in load_image_2D(abs_path, labels)
     27 
     28   # make the 2D image
---> 29   img = slices_matrix_2D(img)
     30 
     31   return img, label

<ipython-input-142-9f2419afd597> in slices_matrix_2D(img)
     44     for i in range(cut.shape[0]):
     45       for j in range(cut.shape[1]):
---> 46         image_2D[i + row_it, j + col_it] = cut[i, j]
     47     row_it += cut.shape[0]
     48 

**IndexError: index 440 is out of bounds for axis 0 with size 440****
4

0 回答 0