"Fossies" - the Fresh Open Source Software Archive

Member "scikit-image-0.19.3/skimage/__init__.py" (12 Jun 2022, 6033 Bytes) of package /linux/misc/scikit-image-0.19.3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Python source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. For more information about "__init__.py" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 0.19.2_vs_0.19.3.

    1 """Image Processing for Python
    2 
    3 ``scikit-image`` (a.k.a. ``skimage``) is a collection of algorithms for image
    4 processing and computer vision.
    5 
    6 The main package of ``skimage`` only provides a few utilities for converting
    7 between image data types; for most features, you need to import one of the
    8 following subpackages:
    9 
   10 Subpackages
   11 -----------
   12 color
   13     Color space conversion.
   14 data
   15     Test images and example data.
   16 draw
   17     Drawing primitives (lines, text, etc.) that operate on NumPy arrays.
   18 exposure
   19     Image intensity adjustment, e.g., histogram equalization, etc.
   20 feature
   21     Feature detection and extraction, e.g., texture analysis corners, etc.
   22 filters
   23     Sharpening, edge finding, rank filters, thresholding, etc.
   24 graph
   25     Graph-theoretic operations, e.g., shortest paths.
   26 io
   27     Reading, saving, and displaying images and video.
   28 measure
   29     Measurement of image properties, e.g., region properties and contours.
   30 metrics
   31     Metrics corresponding to images, e.g. distance metrics, similarity, etc.
   32 morphology
   33     Morphological operations, e.g., opening or skeletonization.
   34 restoration
   35     Restoration algorithms, e.g., deconvolution algorithms, denoising, etc.
   36 segmentation
   37     Partitioning an image into multiple regions.
   38 transform
   39     Geometric and other transforms, e.g., rotation or the Radon transform.
   40 util
   41     Generic utilities.
   42 viewer
   43     A simple graphical user interface for visualizing results and exploring
   44     parameters.
   45 
   46 Utility Functions
   47 -----------------
   48 img_as_float
   49     Convert an image to floating point format, with values in [0, 1].
   50     Is similar to `img_as_float64`, but will not convert lower-precision
   51     floating point arrays to `float64`.
   52 img_as_float32
   53     Convert an image to single-precision (32-bit) floating point format,
   54     with values in [0, 1].
   55 img_as_float64
   56     Convert an image to double-precision (64-bit) floating point format,
   57     with values in [0, 1].
   58 img_as_uint
   59     Convert an image to unsigned integer format, with values in [0, 65535].
   60 img_as_int
   61     Convert an image to signed integer format, with values in [-32768, 32767].
   62 img_as_ubyte
   63     Convert an image to unsigned byte format, with values in [0, 255].
   64 img_as_bool
   65     Convert an image to boolean format, with values either True or False.
   66 dtype_limits
   67     Return intensity limits, i.e. (min, max) tuple, of the image's dtype.
   68 
   69 """
   70 
   71 __version__ = '0.19.3'
   72 
   73 submodules = [
   74     'color',
   75     'data',
   76     'draw',
   77     'exposure',
   78     'feature',
   79     'filters',
   80     'future',
   81     'graph',
   82     'io',
   83     'measure',
   84     'metrics',
   85     'morphology',
   86     'registration',
   87     'restoration',
   88     'segmentation',
   89     'transform',
   90     'util',
   91     'viewer'
   92 ]
   93 
   94 from ._shared.version_requirements import ensure_python_version
   95 ensure_python_version((3, 7))
   96 
   97 from ._shared import lazy
   98 __getattr__, __lazy_dir__, _ = lazy.attach(
   99     __name__,
  100     submodules,
  101     submod_attrs={'data': ['data_dir']}
  102 )
  103 
  104 
  105 def __dir__():
  106     return __lazy_dir__() + ['__version__']
  107 
  108 # Logic for checking for improper install and importing while in the source
  109 # tree when package has not been installed inplace.
  110 # Code adapted from scikit-learn's __check_build module.
  111 _INPLACE_MSG = """
  112 It appears that you are importing a local scikit-image source tree. For
  113 this, you need to have an inplace install. Maybe you are in the source
  114 directory and you need to try from another location."""
  115 
  116 _STANDARD_MSG = """
  117 Your install of scikit-image appears to be broken.
  118 Try re-installing the package following the instructions at:
  119 https://scikit-image.org/docs/stable/install.html """
  120 
  121 
  122 def _raise_build_error(e):
  123     # Raise a comprehensible error
  124     import os.path as osp
  125     local_dir = osp.split(__file__)[0]
  126     msg = _STANDARD_MSG
  127     if local_dir == "skimage":
  128         # Picking up the local install: this will work only if the
  129         # install is an 'inplace build'
  130         msg = _INPLACE_MSG
  131     raise ImportError("""%s
  132 It seems that scikit-image has not been built correctly.
  133 %s""" % (e, msg))
  134 
  135 
  136 try:
  137     # This variable is injected in the __builtins__ by the build
  138     # process. It used to enable importing subpackages of skimage when
  139     # the binaries are not built
  140     __SKIMAGE_SETUP__
  141 except NameError:
  142     __SKIMAGE_SETUP__ = False
  143 
  144 if __SKIMAGE_SETUP__:
  145     import sys
  146     sys.stderr.write('Partial import of skimage during the build process.\n')
  147     # We are not importing the rest of the scikit during the build
  148     # process, as it may not be compiled yet
  149 else:
  150     try:
  151         from ._shared import geometry
  152         del geometry
  153     except ImportError as e:
  154         _raise_build_error(e)
  155 
  156     # All skimage root imports go here
  157     from .util.dtype import (img_as_float32,
  158                              img_as_float64,
  159                              img_as_float,
  160                              img_as_int,
  161                              img_as_uint,
  162                              img_as_ubyte,
  163                              img_as_bool,
  164                              dtype_limits)
  165     from .util.lookfor import lookfor
  166 
  167 if 'dev' in __version__:
  168     # Append last commit date and hash to dev version information, if available
  169 
  170     import subprocess
  171     import os.path
  172 
  173     try:
  174         p = subprocess.Popen(
  175             ['git', 'log', '-1', '--format="%h %aI"'],
  176             stdout=subprocess.PIPE,
  177             stderr=subprocess.PIPE,
  178             cwd=os.path.dirname(__file__),
  179         )
  180     except FileNotFoundError:
  181         pass
  182     else:
  183         out, err = p.communicate()
  184         if p.returncode == 0:
  185             git_hash, git_date = (
  186                 out.decode('utf-8')
  187                 .strip()
  188                 .replace('"', '')
  189                 .split('T')[0]
  190                 .replace('-', '')
  191                 .split()
  192             )
  193 
  194             __version__ = '+'.join(
  195                 [tag for tag in __version__.split('+')
  196                  if not tag.startswith('git')]
  197             )
  198             __version__ += f'+git{git_date}.{git_hash}'
  199 
  200 from skimage._shared.tester import PytestTester  # noqa
  201 test = PytestTester(__name__)
  202 del PytestTester