Motivated by this tweet https://twitter.com/driscollis/status/1457362125802938370?s=20 I just wanted to showcase how you can easily make scikit-image interactive with Panel and HoloViews
Below an app is shown. It works just as well in a notebook
The app can be served via panel serve name_of_script.py
.
from skimage import data
from skimage import color
from skimage import img_as_float
import holoviews as hv
import panel as pn
pn.extension(sizing_mode="stretch_width")
grayscale_image = img_as_float(data.camera()[::2, ::2])
image = color.gray2rgb(grayscale_image)
def tint(red=1, green=1, blue=1):
return hv.RGB([red, green, blue]*image)
red = pn.widgets.FloatSlider(value=1, start=0, end=1, name="Red")
green = pn.widgets.FloatSlider(value=0.5, start=0, end=1, name="Green")
blue = pn.widgets.FloatSlider(value=0.5, start=0, end=1, name="Blue")
tint = pn.bind(tint, red=red, green=green, blue=blue)
pn.template.FastListTemplate(
site="Awesome Panel",
title="Tinting gray-scale images with Scikit-Image",
sidebar=["# 🎨 Colors", red,green,blue],
main=[
pn.Column("# Before", pn.panel(hv.RGB(image))),
pn.Column("# After", pn.panel(tint, sizing_mode="stretch_both")),
],
accent_base_color="#ff286e", header_background="#ff286e"
).servable()