mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 04:59:25 +08:00
24 lines
475 B
Python
24 lines
475 B
Python
__all__ = ['imread']
|
|
|
|
import numpy as np
|
|
import plugin
|
|
|
|
try:
|
|
from PIL import Image
|
|
has_pil = True
|
|
except ImportError:
|
|
has_pil = False
|
|
|
|
def imread(fname, as_grey=False, dtype=None):
|
|
"""Load an image from file.
|
|
|
|
"""
|
|
im = Image.open(fname)
|
|
if as_grey and \
|
|
not im.mode in ('1', 'L', 'I', 'F', 'I;16', 'I;16L', 'I;16B'):
|
|
im = im.convert('F')
|
|
return np.array(im, dtype=dtype)
|
|
|
|
if has_pil:
|
|
plugin.register('PIL', read=imread)
|