MRI(脑肿瘤)图像处理与分割、颅骨切除

2024-07-02 16:22:55 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要图像分割的帮助。我有脑部肿瘤的核磁共振图像。我需要从核磁共振中取出头盖骨,然后只分割肿瘤。我怎么能用python呢?图像处理。我试过做轮廓,但我不知道如何找到和删除最大的轮廓,只得到没有头骨的大脑。 非常感谢。

def get_brain(img):
  row_size = img.shape[0]
  col_size = img.shape[1]

  mean = np.mean(img)
  std = np.std(img)
  img = img - mean
  img = img / std

 middle = img[int(col_size / 5):int(col_size / 5 * 4), int(row_size / 5):int(row_size / 5 * 4)]
  mean = np.mean(middle)
  max = np.max(img)
  min = np.min(img)


  img[img == max] = mean
  img[img == min] = mean

  kmeans = KMeans(n_clusters=2).fit(np.reshape(middle, [np.prod(middle.shape), 1]))
  centers = sorted(kmeans.cluster_centers_.flatten())
  threshold = np.mean(centers)
  thresh_img = np.where(img < threshold, 1.0, 0.0)  # threshold the image


  eroded = morphology.erosion(thresh_img, np.ones([3, 3]))
  dilation = morphology.dilation(eroded, np.ones([5, 5]))

这些图像与我看到的类似:

Skull + Brain

Skull + Brain 2

谢谢你的回答。


Tags: 图像middleimgsizethresholdnpcolmin