ITK  5.0.0
Insight Segmentation and Registration Toolkit
SphinxExamples/src/Filtering/ImageGrid/Create3DVolume/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 if len(sys.argv) < 3:
21  print("Usage: " + sys.argv[0] + " <input1> <input2> <input3> ... <output>")
22  sys.exit(1)
23 
24 InputDimension = 2
25 OutputDimension = 3
26 
27 PixelType = itk.UC
28 
29 InputImageType = itk.Image[PixelType, InputDimension]
30 OutputImageType = itk.Image[PixelType, OutputDimension]
31 
32 reader = itk.ImageFileReader[InputImageType].New()
33 
34 tileFilter = itk.TileImageFilter[InputImageType, OutputImageType].New()
35 
36 layout = [2, 2, 0]
37 tileFilter.SetLayout(layout)
38 
39 for ii in range(1, len(sys.argv)-1):
40  reader.SetFileName(sys.argv[ii])
41  reader.Update()
42 
43  inputImage = reader.GetOutput()
44  inputImage.DisconnectPipeline()
45 
46  tileFilter.SetInput(ii-1, inputImage)
47 
48 defaultValue = 128
49 tileFilter.SetDefaultPixelValue(defaultValue)
50 tileFilter.Update()
51 
52 writer = itk.ImageFileWriter[OutputImageType].New()
53 writer.SetFileName(sys.argv[-1])
54 writer.SetInput(tileFilter.GetOutput())
55 writer.Update()