From 260a336eb91edbfe0fe0e7ddb1c9809a1a0ac8b9 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Wed, 25 Jul 2012 00:31:08 -0400 Subject: [PATCH] ENH: allow color to be set by name --- skimage/viewer/plugins/overlayplugin.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/skimage/viewer/plugins/overlayplugin.py b/skimage/viewer/plugins/overlayplugin.py index 3aa5a445..1473ca51 100644 --- a/skimage/viewer/plugins/overlayplugin.py +++ b/skimage/viewer/plugins/overlayplugin.py @@ -5,11 +5,18 @@ from ..utils import ClearColormap class OverlayPlugin(Plugin): """Plugin for ImageViewer that displays an overlay on top of main image. + The base Plugin class displays the filtered image directly on the viewer. + OverlayPlugin will instead overlay an image with a transparent colormap. + + See base Plugin class for additional details. + Attributes ---------- overlay : array Overlay displayed on top of image. This overlay defaults to a color map with alpha values varying linearly from 0 to 1. + color : int + Color of overlay. """ colors = {'red': (1, 0, 0), 'yellow': (1, 1, 0), @@ -46,10 +53,11 @@ class OverlayPlugin(Plugin): self.image_viewer.redraw() def display_filtered_image(self, image): - """Display image over image in viewer.""" + """Display filtered image as an overlay on top of image in viewer.""" self.overlay = image def closeEvent(self, event): + # clear overlay from ImageViewer on close self.overlay = None super(OverlayPlugin, self).closeEvent(event) @@ -60,7 +68,10 @@ class OverlayPlugin(Plugin): @color.setter def color(self, index): # Update colormap whenever color is changed. - name = self.color_names[index] + if isinstance(index, basestring) and index not in self.color_names: + raise ValueError("%s not defined in OverlayPlugin.colors" % index) + else: + name = self.color_names[index] self._color = name rgb = self.colors[name] self.cmap = ClearColormap(rgb)