如何可视化标签图像

时间:2018-06-28 11:09:06

标签: python-3.x image-processing simpleitk

我要分割图像。我使用了简单的阈值化方法。为此,我读取图像并将其转换为数组,然后将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 &'

1 个答案:

答案 0 :(得分:0)

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