-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathimage_reshaping.py
More file actions
50 lines (34 loc) · 1.3 KB
/
image_reshaping.py
File metadata and controls
50 lines (34 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""
Image reshaping
===============
An example that shows replacement of the image data with new data of a different shape. Under the hood, this creates a
new buffer and a new array of Textures on the GPU that replace the older Textures. Creating a new buffer and textures
has a performance cost, so you should do this only if you need to or if the performance drawback is not a concern for
your use case.
Note that the vmin-vmax is reset when you replace the buffers.
"""
# test_example = false
# sphinx_gallery_pygfx_docs = 'animate'
import numpy as np
import fastplotlib as fpl
# create some data, diagonal sinusoidal bands
xs = np.linspace(0, 2300, 2300, dtype=np.float16)
full_data = np.vstack([np.cos(np.sqrt(xs + (np.pi / 2) * i)) * i for i in range(2_300)])
figure = fpl.Figure()
image = figure[0, 0].add_image(full_data)
figure.show()
i, j = 1, 1
def update():
global i, j
# set the new image data as a subset of the full data
row = np.abs(np.sin(i)) * 2300
col = np.abs(np.cos(i)) * 2300
image.data = full_data[: int(row), : int(col)]
i += 0.01
j += 0.01
figure.add_animations(update)
# NOTE: fpl.loop.run() should not be used for interactive sessions
# See the "JupyterLab and IPython" section in the user guide
if __name__ == "__main__":
print(__doc__)
fpl.loop.run()