ITK  6.0.0
Insight Toolkit
SphinxExamples/src/IO/ImageBase/WriteAnImage/Code.py
1 #!/usr/bin/env python
2 
3 # Copyright NumFOCUS
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 # https://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 itk
18 import argparse
19 
20 parser = argparse.ArgumentParser(description="Write An Image.")
21 parser.add_argument("output_image", nargs="?")
22 args = parser.parse_args()
23 
24 if args.output_image:
25  output_filename = args.output_image
26 else:
27  output_filename = "testPython.png"
28 
29 pixel_type = itk.UC
30 dimension = 2
31 image_type = itk.Image[pixel_type, dimension]
32 
33 start = itk.Index[dimension]()
34 start.Fill(0)
35 
36 size = itk.Size[dimension]()
37 size[0] = 200
38 size[1] = 300
39 
40 region = itk.ImageRegion[dimension]()
41 region.SetIndex(start)
42 region.SetSize(size)
43 
44 image = image_type.New(Regions=region)
45 image.Allocate()
46 
47 itk.imwrite(image, output_filename)
itk::Index
Represent a n-dimensional index in a n-dimensional image.
Definition: itkIndex.h:68
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:69
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:80
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88