| IOLink Python 1.11.0

Loading...
Searching...
No Matches
gradientFloatImage.py

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.

1 import iolink
2
3 import numpy as np
4
5
8 def gradientFloatImage(shape: iolink.VectorXu64):
9 dt = iolink.DataTypeId.FLOAT
10 # To create a float ImageView, the datatype of the image can be FLOAT (32bits) or DOUBLE (64 bits)
11 image = iolink.ImageViewFactory.allocate(shape, dt)
12
13 # here we set the axes interpretation, which indicates where dimensions are located (here [COLUMN, ROW])
14 # this will be useful wether the final image is converted into numpy to reorder axes.
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 # create a buffer corresponding to the line size, and
27 # initialize it to the same value
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
36image = gradientFloatImage([5, 30])
37
38print("Shape of generated image:", image.shape)
39
40
42
43#import numpy as np
44#from matplotlib import pyplot as plt
45
46
48
49#plt.imshow(npy, interpolation='nearest')
50#plt.show()
51
52print("SUCCESS")
gradientFloatImage
Definition gradientFloatImage.py:1