SimpleITK中的图像分割_weixin_42834523的博客-CSDN博客

SimpleITK中的图像分割

weixin_42834523 2020-04-22 15:49:52

522

收藏 4

分类专栏: SimpleITK

版权

图像分割filters对图像进行处理,将其分割成有意义的区域,通常输出一个整数图像,其中每个整数代表一个目标,值0通常表示背景,1或255表示前景对象。

img_T1 = sitk.ReadImage(fdata("nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT1.nrrd"))img_T2 = sitk.ReadImage(fdata("nac-hncma-atlas2013-Slicer4Version/Data/A1_grayT2.nrrd"))# 为了可视化图像,将图像转化为0到255img_T1_255 = sitk.Cast(sitk.RescaleIntensity(img_T1), sitk.sitkUInt8)img_T2_255 = sitk.Cast(sitk.RescaleIntensity(img_T2), sitk.sitkUInt8)1234567

阈值分割是最基本的分割方式,它只是简单地基于灰度范围标记图像地像素,而不考虑几何或连通性。
Itk 有许多基于直方图的自动阈值过滤器,包括 Huang,maximiumentropy,Triangle,和流行的 Otsu 方法。 这些方法创建直方图,然后使用启发式方法确定阈值。

otsu_filter = sitk.OtsuThresholdImageFilter()otsu_filter.SetInsideValue(0)otsu_filter.SetOutsideValue(1)seg = otsu_filter.Execute(img_T1)myshow(sitk.LabelOverlay(img_T1_255, seg), "Otsu Thresholding")otsu_filter.GetThreshold()123456

区域增长分割

seg = sitk.ConfidenceConnected(img_T1, seedList=[seed],                                   numberOfIterations=1,                                   multiplier=2.5,                                   initialNeighborhoodRadius=1,                                   replaceValue=1)myshow(sitk.LabelOverlay(img_T1_255, seg), "ConfidenceConnected")1234567

快速步进算法
快速步进算法实现了对简单水平集进化问题地解决算法,在这个例子中,微分方程中使用地速度参数是以图像地形式来提供地。速度图像是基于梯度的大小,并用有界倒数1/(1+x)来映射。

seed = (132,142,96)feature_img = sitk.GradientMagnitudeRecursiveGaussian(img_T1, sigma=.5)speed_img = sitk.BoundedReciprocal(feature_img) # 不想sigma函数不需要参数myshow(speed_img)1234

Fastmarchingmagefilter的输出是一个跨时间的映射,它表示对于每个像素,前端到达该像素点需要花费多少时间。

fm_filter = sitk.FastMarchingBaseImageFilter()fm_filter.SetTrialPoints([seed])fm_filter.SetStoppingValue(1000)fm_img = fm_filter.Execute(speed_img)myshow(sitk.Threshold(fm_img,                    lower=0.0,                    upper=fm_filter.GetStoppingValue(),                    outsideValue=fm_filter.GetStoppingValue()+1))
(0)

相关推荐