ITK  6.0.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 # https://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 
22 if VS(itk.Version.GetITKVersion()) < VS("5.0.0"):
23  print("ITK 5.0.0 or newer is required.")
24  sys.exit(1)
25 
26 parser = argparse.ArgumentParser(
27  description="Segment blood vessels with multi-scale Hessian-based measure."
28 )
29 parser.add_argument("input_image")
30 parser.add_argument("output_image")
31 parser.add_argument("--sigma_minimum", type=float, default=1.0)
32 parser.add_argument("--sigma_maximum", type=float, default=10.0)
33 parser.add_argument("--number_of_sigma_steps", type=int, default=10)
34 args = parser.parse_args()
35 
36 input_image = itk.imread(args.input_image, itk.F)
37 
38 ImageType = type(input_image)
39 Dimension = input_image.GetImageDimension()
40 HessianPixelType = itk.SymmetricSecondRankTensor[itk.D, Dimension]
41 HessianImageType = itk.Image[HessianPixelType, Dimension]
42 
44  HessianImageType, ImageType
45 ].New()
46 objectness_filter.SetBrightObject(False)
47 objectness_filter.SetScaleObjectnessMeasure(False)
48 objectness_filter.SetAlpha(0.5)
49 objectness_filter.SetBeta(1.0)
50 objectness_filter.SetGamma(5.0)
51 
53  ImageType, HessianImageType, ImageType
54 ].New()
55 multi_scale_filter.SetInput(input_image)
56 multi_scale_filter.SetHessianToMeasureFilter(objectness_filter)
57 multi_scale_filter.SetSigmaStepMethodToLogarithmic()
58 multi_scale_filter.SetSigmaMinimum(args.sigma_minimum)
59 multi_scale_filter.SetSigmaMaximum(args.sigma_maximum)
60 multi_scale_filter.SetNumberOfSigmaSteps(args.number_of_sigma_steps)
61 
62 OutputPixelType = itk.UC
63 OutputImageType = itk.Image[OutputPixelType, Dimension]
64 
65 rescale_filter = itk.RescaleIntensityImageFilter[ImageType, OutputImageType].New()
66 rescale_filter.SetInput(multi_scale_filter)
67 
68 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:87
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:133
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
New
static Pointer New()