Image Browser.ipynb
119 lines
| 2.2 KiB
| text/plain
|
TextLexer
Brian E. Granger
|
r16092 | { | ||
Min RK
|
r18669 | "cells": [ | ||
Brian E. Granger
|
r16092 | { | ||
Min RK
|
r18669 | "cell_type": "markdown", | ||
"metadata": {}, | ||||
"source": [ | ||||
"## Image Browser" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "markdown", | ||||
"metadata": {}, | ||||
"source": [ | ||||
"This example shows how to browse through a set of images with a slider." | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"%matplotlib inline\n", | ||||
"import matplotlib.pyplot as plt" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"from IPython.html.widgets import interact" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"from sklearn import datasets" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "markdown", | ||||
"metadata": {}, | ||||
"source": [ | ||||
"We will use the digits dataset from [scikit-learn](http://scikit-learn.org/stable/)." | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"digits = datasets.load_digits()" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
"outputs": [], | ||||
"source": [ | ||||
"def browse_images(digits):\n", | ||||
" n = len(digits.images)\n", | ||||
" def view_image(i):\n", | ||||
" plt.imshow(digits.images[i], cmap=plt.cm.gray_r, interpolation='nearest')\n", | ||||
" plt.title('Training: %s' % digits.target[i])\n", | ||||
" plt.show()\n", | ||||
" interact(view_image, i=(0,n-1))" | ||||
] | ||||
}, | ||||
{ | ||||
"cell_type": "code", | ||||
Jonathan Frederic
|
r20541 | "execution_count": null, | ||
Min RK
|
r18669 | "metadata": { | ||
"collapsed": false | ||||
}, | ||||
Jonathan Frederic
|
r20541 | "outputs": [], | ||
Min RK
|
r18669 | "source": [ | ||
"browse_images(digits)" | ||||
] | ||||
Brian E. Granger
|
r16092 | } | ||
Min RK
|
r18669 | ], | ||
Min RK
|
r20278 | "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", | ||||
Jonathan Frederic
|
r20541 | "version": "3.4.0" | ||
Min RK
|
r20278 | } | ||
}, | ||||
Min RK
|
r18669 | "nbformat": 4, | ||
"nbformat_minor": 0 | ||||
Min RK
|
r20278 | } | ||