__all__ = ['imread'] import numpy as np try: from PIL import Image except ImportError: raise ImportError("The Python Image Library could not be found. " "Please refer to http://pypi.python.org/pypi/PIL/ " "for further instructions.") from skimage.util import img_as_ubyte def imread(fname, dtype=None): """Load an image from file. """ im = Image.open(fname) if im.mode == 'P': if _palette_is_grayscale(im): im = im.convert('L') else: im = im.convert('RGB') elif im.mode == '1': im = im.convert('L') elif im.mode.startswith('I;16'): shape = im.size dtype = '>u2' if im.mode.endswith('B') else '