This code demonstrates how to create a vertical gradient image with values between 0.0 and 5.0.
This code demonstrates how to create a vertical gradient image with values between 0.0 and 5.0. Lines are written one by one from the bottom to the top.
1import iolink
2
3import numpy as np
4
5
9 dt = iolink.DataTypeId.FLOAT
10
11 image = iolink.ImageViewFactory.allocate(shape, dt)
12
13
14
15 image.axes_interpretation = iolink.AxesInterpretationId.IMAGE
16
17 print("Writing some data slice by slice, line by line")
18
19 stepLine = 5.0 / shape[1];
20
21 lineSize = iolink.VectorXu64(shape[0], 1)
22 valueInit = float(0)
23 valueToSet = valueInit
24 for j in range(0, shape[1]):
25 lineRegion = iolink.RegionXu64((0, j), lineSize)
26
27
28 lineBuffer = np.full(shape=(shape[0], 1), fill_value=valueToSet, dtype=np.float32)
29 image.write_region(lineRegion, lineBuffer)
30 valueToSet = valueInit + j * stepLine
31
32 print("Writing completed")
33 return image
34
35
37
38print("Shape of generated image:", image.shape)
39
40
42
43
44
45
46
48
49
50
51
52print("SUCCESS")
Definition gradientFloatImage.py:1