Images from a function (Lazy loading)#

You do not need to provide an array of images. Instead you can provide a function that returns an image given an index. This enables the follow:

  1. Lazy loading of images

  2. Easily have images of different sizes (the image will update limits automatically)

# if in a notebook
%matplotlib ipympl
# You can lazy load images by providing a function instead of a list for *images*
# if you do this then you must also provide *N_images* in the labeller constructor


import matplotlib.pyplot as plt
from numpy.random import default_rng

from mpl_image_labeller import image_labeller


def lazy_image_generator(idx):
    rng = default_rng(idx)
    return rng.random((rng.integers(5, 15), rng.integers(5, 15)))


labeller = image_labeller(
    lazy_image_generator, classes=["cool", "rad", "lame"], N_images=57
)
plt.show()