【SimpleITK】分割label覆盖到原图上显示_m0_37477175的博客-CSDN博客
医疗影像跟自然场景下图像的区别之一就是“像素”范围不一样,在将label覆盖到原图上时也略微不同,但是必须要将图像归一化到[0,255]。
我们使用SimpleITK的相关API来解决这个问题。
涉及到的API:
sitk.ReadImage
sitk.Cast
sitk.RescaleIntensity
sitk.LabelOverlay
数据为BraTS2019的数据,label 有4个,[0,1,2,4]。
from __future__ import print_function%matplotlib inlineimport matplotlib.pyplot as pltfrom ipywidgets import interact, FloatSliderimport SimpleITK as sitkfrom myshow import myshow, myshow3d123456
data:
img_T1 = 'MICCAI_BraTS_2019_Data_Training/HGG/BraTS19_CBICA_ATV_1/BraTS19_CBICA_ATV_1_t1.nii.gz'seg = 'MICCAI_BraTS_2019_Data_Training/HGG/BraTS19_CBICA_ATV_1/BraTS19_CBICA_ATV_1_seg.nii.gz'12
img_T1 = sitk.ReadImage(img_T1)# To visualize the labels image in RGB with needs a image with 0-255 rangeimg_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)myshow3d(img_T1)12345
覆盖label:
seg = sitk.ReadImage(seg)myshow(sitk.LabelOverlay(img_T1_255, seg), "Brain tumor label")12
完美~贼方便~
赞 (0)