imread_plugin.py 956 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. __all__ = ['imread', 'imsave']
  2. from ...util.dtype import _convert
  3. try:
  4. import imread as _imread
  5. except ImportError:
  6. raise ImportError(
  7. "Imread could not be found"
  8. "Please refer to http://pypi.python.org/pypi/imread/ "
  9. "for further instructions."
  10. )
  11. def imread(fname, dtype=None):
  12. """Load an image from file.
  13. Parameters
  14. ----------
  15. fname : str
  16. Name of input file
  17. """
  18. im = _imread.imread(fname)
  19. if dtype is not None:
  20. im = _convert(im, dtype)
  21. return im
  22. def imsave(fname, arr, format_str=None):
  23. """Save an image to disk.
  24. Parameters
  25. ----------
  26. fname : str
  27. Name of destination file.
  28. arr : ndarray of uint8 or uint16
  29. Array (image) to save.
  30. format_str : str,optional
  31. Format to save as.
  32. Notes
  33. -----
  34. Currently, only 8-bit precision is supported.
  35. """
  36. return _imread.imsave(fname, arr, formatstr=format_str)