ITK  5.0.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Core/Common/StreamAPipeline/Code.py
1 #!/usr/bin/env python
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 import sys
18 import itk
19 
20 from distutils.version import StrictVersion as VS
21 if VS(itk.Version.GetITKVersion()) < VS("4.10.0"):
22  print("ITK 4.10.0 is required.")
23  sys.exit(1)
24 
25 if len(sys.argv) != 2:
26  print('Usage: ' + sys.argv[0] + ' <NumberOfSplits>')
27  sys.exit(1)
28 numberOfSplits = int(sys.argv[1])
29 
30 Dimension = 2
31 PixelType = itk.UC
32 ImageType = itk.Image[PixelType, Dimension]
33 
34 source = itk.RandomImageSource[ImageType].New()
35 size = itk.Size[Dimension]()
36 size.Fill(numberOfSplits)
37 source.SetSize(size)
38 
39 monitorFilter = itk.PipelineMonitorImageFilter[ImageType].New()
40 monitorFilter.SetInput(source.GetOutput())
41 
42 streamingFilter = itk.StreamingImageFilter[ImageType, ImageType].New()
43 streamingFilter.SetInput(monitorFilter.GetOutput())
44 streamingFilter.SetNumberOfStreamDivisions(numberOfSplits)
45 
46 streamingFilter.Update()
47 
48 print('The output LargestPossibleRegion is: ' +
49  str(streamingFilter.GetOutput().GetLargestPossibleRegion()))
50 
51 print('')
52 
53 updatedRequestedRegions = monitorFilter.GetUpdatedRequestedRegions()
54 print("Updated RequestedRegion's:")
55 for ii in range(len(updatedRequestedRegions)):
56  print(' ' + str(updatedRequestedRegions[ii]))