ITK  5.2.0
Insight Toolkit
SphinxExamples/src/Nonunit/Review/SegmentBloodVesselsWithMultiScaleHessianBasedMeasure/Code.py
1 #!/usr/bin/env python
2 
3 # Copyright NumFOCUS
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0.txt
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 
17 import argparse
18 
19 import itk
20 from distutils.version import StrictVersion as VS
21 if VS(itk.Version.GetITKVersion()) < VS("5.0.0"):
22  print("ITK 5.0.0 or newer is required.")
23  sys.exit(1)
24 
25 parser = argparse.ArgumentParser(description='Segment blood vessels with multi-scale Hessian-based measure.')
26 parser.add_argument('input_image')
27 parser.add_argument('output_image')
28 parser.add_argument('--sigma_minimum', type=float, default=1.0)
29 parser.add_argument('--sigma_maximum', type=float, default=10.0)
30 parser.add_argument('--number_of_sigma_steps', type=int, default=10)
31 args = parser.parse_args()
32 
33 input_image = itk.imread(args.input_image, itk.F)
34 
35 ImageType = type(input_image)
36 Dimension = input_image.GetImageDimension()
37 HessianPixelType = itk.SymmetricSecondRankTensor[itk.D, Dimension]
38 HessianImageType = itk.Image[HessianPixelType, Dimension]
39 
40 objectness_filter = itk.HessianToObjectnessMeasureImageFilter[HessianImageType, ImageType].New()
41 objectness_filter.SetBrightObject(False)
42 objectness_filter.SetScaleObjectnessMeasure(False)
43 objectness_filter.SetAlpha(0.5)
44 objectness_filter.SetBeta(1.0)
45 objectness_filter.SetGamma(5.0)
46 
47 multi_scale_filter = itk.MultiScaleHessianBasedMeasureImageFilter[ImageType, HessianImageType, ImageType].New()
48 multi_scale_filter.SetInput(input_image)
49 multi_scale_filter.SetHessianToMeasureFilter(objectness_filter)
50 multi_scale_filter.SetSigmaStepMethodToLogarithmic()
51 multi_scale_filter.SetSigmaMinimum(args.sigma_minimum)
52 multi_scale_filter.SetSigmaMaximum(args.sigma_maximum)
53 multi_scale_filter.SetNumberOfSigmaSteps(args.number_of_sigma_steps)
54 
55 OutputPixelType = itk.UC
56 OutputImageType = itk.Image[OutputPixelType, Dimension]
57 
58 rescale_filter = itk.RescaleIntensityImageFilter[ImageType, OutputImageType].New()
59 rescale_filter.SetInput(multi_scale_filter)
60 
61 itk.imwrite(rescale_filter.GetOutput(), args.output_image)
itk::Version::GetITKVersion
static const char * GetITKVersion()
itk::SymmetricSecondRankTensor
Represent a symmetric tensor of second rank.
Definition: itkSymmetricSecondRankTensor.h:75
itk::MultiScaleHessianBasedMeasureImageFilter
A filter to enhance structures using Hessian eigensystem-based measures in a multiscale framework.
Definition: itkMultiScaleHessianBasedMeasureImageFilter.h:88
itk::HessianToObjectnessMeasureImageFilter
A filter to enhance M-dimensional objects in N-dimensional images.
Definition: itkHessianToObjectnessMeasureImageFilter.h:61
itk::RescaleIntensityImageFilter
Applies a linear transformation to the intensity levels of the input Image.
Definition: itkRescaleIntensityImageFilter.h:154
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:86