ITK  5.4.0
Insight Toolkit
Examples/Segmentation/WatershedSegmentation1.py
1# ==========================================================================
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# ==========================================================================*/
18
19import InsightToolkit as itk
20import sys
21
22reader = itk.itkImageFileReaderF2_New()
23reader.SetFileName(sys.argv[1])
24
25diffusion = itk.itkGradientAnisotropicDiffusionImageFilterF2F2_New()
26diffusion.SetInput(reader.GetOutput())
27diffusion.SetTimeStep(0.0625)
28diffusion.SetConductanceParameter(9.0)
29diffusion.SetNumberOfIterations(5)
30
31gradient = itk.itkGradientMagnitudeImageFilterF2F2_New()
32gradient.SetInput(diffusion.GetOutput())
33
34watershed = itk.itkWatershedImageFilterF2_New()
35watershed.SetInput(gradient.GetOutput())
36watershed.SetThreshold(0.01)
37watershed.SetLevel(0.2)
38
39writer = itk.itkImageFileWriterUL2_New()
40writer.SetFileName(sys.argv[2])
41writer.SetInput(watershed.GetOutput())
42writer.Update()