{
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Render text onto an image\n\nScikit-image currently doesn't feature a function that allows you to\nwrite text onto an image. However, there is a fairly easy workaround\nusing scikit-image's optional dependency [matplotlib](https://matplotlib.org/).\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import matplotlib.pyplot as plt\nimport numpy as np\nimport skimage as ski\n\nimg = ski.data.cat()\n\nfig = plt.figure()\nfig.figimage(img, resize=True)\nfig.text(0, 0.99, \"I am stefan's cat.\", fontsize=32, va=\"top\")\nfig.canvas.draw()\nannotated_img = np.asarray(fig.canvas.renderer.buffer_rgba())\nplt.close(fig)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "For the purpose of this example, we can also show the image; however, if one\njust wants to write onto the image, this step is not necessary.\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "fig, ax = plt.subplots()\nax.imshow(annotated_img)\nax.set_axis_off()\nax.set_position([0, 0, 1, 1])\nplt.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "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.12.12"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}