ITK  6.0.0
Insight Toolkit
SphinxExamples/src/Core/Common/CreateAnImageOfVectors/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 
19 Dimension = 3
20 ComponentType = itk.ctype("float")
21 PixelType = itk.Vector[ComponentType, Dimension]
22 ImageType = itk.Image[PixelType, Dimension]
23 
24 image = ImageType.New()
25 
26 start = itk.Index[Dimension]()
27 start[0] = 0
28 start[1] = 0
29 start[2] = 0
30 
31 size = itk.Size[Dimension]()
32 size[0] = 200
33 size[1] = 200
34 size[2] = 200
35 
36 region = itk.ImageRegion[Dimension]()
37 region.SetSize(size)
38 region.SetIndex(start)
39 
40 image.SetRegions(region)
41 image.Allocate()
42 
43 vectorValue = PixelType()
44 vectorValue[0] = 0
45 vectorValue[1] = 0
46 vectorValue[2] = 0
47 image.FillBuffer(vectorValue)
48 
49 pixelIndex = itk.Index[Dimension]()
50 pixelIndex[0] = 27
51 pixelIndex[1] = 29
52 pixelIndex[2] = 37
53 
54 pixelValue = PixelType()
55 pixelValue[0] = 1.345
56 pixelValue[1] = 6.841
57 pixelValue[2] = 3.295
58 
59 image.SetPixel(pixelIndex, pixelValue)
60 
61 value = image.GetPixel(pixelIndex)
62 
63 print(value)
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::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88