{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "7b2b704c-a2b1-4497-bd93-b6619804d848",
   "metadata": {},
   "source": [
    "# Images from a function (Lazy loading)\n",
    "\n",
    "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:\n",
    "\n",
    "1. Lazy loading of images\n",
    "2. Easily have images of different sizes (the image will update limits automatically)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "483bffb1-f291-40ad-80ba-e9e08b8f6e88",
   "metadata": {},
   "outputs": [],
   "source": [
    "# if in a notebook\n",
    "%matplotlib ipympl"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b62a762f-26be-4dba-ab07-ec26648b970b",
   "metadata": {
    "tags": []
   },
   "outputs": [],
   "source": [
    "# You can lazy load images by providing a function instead of a list for *images*\n",
    "# if you do this then you must also provide *N_images* in the labeller constructor\n",
    "\n",
    "\n",
    "import matplotlib.pyplot as plt\n",
    "from numpy.random import default_rng\n",
    "\n",
    "from mpl_image_labeller import image_labeller\n",
    "\n",
    "\n",
    "def lazy_image_generator(idx):\n",
    "    rng = default_rng(idx)\n",
    "    return rng.random((rng.integers(5, 15), rng.integers(5, 15)))\n",
    "\n",
    "\n",
    "labeller = image_labeller(\n",
    "    lazy_image_generator, classes=[\"cool\", \"rad\", \"lame\"], N_images=57\n",
    ")\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8000249c-babc-430d-bd29-7a55145ce0bc",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
