diff --git a/skimage/viewer/plugins/overlayplugin.py b/skimage/viewer/plugins/overlayplugin.py index 278f072c..25ea3b00 100644 --- a/skimage/viewer/plugins/overlayplugin.py +++ b/skimage/viewer/plugins/overlayplugin.py @@ -2,7 +2,7 @@ from warnings import warn from skimage.util.dtype import dtype_range from .base import Plugin -from ..utils import ClearColormap +from ..utils import ClearColormap, update_axes_image __all__ = ['OverlayPlugin'] @@ -66,7 +66,8 @@ class OverlayPlugin(Plugin): self._overlay_plot = ax.imshow(image, cmap=self.cmap, vmin=vmin, vmax=vmax) else: - self._overlay_plot.set_array(image) + update_axes_image(self._overlay_plot, image) + self.image_viewer.redraw() @property diff --git a/skimage/viewer/utils/core.py b/skimage/viewer/utils/core.py index 7ea28fab..826147eb 100644 --- a/skimage/viewer/utils/core.py +++ b/skimage/viewer/utils/core.py @@ -18,7 +18,8 @@ from ..qt import QtGui __all__ = ['init_qtapp', 'start_qtapp', 'RequiredAttr', 'figimage', - 'LinearColormap', 'ClearColormap', 'FigureCanvas', 'new_plot'] + 'LinearColormap', 'ClearColormap', 'FigureCanvas', 'new_plot', + 'update_axes_image'] QApp = None @@ -179,3 +180,22 @@ def figimage(image, scale=1, dpi=None, **kwargs): ax.set_axis_off() ax.imshow(image, **kwargs) return fig, ax + + +def update_axes_image(image_axes, image): + """Update the image displayed by an image plot. + + This sets the image plot's array and updates its shape appropriately + + Parameters + ---------- + image_axes : `matplotlib.image.AxesImage` + Image axes to update. + image : array + Image array. + """ + image_axes.set_array(image) + + # Adjust size if new image shape doesn't match the original + h, w = image.shape[:2] + image_axes.set_extent((0, w, h, 0)) diff --git a/skimage/viewer/viewers/core.py b/skimage/viewer/viewers/core.py index a054da13..874dc6ba 100644 --- a/skimage/viewer/viewers/core.py +++ b/skimage/viewer/viewers/core.py @@ -221,13 +221,10 @@ class ImageViewer(QtGui.QMainWindow): @image.setter def image(self, image): self._img = image - self._image_plot.set_array(image) + utils.update_axes_image(self._image_plot, image) - # Adjust size if new image shape doesn't match the original - h, w = image.shape[:2] - # update data coordinates (otherwise pixel coordinates are off) - self._image_plot.set_extent((0, w, h, 0)) # update display (otherwise image doesn't fill the canvas) + h, w = image.shape[:2] self.ax.set_xlim(0, w) self.ax.set_ylim(h, 0) diff --git a/viewer_examples/plugins/collection_overlay.py b/viewer_examples/plugins/collection_overlay.py new file mode 100644 index 00000000..4c7002f2 --- /dev/null +++ b/viewer_examples/plugins/collection_overlay.py @@ -0,0 +1,21 @@ +""" +============================================== +``CollectionViewer`` with an ``OverlayPlugin`` +============================================== + +Demo of a CollectionViewer for viewing collections of images with an +overlay plugin. + +""" +from skimage import data + +from skimage.viewer import CollectionViewer +from skimage.viewer.plugins.canny import CannyPlugin + + +img_collection = [data.camera(), data.coins(), data.text()] + +viewer = CollectionViewer(img_collection) +viewer += CannyPlugin() + +viewer.show() diff --git a/viewer_examples/plugins/collection_plugin.py b/viewer_examples/plugins/collection_plugin.py index f29b0132..80c7ff45 100644 --- a/viewer_examples/plugins/collection_plugin.py +++ b/viewer_examples/plugins/collection_plugin.py @@ -1,7 +1,7 @@ """ -================= -Collection plugin -================= +================================== +``CollectionViewer`` with a plugin +================================== Demo of a CollectionViewer for viewing collections of images with the `autolevel` rank filter connected as a plugin.