Hello!
Yep. It took a while to play around with. I ended up using the pre-built function in the nengo_extras
package called image_display_function
which has a snippet here.
Here’s some code to get started.
from PIL import Image
import requests
from io import BytesIO
import numpy as np
import nengo
from nengo_extras.gui import image_display_function
# fetch image
url = 'https://upload.wikimedia.org/wikipedia/en/7/7d/Lenna_%28test_image%29.png'
response = requests.get(url)
img = Image.open(BytesIO(response.content))
# "image_display_function" expects images
# to be in (channels, x, y) and scaled between 0 and 1
img = np.transpose(img, (2, 0, 1)) / 255.
image_shape = np.shape(img)
model = nengo.Network()
with model:
# flatten image to 1D array
u = nengo.Node(lambda t: np.ndarray.flatten(img))
# display image using "image_display_function"
display_f = image_display_function(image_shape)
display_node = nengo.Node(display_f, size_in=u.size_out)
nengo.Connection(u, display_node, synapse=None)