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