Files
scikit-image/skimage/viewer/plugins/canny.py
T
Tony S Yu 86b428952d ENH: Allow Plugin.add_widget to hook into Plugin attributes.
The `ptype` parameter of widget can now be set to 'plugin'. When this is the case, the plugin will set a plugin attribute whenever the widget is updated.

As an example, this commit adds a ComboBox widget which is hooked into the overlay color of the OverlayPlugin.
2012-07-22 13:24:41 -04:00

26 lines
944 B
Python

from skimage.filter import canny
from .overlayplugin import OverlayPlugin
from ..widgets import Slider, ComboBox
class CannyPlugin(OverlayPlugin):
name = 'Canny Filter'
def __init__(self, image_viewer, *args, **kwargs):
height = kwargs.get('height', 100)
width = kwargs.get('width', 400)
super(CannyPlugin, self).__init__(image_viewer,
width=width, height=height)
self.add_widget(Slider('sigma', 0, 5, update_on='release'))
self.add_widget(Slider('low threshold', 0, 255, update_on='release'))
self.add_widget(Slider('high threshold', 0, 255, update_on='release'))
self.add_widget(ComboBox('color', self.color_names, ptype='plugin'))
# Update image overlay to default slider values.
self.filter_image()
def image_filter(self, *args, **kwargs):
image = canny(*args, **kwargs)
self.overlay = image