| IOLink Python 1.11.0

Loading...
Searching...
No Matches
checkerBoard.py

Basic method which shows how to create a checkerboard of given size in memory.

Basic method which shows how to create a checkerboard of given size in memory. Pixels are written one by one.

1 import iolink
2
3 from array import array
4
5 import timeit
6
7
10 def checkerBoard(sideLength):
11 shape = iolink.VectorXu64(sideLength, sideLength)
12 dt = iolink.DataTypeId.UINT8
13
14 # allocate the image in memory
15 image = iolink.ImageViewFactory.allocate(shape, dt)
16
17 tileCount = 10
18
19 blackValue = 0
20 whiteValue = 255
21
22 # tile is square, its width and height are the same
23 tileSizeInPixel = shape[0] // tileCount
24
25 # create the checkerboard pixel by pixel
26 for i in range(0, shape[0]):
27 for j in range(0, shape[1]):
28
29 # compute the concerned tile position
30 # which contains current pixel
31 tileIndexX = i // tileSizeInPixel
32 tileIndexY = j // tileSizeInPixel
33
34 # write black or white color according to the tile index
35 # at the pixel position
36 if ( (tileIndexX + tileIndexY) % 2 == 0):
37 image.write([i, j], blackValue)
38 else:
39 image.write([i, j], whiteValue)
40
41 return image
42
43start = timeit.default_timer()
44img = checkerBoard(1000)
45stop = timeit.default_timer()
46print('CheckerBoard created in: ', stop - start, "s")
47
48print("Generated ImageView:", str(img))
49
50
52
53# from PIL import Image
54# import numpy as np
55
56
59
60#img.save("checkerboard.png")
61#img.show()
62
63print("SUCCESS")
checkerBoard
Definition checkerBoard.py:1