{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": false }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ ":0: FutureWarning: IPython widgets are experimental and may change in the future.\n" ] } ], "source": [ "import numpy as np\n", "from scipy.misc import imread\n", "\n", "from bokeh.plotting import figure, show\n", "from bokeh.io import output_notebook\n", "from bokeh.models import ColumnDataSource\n", "from bokeh.palettes import Greys9, Greys3\n", "\n", "from IPython.html.widgets import interact" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ " \n", " \n", " \n", " \n", "
\n", " \n", " BokehJS successfully loaded.\n", "
" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "output_notebook()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "TOOLS=\"pan, box_zoom, reset, save\"\n", "\n", "# The image is this one: https://windycitizensports.files.wordpress.com/2011/10/baboon.jpg?w=595\n", "RGB_image = imread('/Users/curt/Downloads/BaboonRGB.jpg')\n", "\n", "nx, ny, n_colors = RGB_image.shape\n", "\n", "source = ColumnDataSource(data={'image': RGB_image[:, :, 0]})\n", "\n", "p = figure(title=\"Single-color slice of RGB image\", \n", " tools=TOOLS, \n", " x_range=[0, nx], \n", " y_range=[0, ny],\n", " )" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "\n" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/plain": [ "" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# This is really slow; not sure if it is a bokeh problem or a problem with my code.\n", "\n", "def update(color=0):\n", " global RGB_image\n", " source.data['image'] = RGB_image[:, :, color]\n", " p.image([source.data['image'][::-1, :]],\n", " x=0, \n", " y=0, \n", " dh=[ny], \n", " dw=[nx], \n", " palette=Greys9,\n", " source = source\n", " )\n", " show(p)\n", "\n", " \n", "interact(update, color=(0, 2))" ] } ], "metadata": { "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.10" } }, "nbformat": 4, "nbformat_minor": 0 }