__init__.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. # -*- coding: utf-8 -*-
  2. # Copyright (c) 2014-2020, imageio contributors
  3. # imageio is distributed under the terms of the (new) BSD License.
  4. # This docstring is used at the index of the documentation pages, and
  5. # gets inserted into a slightly larger description (in setup.py) for
  6. # the page on Pypi:
  7. """
  8. Imageio is a Python library that provides an easy interface to read and
  9. write a wide range of image data, including animated images, volumetric
  10. data, and scientific formats. It is cross-platform, runs on Python 3.9+,
  11. and is easy to install.
  12. Main website: https://imageio.readthedocs.io/
  13. """
  14. # flake8: noqa
  15. from importlib.metadata import version as get_version
  16. __version__ = get_version("imageio")
  17. import warnings
  18. # Load some bits from core
  19. from .core import FormatManager, RETURN_BYTES
  20. # Instantiate the old format manager
  21. formats = FormatManager()
  22. show_formats = formats.show
  23. from . import v2
  24. from . import v3
  25. from . import plugins
  26. # import config after core to avoid circular import
  27. from . import config
  28. # import all APIs into the top level (meta API)
  29. from .v2 import (
  30. imread as imread_v2,
  31. mimread,
  32. volread,
  33. mvolread,
  34. imwrite,
  35. mimwrite,
  36. volwrite,
  37. mvolwrite,
  38. # aliases
  39. get_reader as read,
  40. get_writer as save,
  41. imwrite as imsave,
  42. mimwrite as mimsave,
  43. volwrite as volsave,
  44. mvolwrite as mvolsave,
  45. # misc
  46. help,
  47. get_reader,
  48. get_writer,
  49. )
  50. from .v3 import (
  51. imopen,
  52. # imread, # Will take over once v3 is released
  53. # imwrite, # Will take over once v3 is released
  54. imiter,
  55. )
  56. def imread(uri, format=None, **kwargs):
  57. """imread(uri, format=None, **kwargs)
  58. Reads an image from the specified file. Returns a numpy array, which
  59. comes with a dict of meta data at its 'meta' attribute.
  60. Note that the image data is returned as-is, and may not always have
  61. a dtype of uint8 (and thus may differ from what e.g. PIL returns).
  62. Parameters
  63. ----------
  64. uri : {str, pathlib.Path, bytes, file}
  65. The resource to load the image from, e.g. a filename, pathlib.Path,
  66. http address or file object, see the docs for more info.
  67. format : str
  68. The format to use to read the file. By default imageio selects
  69. the appropriate for you based on the filename and its contents.
  70. kwargs : ...
  71. Further keyword arguments are passed to the reader. See :func:`.help`
  72. to see what arguments are available for a particular format.
  73. """
  74. warnings.warn(
  75. "Starting with ImageIO v3 the behavior of this function will switch to that of"
  76. " iio.v3.imread. To keep the current behavior (and make this warning disappear)"
  77. " use `import imageio.v2 as imageio` or call `imageio.v2.imread` directly.",
  78. DeprecationWarning,
  79. stacklevel=2,
  80. )
  81. return imread_v2(uri, format=format, **kwargs)
  82. __all__ = [
  83. "v2",
  84. "v3",
  85. "config",
  86. "plugins",
  87. # v3 API
  88. "imopen",
  89. "imread",
  90. "imwrite",
  91. "imiter",
  92. # v2 API
  93. "mimread",
  94. "volread",
  95. "mvolread",
  96. "imwrite",
  97. "mimwrite",
  98. "volwrite",
  99. "mvolwrite",
  100. # v2 aliases
  101. "read",
  102. "save",
  103. "imsave",
  104. "mimsave",
  105. "volsave",
  106. "mvolsave",
  107. # functions to deprecate
  108. "help",
  109. "get_reader",
  110. "get_writer",
  111. "formats",
  112. "show_formats",
  113. ]