SMIL 1.1.1
Loading...
Searching...
No Matches
numpy_array.py
1
2import smilPython as sp
3import numpy as np
4
5# Create an image
6sx = 256
7sy = 384
8im1 = sp.Image(sx, sy)
9im1.show()
10
11# Create a numpy array containing the real image pixels
12imArr = im1.getNumpyArray()
13
14# Display the dimensions of the created array
15print("Array dims:", imArr.shape)
16
17# Do something with the array... E.g., draw a circle
18imArr[:] = 0
19# the circle will be centered at the center of the image
20radius, cx, cy = 64, sy//2, sx//2
21y, x = np.ogrid[0:sx, 0:sy]
22# get the indexes of the pixels inside the circle
23index = (x - cx)**2 + (y - cy)**2 <= radius**2
24imArr[:,:][index] = 255
25
26# Call the "modified" method in order to update the viewer content
27im1.modified()
28
29input()
30