##// END OF EJS Templates
Merge pull request #8778 from SylvainCorlay/Meta...
Merge pull request #8778 from SylvainCorlay/Meta Use isinstance to check for types

File last commit:

r20541:1e566dcc
r21631:3ac9be53 merge
Show More
Image Processing.ipynb
162 lines | 3.4 KiB | text/plain | TextLexer

Image Manipulation with skimage

This example builds a simple UI for performing basic image manipulation with scikit-image.

In [ ]:
from IPython.html.widgets import interact, interactive, fixed
from IPython.display import display
In [ ]:
import skimage
from skimage import data, filter, io
In [ ]:
i = data.coffee()
In [ ]:
io.Image(i)
In [ ]:
def edit_image(image, sigma=0.1, r=1.0, g=1.0, b=1.0):
    new_image = filter.gaussian_filter(image, sigma=sigma, multichannel=True)
    new_image[:,:,0] = r*new_image[:,:,0]
    new_image[:,:,1] = g*new_image[:,:,1]
    new_image[:,:,2] = b*new_image[:,:,2]
    new_image = io.Image(new_image)
    display(new_image)
    return new_image
In [ ]:
lims = (0.0,1.0,0.01)
w = interactive(edit_image, image=fixed(i), sigma=(0.0,10.0,0.1), r=lims, g=lims, b=lims)
display(w)
In [ ]:
w.result

Python 3 only: Function annotations

In Python 3, you can use the new function annotation syntax to describe widgets for interact:

In [ ]:
lims = (0.0,1.0,0.01)

@interact
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):
    new_image = filter.gaussian_filter(image, sigma=sigma, multichannel=True)
    new_image[:,:,0] = r*new_image[:,:,0]
    new_image[:,:,1] = g*new_image[:,:,1]
    new_image[:,:,2] = b*new_image[:,:,2]
    new_image = io.Image(new_image)
    display(new_image)
    return new_image