mirror of
https://github.com/wassname/scikit-image.git
synced 2026-09-12 12:50:49 +08:00
Second part of I/O infrastructure reorganisation.
This commit is contained in:
@@ -2,7 +2,7 @@ import plugin
|
||||
|
||||
try:
|
||||
import matplotlib.pyplot as plt
|
||||
except ImportError:
|
||||
pass
|
||||
except ImportError, e:
|
||||
print e
|
||||
else:
|
||||
plugin.register('matplotlib', show=plt.imshow, save=plt.imsave)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
__all__ = ['imread']
|
||||
|
||||
import numpy as np
|
||||
import plugin
|
||||
import numpy as np
|
||||
|
||||
try:
|
||||
from PIL import Image
|
||||
@@ -51,4 +51,4 @@ def palette_is_grayscale(pil_image):
|
||||
|
||||
|
||||
if has_pil:
|
||||
plugin.register('PIL', read=imread)
|
||||
plugin.register('pil', read=imread)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
"""
|
||||
|
||||
__all__ = ['register', 'use']
|
||||
__all__ = ['register', 'use', 'load', 'available', 'call']
|
||||
|
||||
import warnings
|
||||
|
||||
@@ -38,7 +38,7 @@ def register(name, **kwds):
|
||||
if not callable(func):
|
||||
raise ValueError('Can only register functions as plugins.')
|
||||
|
||||
plugin_store[kind].append((name, func))
|
||||
plugin_store[kind].insert(0, (name, func))
|
||||
|
||||
|
||||
def call(kind, *args, **kwargs):
|
||||
@@ -60,7 +60,11 @@ def call(kind, *args, **kwargs):
|
||||
|
||||
plugin_funcs = plugin_store[kind]
|
||||
if len(plugin_funcs) == 0:
|
||||
raise RuntimeError('No suitable plugin registered for %s' % kind)
|
||||
raise RuntimeError('''No suitable plugin registered for %s.
|
||||
|
||||
You may load I/O plugins with the `scikits.image.io.load_plugin`
|
||||
command. A list of all available plugins can be found using
|
||||
`scikits.image.io.plugins()`.''' % kind)
|
||||
|
||||
plugin = kwargs.pop('plugin', None)
|
||||
if plugin is None:
|
||||
@@ -123,8 +127,9 @@ def available(kind=None):
|
||||
Parameters
|
||||
----------
|
||||
kind : {'show', 'save', 'read'}, optional
|
||||
Display the plugin list for the given function type. If not specified,
|
||||
return a dictionary with the plugins for all functions.
|
||||
Display the plugin list for the given function type. If not
|
||||
specified, return a dictionary with the plugins for all
|
||||
functions.
|
||||
|
||||
"""
|
||||
if kind is None:
|
||||
@@ -141,3 +146,21 @@ def available(kind=None):
|
||||
d[k] = [name for (name, func) in plugin_store[k]]
|
||||
|
||||
return d
|
||||
|
||||
def load(plugin):
|
||||
"""Load the given plugin.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
plugin : str
|
||||
Name of plugin to load.
|
||||
|
||||
See Also
|
||||
--------
|
||||
plugins : List of available plugins
|
||||
|
||||
"""
|
||||
try:
|
||||
__import__('scikits.image.io._plugins.' + plugin + "_plugin")
|
||||
except ImportError:
|
||||
raise ValueError('Plugin %s not found.' % plugin)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import plugin
|
||||
from _plugin_util import prepare_for_display
|
||||
from util import prepare_for_display
|
||||
|
||||
import numpy as np
|
||||
import sys
|
||||
@@ -37,7 +37,7 @@ else:
|
||||
def show(arr, block=True):
|
||||
global app
|
||||
|
||||
if not '-q4thread' in sys.argv and app is None:
|
||||
if not '-qt4thread' in sys.argv and app is None:
|
||||
app = QApplication([])
|
||||
|
||||
arr = prepare_for_display(arr)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import numpy as np
|
||||
import plugin
|
||||
from _plugin_util import prepare_for_display
|
||||
from util import prepare_for_display
|
||||
|
||||
try:
|
||||
import wx
|
||||
|
||||
Reference in New Issue
Block a user