__init__.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. """Image Processing for Python
  2. scikit-image (a.k.a. ``skimage``) is a collection of algorithms for image
  3. processing and computer vision.
  4. Attributes
  5. ----------
  6. __version__ : str
  7. The scikit-image version string.
  8. Subpackages
  9. -----------
  10. color
  11. Color space conversion.
  12. data
  13. Example images and datasets.
  14. draw
  15. Drawing primitives, such as lines, circles, text, etc.
  16. exposure
  17. Image intensity adjustment, e.g., histogram equalization, etc.
  18. feature
  19. Feature detection and extraction, e.g., texture analysis, corners, etc.
  20. filters
  21. Sharpening, edge finding, rank filters, thresholding, etc.
  22. future
  23. Functionality with an experimental API.
  24. graph
  25. Graph-based operations, e.g., shortest paths.
  26. io
  27. Reading and saving of images and videos.
  28. measure
  29. Measurement of image properties, e.g., region properties, contours.
  30. metrics
  31. Metrics corresponding to images, e.g., distance metrics, similarity, etc.
  32. morphology
  33. Morphological algorithms, e.g., closing, opening, skeletonization.
  34. registration
  35. Image registration algorithms, e.g., optical flow or phase cross correlation.
  36. restoration
  37. Restoration algorithms, e.g., deconvolution algorithms, denoising, etc.
  38. segmentation
  39. Algorithms to partition images into meaningful regions or boundaries.
  40. transform
  41. Geometric and other transformations, e.g., rotations, Radon transform.
  42. util
  43. Generic utilities.
  44. """
  45. __version__ = '0.26.0'
  46. import lazy_loader as _lazy
  47. __getattr__, *_ = _lazy.attach_stub(__name__, __file__)
  48. # Don't use the `__all__` and `__dir__` returned by `attach_stubs` since that
  49. # one would expose utility functions we don't want to advertise in our
  50. # top-level module anymore.
  51. __all__ = [
  52. "__version__",
  53. "color",
  54. "data",
  55. "draw",
  56. "exposure",
  57. "feature",
  58. "filters",
  59. "future",
  60. "graph",
  61. "io",
  62. "measure",
  63. "metrics",
  64. "morphology",
  65. "registration",
  66. "restoration",
  67. "segmentation",
  68. "transform",
  69. "util",
  70. ]
  71. def __dir__():
  72. return __all__.copy()
  73. # Logic for checking for improper install and importing while in the source
  74. # tree when package has not been installed inplace.
  75. # Code adapted from scikit-learn's __check_build module.
  76. _INPLACE_MSG = """
  77. It appears that you are importing a local scikit-image source tree. For
  78. this, you need to have an inplace install. Maybe you are in the source
  79. directory and you need to try from another location."""
  80. _STANDARD_MSG = """
  81. Your install of scikit-image appears to be broken.
  82. Try re-installing the package following the instructions at:
  83. https://scikit-image.org/docs/stable/user_guide/install.html"""
  84. def _raise_build_error(e):
  85. # Raise a comprehensible error
  86. import os.path as osp
  87. local_dir = osp.split(__file__)[0]
  88. msg = _STANDARD_MSG
  89. if local_dir == "skimage":
  90. # Picking up the local install: this will work only if the
  91. # install is an 'inplace build'
  92. msg = _INPLACE_MSG
  93. raise ImportError(
  94. f"{e}\nIt seems that scikit-image has not been built correctly.\n{msg}"
  95. )
  96. def _try_append_commit_info(version):
  97. """Append last commit date and hash to `version`, if available."""
  98. import subprocess
  99. from pathlib import Path
  100. try:
  101. output = subprocess.check_output(
  102. ['git', 'log', '-1', '--format="%h %aI"'],
  103. cwd=Path(__file__).parent,
  104. text=True,
  105. )
  106. if output:
  107. git_hash, git_date = (
  108. output.strip().replace('"', '').split('T')[0].replace('-', '').split()
  109. )
  110. version = '+'.join(
  111. [tag for tag in version.split('+') if not tag.startswith('git')]
  112. )
  113. version += f'+git{git_date}.{git_hash}'
  114. except (FileNotFoundError, subprocess.CalledProcessError):
  115. pass
  116. except OSError:
  117. pass # If skimage is built with emscripten which does not support processes
  118. return version
  119. if 'dev' in __version__:
  120. __version__ = _try_append_commit_info(__version__)
  121. from skimage._shared.tester import PytestTester as _PytestTester
  122. test = _PytestTester(__name__)