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