mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-26 13:37:17 +08:00
Fix display of overlay plugin when original image is updated
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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()
|
||||
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user