io.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536
  1. from __future__ import division, print_function, absolute_import
  2. import numpy as np
  3. _have_pil = True
  4. try:
  5. from scipy.misc.pilutil import imread as _imread
  6. except ImportError:
  7. _have_pil = False
  8. __all__ = ['imread']
  9. # Use the implementation of `imread` in `scipy.misc.pilutil.imread`.
  10. # If it weren't for the different names of the first arguments of
  11. # ndimage.io.imread and misc.pilutil.imread, we could simplify this file
  12. # by writing
  13. # from scipy.misc.pilutil import imread
  14. # Unfortunately, because the argument names are different, that
  15. # introduces a backwards incompatibility.
  16. @np.deprecate(message="`imread` is deprecated in SciPy 1.0.0.\n"
  17. "Use ``matplotlib.pyplot.imread`` instead.")
  18. def imread(fname, flatten=False, mode=None):
  19. if _have_pil:
  20. return _imread(fname, flatten, mode)
  21. raise ImportError("Could not import the Python Imaging Library (PIL)"
  22. " required to load image files. Please refer to"
  23. " http://pillow.readthedocs.org/en/latest/installation.html"
  24. " for installation instructions.")
  25. if _have_pil and _imread.__doc__ is not None:
  26. imread.__doc__ = _imread.__doc__.replace('name : str', 'fname : str')