mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-27 21:08:24 +08:00
Extend plugins with imshow_collection
A first implementation is made for Matplotlib.
This commit is contained in:
+22
-1
@@ -10,7 +10,8 @@ from ..exposure import is_low_contrast
|
||||
from .._shared.utils import all_warnings, warn
|
||||
|
||||
|
||||
__all__ = ['imread', 'imread_collection', 'imsave', 'imshow', 'show']
|
||||
__all__ = ['imread', 'imsave', 'imshow', 'show',
|
||||
'imread_collection', 'imshow_collection']
|
||||
|
||||
|
||||
def imread(fname, as_grey=False, plugin=None, flatten=None,
|
||||
@@ -155,6 +156,26 @@ def imshow(arr, plugin=None, **plugin_args):
|
||||
return call_plugin('imshow', arr, plugin=plugin, **plugin_args)
|
||||
|
||||
|
||||
def imshow_collection(ic, plugin=None, **plugin_args):
|
||||
"""Display an image.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
ic : ImageCollection
|
||||
Collection to display.
|
||||
plugin : str
|
||||
Name of plugin to use. By default, the different plugins are
|
||||
tried until a suitable candidate is found.
|
||||
|
||||
Other parameters
|
||||
----------------
|
||||
plugin_args : keywords
|
||||
Passed to the given plugin.
|
||||
|
||||
"""
|
||||
return call_plugin('imshow_collection', ic, plugin=plugin, **plugin_args)
|
||||
|
||||
|
||||
def show():
|
||||
'''Display pending images.
|
||||
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
[matplotlib]
|
||||
description = Display or save images using Matplotlib
|
||||
provides = imshow, imread, _app_show
|
||||
|
||||
provides = imshow, imread, imshow_collection, _app_show
|
||||
|
||||
@@ -147,6 +147,7 @@ def imshow(im, ax=None, show_cbar=None, **kwargs):
|
||||
if kwargs.get('cmap', None) == 'viridis':
|
||||
kwargs['cmap'] = viridis
|
||||
lo, hi, cmap = _get_display_range(im)
|
||||
|
||||
kwargs.setdefault('interpolation', 'nearest')
|
||||
kwargs.setdefault('cmap', cmap)
|
||||
kwargs.setdefault('vmin', lo)
|
||||
@@ -160,8 +161,20 @@ def imshow(im, ax=None, show_cbar=None, **kwargs):
|
||||
plt.colorbar(ax_im, cax=cax)
|
||||
ax.set_adjustable('box-forced')
|
||||
ax.get_figure().tight_layout()
|
||||
|
||||
return ax_im
|
||||
|
||||
|
||||
def imshow_collection(ic, *args, **kwargs):
|
||||
"""Display all images in the collection.
|
||||
|
||||
"""
|
||||
fig, axes = plt.subplots(1, len(ic))
|
||||
for n, image in enumerate(ic):
|
||||
kwargs['axis'] = axes[n]
|
||||
imshow(image, *args, **kwargs)
|
||||
|
||||
|
||||
imread = plt.imread
|
||||
show = plt.show
|
||||
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
[test]
|
||||
description = Test plugin
|
||||
provides = imsave, imshow, imread, imread_collection
|
||||
provides = imsave, imshow, imread, imread_collection, imshow_collection
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# This mock-up is called by ../tests/test_plugin.py
|
||||
# to verify the behaviour of the plugin infrastructure
|
||||
|
||||
from skimage.io import ImageCollection
|
||||
|
||||
|
||||
def imread(fname, dtype=None):
|
||||
assert fname == 'test.png'
|
||||
@@ -20,3 +22,8 @@ def imshow(arr, plugin_arg=None):
|
||||
def imread_collection(x, conserve_memory=True):
|
||||
assert conserve_memory == False
|
||||
assert x == '*.png'
|
||||
return ImageCollection([0, 1], load_func=lambda x: x)
|
||||
|
||||
|
||||
def imshow_collection(x):
|
||||
assert len(x) == 2
|
||||
|
||||
@@ -46,7 +46,8 @@ plugin_meta_data = {}
|
||||
preferred_plugins = {
|
||||
# Default plugins for all types (overridden by specific types below).
|
||||
'all': ['pil', 'matplotlib', 'qt', 'freeimage'],
|
||||
'imshow': ['matplotlib']
|
||||
'imshow': ['matplotlib'],
|
||||
'imshow_collection': ['matplotlib']
|
||||
}
|
||||
|
||||
|
||||
@@ -59,13 +60,15 @@ def _clear_plugins():
|
||||
'imsave': [],
|
||||
'imshow': [],
|
||||
'imread_collection': [],
|
||||
'imshow_collection': [],
|
||||
'_app_show': []}
|
||||
_clear_plugins()
|
||||
|
||||
|
||||
def _load_preferred_plugins():
|
||||
# Load preferred plugin for each io function.
|
||||
io_types = ['imsave', 'imshow', 'imread_collection', 'imread']
|
||||
io_types = ['imsave', 'imshow', 'imread_collection', 'imshow_collection',
|
||||
'imread']
|
||||
for p_type in io_types:
|
||||
_set_plugin(p_type, preferred_plugins['all'])
|
||||
|
||||
@@ -190,8 +193,8 @@ def call_plugin(kind, *args, **kwargs):
|
||||
if len(plugin_funcs) == 0:
|
||||
msg = ("No suitable plugin registered for %s.\n\n"
|
||||
"You may load I/O plugins with the `skimage.io.use_plugin` "
|
||||
"command. A list of all available plugins can be found using "
|
||||
"`skimage.io.plugins()`.")
|
||||
"command. A list of all available plugins are shown in the "
|
||||
"`skimage.io` docstring.")
|
||||
raise RuntimeError(msg % kind)
|
||||
|
||||
plugin = kwargs.pop('plugin', None)
|
||||
@@ -216,7 +219,7 @@ def use_plugin(name, kind=None):
|
||||
----------
|
||||
name : str
|
||||
Name of plugin.
|
||||
kind : {'imsave', 'imread', 'imshow', 'imread_collection'}, optional
|
||||
kind : {'imsave', 'imread', 'imshow', 'imread_collection', 'imshow_collection'}, optional
|
||||
Set the plugin for this function. By default,
|
||||
the plugin is set for all functions.
|
||||
|
||||
|
||||
@@ -41,7 +41,8 @@ def test_show():
|
||||
|
||||
|
||||
def test_collection():
|
||||
io.imread_collection('*.png', conserve_memory=False, plugin='test')
|
||||
ic = io.imread_collection('*.png', conserve_memory=False, plugin='test')
|
||||
io.imshow_collection(ic)
|
||||
|
||||
|
||||
def test_use():
|
||||
|
||||
Reference in New Issue
Block a user