0

我想分割图像。我使用了简单的阈值方法。为此,我读取图像并将其转换为数组,然后转换 img

import SimpleITK as sitk
import numpy as np
header = sitk.ReadImage("Sub1.png")
img = sitk.GetArrayFromImage(header)
a=img
img = ((img > 20) * 255).astype(np.uint8)
# To visualize the labels image in RGB with needs a image with 0-255 range
img_T1_255 = sitk.Cast(sitk.RescaleIntensity(a), sitk.sitkUInt8)
myshow(sitk.LabelOverlay(img_T1_255, img), "Basic Thresholding")

错误是:

TypeError                                 Traceback (most recent call last)
<ipython-input-70-c44b80227919> in <module>()
      8 img = ((img > 20) * 255).astype(np.uint8)
      9 # To visualize the labels image in RGB with needs a image with 0-255 range
---> 10 img_T1_255 = sitk.Cast(sitk.RescaleIntensity(a), sitk.sitkUInt8)

~/sitkpy/lib/python3.5/site-packages/SimpleITK/SimpleITK.py in RescaleIntensity(image1, outputMinimum, outputMaximum)
  58734 
  58735     """
> 58736     return _SimpleITK.RescaleIntensity(image1, outputMinimum, outputMaximum)
  58737 class RichardsonLucyDeconvolutionImageFilter(ImageFilter_2):
  58738     """

TypeError: in method 'RescaleIntensity', argument 1 of type 'itk::simple::Image const &'
4

1 回答 1

0

您已将 SimpleITK sitk.Image 对象“header”(此变量名称表示对 sitk.ReadImage 返回的内容的理解缺失)转换为 numpy nd.array。SimpleITK 过滤器、函数和重载运算符仅适用于 sitk.ImageTypes。

于 2018-06-28T12:51:53.987 回答