##// END OF EJS Templates
Provide the notebook being imported with "get_ipython"
r21008:bf5fb3f5
Show More
Image Processing.ipynb
162 lines | 3.4 KiB | text/plain | TextLexer
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cells": [
Brian E. Granger
Refactoring interact examples.
r16092 {
Min RK
upate exmaple notebooks to nbformat v4
r18669 "cell_type": "markdown",
"metadata": {},
"source": [
"# Image Manipulation with skimage"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This example builds a simple UI for performing basic image manipulation with [scikit-image](http://scikit-image.org/)."
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"from IPython.html.widgets import interact, interactive, fixed\n",
"from IPython.display import display"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import skimage\n",
"from skimage import data, filter, io"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"i = data.coffee()"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"io.Image(i)"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"def edit_image(image, sigma=0.1, r=1.0, g=1.0, b=1.0):\n",
" new_image = filter.gaussian_filter(image, sigma=sigma, multichannel=True)\n",
" new_image[:,:,0] = r*new_image[:,:,0]\n",
" new_image[:,:,1] = g*new_image[:,:,1]\n",
" new_image[:,:,2] = b*new_image[:,:,2]\n",
" new_image = io.Image(new_image)\n",
" display(new_image)\n",
" return new_image"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"lims = (0.0,1.0,0.01)\n",
"w = interactive(edit_image, image=fixed(i), sigma=(0.0,10.0,0.1), r=lims, g=lims, b=lims)\n",
"display(w)"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"w.result"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Python 3 only: Function annotations"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"In Python 3, you can use the new function annotation syntax to describe widgets for interact:"
]
},
{
"cell_type": "code",
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "execution_count": null,
Min RK
upate exmaple notebooks to nbformat v4
r18669 "metadata": {
"collapsed": false
},
Jonathan Frederic
Update examples/Interactive Widgets :troll:
r20541 "outputs": [],
Min RK
upate exmaple notebooks to nbformat v4
r18669 "source": [
"lims = (0.0,1.0,0.01)\n",
"\n",
"@interact\n",
"def edit_image(image: fixed(i), sigma:(0.0,10.0,0.1)=0.1, r:lims=1.0, g:lims=1.0, b:lims=1.0):\n",
" new_image = filter.gaussian_filter(image, sigma=sigma, multichannel=True)\n",
" new_image[:,:,0] = r*new_image[:,:,0]\n",
" new_image[:,:,1] = g*new_image[:,:,1]\n",
" new_image[:,:,2] = b*new_image[:,:,2]\n",
" new_image = io.Image(new_image)\n",
" display(new_image)\n",
" return new_image"
]
Brian E. Granger
Refactoring interact examples.
r16092 }
Min RK
upate exmaple notebooks to nbformat v4
r18669 ],
Min RK
add kernel metadata to example notebooks
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
Update examples/Interactive Widgets :troll:
r20541 "version": "3.4.0"
Min RK
add kernel metadata to example notebooks
r20278 }
},
Min RK
upate exmaple notebooks to nbformat v4
r18669 "nbformat": 4,
"nbformat_minor": 0
Min RK
add kernel metadata to example notebooks
r20278 }