1.原始图像
2. 采用itk的Hessian矩阵进行血管增强
代码如下:
def vessleSegment(niipath):
sigma_minimum = 0.2
sigma_maximum = 3.
number_of_sigma_steps = 8
lowerThreshold = 40
output_image = 'vessel.mha'
input_image = itk.imread(niipath)
# 1.采用itk的多尺度hessian矩阵进行血管增强
ImageType = type(input_image)
Dimension = input_image.GetImageDimension()
HessianPixelType = itk.SymmetricSecondRankTensor[itk.D, Dimension]
HessianImageType = itk.Image[HessianPixelType, Dimension]
objectness_filter = itk.HessianToObjectnessMeasureImageFilter[HessianImageType, ImageType].New()
objectness_filter.SetBrightObject(True)
objectness_filter.SetScaleObjectnessMeasure(True)
objectness_filter.SetAlpha(0.5)
objectness_filter.SetBeta(1.0)
objectness_filter.SetGamma(5.0)
multi_scale_filter = itk.MultiScaleHessianBasedMeasureImageFilter[ImageType, HessianImageType, ImageType].New()
multi_scale_filter.SetInput(input_image)
multi_scale_filter.SetHessianToMeasureFilter(objectness_filter)
multi_scale_filter.SetSigmaStepMethodToLogarithmic()
multi_scale_filter.SetSigmaMinimum(sigma_minimum)
multi_scale_filter.SetSigmaMaximum(sigma_maximum)
multi_scale_filter.SetNumberOfSigmaSteps(number_of_sigma_steps)
itk.imwrite(multi_scale_filter.GetOutput(), "step1.mha")
效果图如下:
3. 将增强后的血管归一化到0-255范围内
代码如下:
# 2,将增强后的血管归一化到0-255范围
OutputPixelType = itk.UC
OutputImageType = itk.Image[OutputPixelType, Dimension]
rescale_filter = itk.RescaleIntensityImageFilter[ImageType, OutputImageType].New()
rescale_filter.SetInput(multi_scale_filter)
itk.imwrite(rescale_filter.GetOutput(), "step2.mha")
效果图如下:
4.对归一化的血管进行固定阈值分割
代码如下:
# 3归一化的血管进行固定阈值分割
thresholdFilter = itk.BinaryThresholdImageFilter[OutputImageType, OutputImageType].New()
thresholdFilter.SetInput(rescale_filter.GetOutput())
thresholdFilter.SetLowerThreshold(lowerThreshold)
thresholdFilter.SetUpperThreshold(255)
thresholdFilter.SetOutsideValue(0)
thresholdFilter.SetInsideValue(255)
itk.imwrite(thresholdFilter.GetOutput(), "step3.mha")
效果图如下: