ITK  4.13.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Core/Common/StreamAPipeline/Code.py
1 #!/usr/bin/env python
2 
3 #==========================================================================
4 #
5 # Copyright Insight Software Consortium
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License")
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 # http://www.apache.org/licenses/LICENSE-2.0.txt
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19 #==========================================================================*/
20 
21 import sys
22 import itk
23 
24 from distutils.version import StrictVersion as VS
25 if VS(itk.Version.GetITKVersion()) < VS("4.10.0"):
26  print("ITK 4.10.0 is required.")
27  sys.exit(1)
28 
29 if len(sys.argv) != 2:
30  print('Usage: ' + sys.argv[0] + ' <NumberOfSplits>')
31  sys.exit(1)
32 numberOfSplits = int(sys.argv[1])
33 
34 Dimension = 2
35 PixelType = itk.UC
36 ImageType = itk.Image[PixelType, Dimension]
37 
38 source = itk.RandomImageSource[ImageType].New()
39 size = itk.Size[Dimension]()
40 size.Fill(numberOfSplits)
41 source.SetSize(size)
42 
43 monitorFilter = itk.PipelineMonitorImageFilter[ImageType].New()
44 monitorFilter.SetInput(source.GetOutput())
45 
46 streamingFilter = itk.StreamingImageFilter[ImageType, ImageType].New()
47 streamingFilter.SetInput(monitorFilter.GetOutput())
48 streamingFilter.SetNumberOfStreamDivisions(numberOfSplits)
49 
50 streamingFilter.Update()
51 
52 print('The output LargestPossibleRegion is: ' +
53  str(streamingFilter.GetOutput().GetLargestPossibleRegion()))
54 
55 print('')
56 
57 updatedRequestedRegions = monitorFilter.GetUpdatedRequestedRegions()
58 print("Updated RequestedRegion's:")
59 for ii in range(len(updatedRequestedRegions)):
60  print(' ' + str(updatedRequestedRegions[ii]))