{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%gui qt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Display an Image\n\nSimple use of SceneCanvas to display an Image.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import sys\nfrom vispy import scene\nfrom vispy import app\nfrom vispy.io import load_data_file, read_png\n\ncanvas = scene.SceneCanvas(keys='interactive')\ncanvas.size = 800, 600\ncanvas.show()\n\n# Set up a viewbox to display the image with interactive pan/zoom\nview = canvas.central_widget.add_view()\n\n# Create the image\nimg_data = read_png(load_data_file('mona_lisa/mona_lisa_sm.png'))\ninterpolation = 'nearest'\n\nimage = scene.visuals.Image(img_data, interpolation=interpolation,\n parent=view.scene, method='subdivide')\n\ncanvas.title = 'Spatial Filtering using %s Filter' % interpolation\n\n# Set 2D camera (the camera will scale to the contents in the scene)\nview.camera = scene.PanZoomCamera(aspect=1)\n# flip y-axis to have correct aligment\nview.camera.flip = (0, 1, 0)\nview.camera.set_range()\nview.camera.zoom(0.1, (250, 200))\n\n# get interpolation functions from Image\nnames = image.interpolation_functions\nnames = sorted(names)\nact = 17\n\n\n# Implement key presses\n@canvas.events.key_press.connect\ndef on_key_press(event):\n global act\n if event.key in ['Left', 'Right']:\n if event.key == 'Right':\n step = 1\n else:\n step = -1\n act = (act + step) % len(names)\n interpolation = names[act]\n image.interpolation = interpolation\n canvas.title = 'Spatial Filtering using %s Filter' % interpolation\n canvas.update()\n\n\nif __name__ == '__main__' and sys.flags.interactive == 0:\n app.run()" ] } ], "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.9.19" } }, "nbformat": 4, "nbformat_minor": 0 }