Python 这是正确的乳房整形吗?

Python 这是正确的乳房整形吗?,python,numpy,Python,Numpy,我刚开始学习Python和Numpy 我发现了这段代码: def preprocessing(FLAIR_array, T1_array): brain_mask = np.ndarray(np.shape(FLAIR_array), dtype=np.float32) brain_mask[FLAIR_array >=thresh] = 1 brain_mask[FLAIR_array < thresh] = 0 for iii in range(

我刚开始学习Python和Numpy

我发现了这段代码:

def preprocessing(FLAIR_array, T1_array):

    brain_mask = np.ndarray(np.shape(FLAIR_array), dtype=np.float32)
    brain_mask[FLAIR_array >=thresh] = 1
    brain_mask[FLAIR_array < thresh] = 0
    for iii in range(np.shape(FLAIR_array)[0]):
        brain_mask[iii,:,:] = scipy.ndimage.morphology.binary_fill_holes(brain_mask[iii,:,:])  #fill the holes inside brain

    FLAIR_array -=np.mean(FLAIR_array[brain_mask == 1])      #Gaussion Normalization
    FLAIR_array /=np.std(FLAIR_array[brain_mask == 1])

    rows_o = np.shape(FLAIR_array)[1]
    cols_o = np.shape(FLAIR_array)[2]
    FLAIR_array = FLAIR_array[:, int((rows_o-rows_standard)/2):int((rows_o-rows_standard)/2)+rows_standard, int((cols_o-cols_standard)/2):int((cols_o-cols_standard)/2)+cols_standard]
FLAIR\u数组具有以下形状:[48240240]

48是图像的数量。
240,240是它的高度和宽度。


或者,他们正在对其进行切片。

是的,他们只在
FLAIR\u数组上执行(而不是重塑)操作,其结果尺寸为:

  • 第0维中的所有元素都保留在原始数组中(如
    所示)
  • 元素
    int((rows\o-rows\u-standard)/2)
    int((rows\o-rows\u-standard)/2)+rows\u-standard-1
    从原始数组的第一维开始使用
  • 元素
    int((cols\u o-cols\u标准)/2)
    int((cols\u-cols\u标准)/2)+cols\u标准-1
    从原始数组的第二维开始使用

很难说,因为函数中没有定义标准行。 但是如果您将其重写为(删除一些int(..)以增加可读性)


似乎他们正在为每个图像提取一个小裁剪,以行为中心,列为中心,行数和列数等于行数和列数,谢谢你的回答。所以,它将具有相同的形状,但元素较少,不是吗?是的,完全如此。切片减少了元素的数量,而重塑保留了元素的数量,但在不同的维度上排列顺序不同。看起来像是从每个图像中切片一个居中窗口,例如
FLAIR\u数组[:,100:140,90:150]
以生成(48,40,60)数组。
FLAIR_array[:, int((rows_o-rows_standard)/2):int((rows_o-rows_standard)/2)+rows_standard, int((cols_o-cols_standard)/2):int((cols_o-cols_standard)/2)+cols_standard]
rows_center = int(rows_o/2)
cols_center = int(cols_o/2)
delta_rows = int(rows_standard)
delta_cols = int(cols_standard)
FLAIR_array = FLAIR_array[:, rows_center - rows_delta/2:rows_center + rows_delta/2, cols_center - cols_delta/2:cols_center + cols_delta/2]