Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- envs/kitoverlay/skimage/data/README.txt +9 -0
- envs/kitoverlay/skimage/data/__init__.py +13 -0
- envs/kitoverlay/skimage/data/__init__.pyi +88 -0
- envs/kitoverlay/skimage/data/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/data/__pycache__/_binary_blobs.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/data/__pycache__/_fetchers.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/data/__pycache__/_registry.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/data/_binary_blobs.py +106 -0
- envs/kitoverlay/skimage/data/_fetchers.py +1271 -0
- envs/kitoverlay/skimage/data/_registry.py +191 -0
- envs/kitoverlay/skimage/data/lbpcascade_frontalface_opencv.xml +1505 -0
- envs/kitoverlay/skimage/data/multipage.tif +0 -0
- envs/kitoverlay/skimage/data/multipage_rgb.tif +0 -0
- envs/kitoverlay/skimage/feature/__init__.py +5 -0
- envs/kitoverlay/skimage/feature/__init__.pyi +88 -0
- envs/kitoverlay/skimage/feature/__pycache__/_hog.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/censure.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/orb.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/peak.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/_basic_features.py +198 -0
- envs/kitoverlay/skimage/feature/_canny.py +262 -0
- envs/kitoverlay/skimage/feature/_daisy.py +249 -0
- envs/kitoverlay/skimage/feature/_fisher_vector.py +262 -0
- envs/kitoverlay/skimage/feature/_hessian_det_appx.cpython-311-x86_64-linux-gnu.so +0 -0
- envs/kitoverlay/skimage/feature/_hog.py +341 -0
- envs/kitoverlay/skimage/feature/_orb_descriptor_positions.py +10 -0
- envs/kitoverlay/skimage/feature/blob.py +723 -0
- envs/kitoverlay/skimage/feature/brief.py +216 -0
- envs/kitoverlay/skimage/feature/censure.py +346 -0
- envs/kitoverlay/skimage/feature/corner.py +1355 -0
- envs/kitoverlay/skimage/feature/haar.py +339 -0
- envs/kitoverlay/skimage/feature/match.py +103 -0
- envs/kitoverlay/skimage/feature/orb.py +366 -0
- envs/kitoverlay/skimage/feature/orb_descriptor_positions.txt +256 -0
- envs/kitoverlay/skimage/feature/peak.py +420 -0
- envs/kitoverlay/skimage/feature/sift.py +771 -0
- envs/kitoverlay/skimage/feature/template.py +186 -0
- envs/kitoverlay/skimage/feature/texture.py +562 -0
- envs/kitoverlay/skimage/feature/util.py +232 -0
- envs/kitoverlay/skimage/metrics/__init__.py +5 -0
- envs/kitoverlay/skimage/metrics/__init__.pyi +28 -0
- envs/kitoverlay/skimage/metrics/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/_adapted_rand_error.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/_contingency_table.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/_structural_similarity.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/_variation_of_information.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/set_metrics.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/__pycache__/simple_metrics.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/metrics/_adapted_rand_error.py +103 -0
- envs/kitoverlay/skimage/metrics/_contingency_table.py +51 -0
envs/kitoverlay/skimage/data/README.txt
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
This directory contains sample data from scikit-image.
|
| 2 |
+
|
| 3 |
+
By default, it only contains a small subset of the entire dataset.
|
| 4 |
+
|
| 5 |
+
The full detaset can be downloaded by using the following commands from
|
| 6 |
+
a python console.
|
| 7 |
+
|
| 8 |
+
>>> from skimage.data import download_all
|
| 9 |
+
>>> download_all()
|
envs/kitoverlay/skimage/data/__init__.py
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Example images and datasets.
|
| 2 |
+
|
| 3 |
+
A curated set of general purpose and scientific images used in tests, examples,
|
| 4 |
+
and documentation.
|
| 5 |
+
|
| 6 |
+
Newer datasets are no longer included as part of the package, but are
|
| 7 |
+
downloaded on demand. To make data available offline, use :func:`download_all`.
|
| 8 |
+
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
import lazy_loader as _lazy
|
| 12 |
+
|
| 13 |
+
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|
envs/kitoverlay/skimage/data/__init__.pyi
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
__all__ = [
|
| 2 |
+
'astronaut',
|
| 3 |
+
'binary_blobs',
|
| 4 |
+
'brain',
|
| 5 |
+
'brick',
|
| 6 |
+
'camera',
|
| 7 |
+
'cat',
|
| 8 |
+
'cell',
|
| 9 |
+
'cells3d',
|
| 10 |
+
'checkerboard',
|
| 11 |
+
'chelsea',
|
| 12 |
+
'clock',
|
| 13 |
+
'coffee',
|
| 14 |
+
'coins',
|
| 15 |
+
'colorwheel',
|
| 16 |
+
'data_dir',
|
| 17 |
+
'download_all',
|
| 18 |
+
'eagle',
|
| 19 |
+
'file_hash',
|
| 20 |
+
'grass',
|
| 21 |
+
'gravel',
|
| 22 |
+
'horse',
|
| 23 |
+
'hubble_deep_field',
|
| 24 |
+
'human_mitosis',
|
| 25 |
+
'immunohistochemistry',
|
| 26 |
+
'kidney',
|
| 27 |
+
'lbp_frontal_face_cascade_filename',
|
| 28 |
+
'lfw_subset',
|
| 29 |
+
'lily',
|
| 30 |
+
'logo',
|
| 31 |
+
'microaneurysms',
|
| 32 |
+
'moon',
|
| 33 |
+
'nickel_solidification',
|
| 34 |
+
'page',
|
| 35 |
+
'protein_transport',
|
| 36 |
+
'retina',
|
| 37 |
+
'rocket',
|
| 38 |
+
'shepp_logan_phantom',
|
| 39 |
+
'skin',
|
| 40 |
+
'stereo_motorcycle',
|
| 41 |
+
'text',
|
| 42 |
+
'vortex',
|
| 43 |
+
]
|
| 44 |
+
|
| 45 |
+
from ._binary_blobs import binary_blobs
|
| 46 |
+
from ._fetchers import (
|
| 47 |
+
astronaut,
|
| 48 |
+
brain,
|
| 49 |
+
brick,
|
| 50 |
+
camera,
|
| 51 |
+
cat,
|
| 52 |
+
cell,
|
| 53 |
+
cells3d,
|
| 54 |
+
checkerboard,
|
| 55 |
+
chelsea,
|
| 56 |
+
clock,
|
| 57 |
+
coffee,
|
| 58 |
+
coins,
|
| 59 |
+
colorwheel,
|
| 60 |
+
data_dir,
|
| 61 |
+
download_all,
|
| 62 |
+
eagle,
|
| 63 |
+
file_hash,
|
| 64 |
+
grass,
|
| 65 |
+
gravel,
|
| 66 |
+
horse,
|
| 67 |
+
hubble_deep_field,
|
| 68 |
+
human_mitosis,
|
| 69 |
+
immunohistochemistry,
|
| 70 |
+
kidney,
|
| 71 |
+
lbp_frontal_face_cascade_filename,
|
| 72 |
+
lfw_subset,
|
| 73 |
+
lily,
|
| 74 |
+
logo,
|
| 75 |
+
microaneurysms,
|
| 76 |
+
moon,
|
| 77 |
+
nickel_solidification,
|
| 78 |
+
page,
|
| 79 |
+
palisades_of_vogt,
|
| 80 |
+
protein_transport,
|
| 81 |
+
retina,
|
| 82 |
+
rocket,
|
| 83 |
+
shepp_logan_phantom,
|
| 84 |
+
skin,
|
| 85 |
+
stereo_motorcycle,
|
| 86 |
+
text,
|
| 87 |
+
vortex,
|
| 88 |
+
)
|
envs/kitoverlay/skimage/data/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (649 Bytes). View file
|
|
|
envs/kitoverlay/skimage/data/__pycache__/_binary_blobs.cpython-311.pyc
ADDED
|
Binary file (5.11 kB). View file
|
|
|
envs/kitoverlay/skimage/data/__pycache__/_fetchers.cpython-311.pyc
ADDED
|
Binary file (39.3 kB). View file
|
|
|
envs/kitoverlay/skimage/data/__pycache__/_registry.cpython-311.pyc
ADDED
|
Binary file (22.1 kB). View file
|
|
|
envs/kitoverlay/skimage/data/_binary_blobs.py
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import warnings
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
from .._shared.filters import gaussian
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def binary_blobs(
|
| 9 |
+
length=512,
|
| 10 |
+
blob_size_fraction=0.1,
|
| 11 |
+
n_dim=2,
|
| 12 |
+
volume_fraction=0.5,
|
| 13 |
+
rng=None,
|
| 14 |
+
*,
|
| 15 |
+
boundary_mode='nearest',
|
| 16 |
+
):
|
| 17 |
+
"""
|
| 18 |
+
Generate synthetic binary image with several rounded blob-like objects.
|
| 19 |
+
|
| 20 |
+
Parameters
|
| 21 |
+
----------
|
| 22 |
+
length : int, optional
|
| 23 |
+
Linear size of output image.
|
| 24 |
+
blob_size_fraction : float, optional
|
| 25 |
+
Typical linear size of blob, as a fraction of ``length``, should be
|
| 26 |
+
smaller than 1.
|
| 27 |
+
n_dim : int, optional
|
| 28 |
+
Number of dimensions of output image.
|
| 29 |
+
volume_fraction : float, default 0.5
|
| 30 |
+
Fraction of image pixels covered by the blobs (where the output is 1).
|
| 31 |
+
Should be in [0, 1].
|
| 32 |
+
rng : {`numpy.random.Generator`, int}, optional
|
| 33 |
+
Pseudo-random number generator.
|
| 34 |
+
By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
|
| 35 |
+
If `rng` is an int, it is used to seed the generator.
|
| 36 |
+
boundary_mode : {'nearest', 'wrap'}, optional
|
| 37 |
+
The blobs are created by smoothing and then thresholding an
|
| 38 |
+
array consisting of ones at seed positions. This mode determines which values are
|
| 39 |
+
filled in when the smoothing kernel overlaps the seed array's boundary.
|
| 40 |
+
|
| 41 |
+
'nearest' (`a a a a | a b c d | d d d d`)
|
| 42 |
+
By default, when applying the Gaussian filter, the seed array is extended by replicating the last
|
| 43 |
+
boundary value. This will increase the size of blobs whose seed or
|
| 44 |
+
center lies exactly on the edge.
|
| 45 |
+
|
| 46 |
+
'wrap' (`a b c d | a b c d | a b c d`)
|
| 47 |
+
The seed array is extended by wrapping around to the opposite edge.
|
| 48 |
+
The resulting blob array can be tiled and blobs will be contiguous and
|
| 49 |
+
have smooth edges across tile boundaries.
|
| 50 |
+
|
| 51 |
+
boundary_mode : str, default "nearest"
|
| 52 |
+
The `mode` parameter passed to the Gaussian filter.
|
| 53 |
+
Use "wrap" for periodic boundary conditions.
|
| 54 |
+
|
| 55 |
+
Returns
|
| 56 |
+
-------
|
| 57 |
+
blobs : ndarray of bools
|
| 58 |
+
Output binary image
|
| 59 |
+
|
| 60 |
+
Examples
|
| 61 |
+
--------
|
| 62 |
+
>>> from skimage import data
|
| 63 |
+
>>> data.binary_blobs(length=5, blob_size_fraction=0.2) # doctest: +SKIP
|
| 64 |
+
array([[ True, False, True, True, True],
|
| 65 |
+
[ True, True, True, False, True],
|
| 66 |
+
[False, True, False, True, True],
|
| 67 |
+
[ True, False, False, True, True],
|
| 68 |
+
[ True, False, False, False, True]])
|
| 69 |
+
>>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.1)
|
| 70 |
+
>>> # Finer structures
|
| 71 |
+
>>> blobs = data.binary_blobs(length=256, blob_size_fraction=0.05)
|
| 72 |
+
>>> # Blobs cover a smaller volume fraction of the image
|
| 73 |
+
>>> blobs = data.binary_blobs(length=256, volume_fraction=0.3)
|
| 74 |
+
"""
|
| 75 |
+
if boundary_mode not in {"nearest", "wrap"}:
|
| 76 |
+
raise ValueError(f"unsupported `boundary_mode`: {boundary_mode!r}")
|
| 77 |
+
|
| 78 |
+
blob_size = blob_size_fraction * length
|
| 79 |
+
if blob_size < 0.1:
|
| 80 |
+
clamped_size_fraction = 0.1 / length
|
| 81 |
+
clamped_blob_size = clamped_size_fraction * length
|
| 82 |
+
warnings.warn(
|
| 83 |
+
f"`{blob_size_fraction=}` together with `{length=}` would result in a blob "
|
| 84 |
+
f"size of {blob_size} pixels. Small blob sizes likely lead to unexpected "
|
| 85 |
+
f"results! "
|
| 86 |
+
f"Clamping to `blob_size_fraction={clamped_size_fraction}` and a blob size "
|
| 87 |
+
f"of {clamped_blob_size} pixels to avoid allocating excessive memory.",
|
| 88 |
+
category=RuntimeWarning,
|
| 89 |
+
stacklevel=2,
|
| 90 |
+
)
|
| 91 |
+
blob_size_fraction = clamped_size_fraction
|
| 92 |
+
|
| 93 |
+
rs = np.random.default_rng(rng)
|
| 94 |
+
shape = tuple([length] * n_dim)
|
| 95 |
+
mask = np.zeros(shape)
|
| 96 |
+
n_pts = max(int(1.0 / blob_size_fraction) ** n_dim, 1)
|
| 97 |
+
points = (length * rs.random((n_dim, n_pts))).astype(int)
|
| 98 |
+
mask[tuple(indices for indices in points)] = 1
|
| 99 |
+
mask = gaussian(
|
| 100 |
+
mask,
|
| 101 |
+
sigma=0.25 * length * blob_size_fraction,
|
| 102 |
+
preserve_range=False,
|
| 103 |
+
mode=boundary_mode,
|
| 104 |
+
)
|
| 105 |
+
threshold = np.percentile(mask, 100 * (1 - volume_fraction))
|
| 106 |
+
return np.logical_not(mask < threshold)
|
envs/kitoverlay/skimage/data/_fetchers.py
ADDED
|
@@ -0,0 +1,1271 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Standard test images.
|
| 2 |
+
|
| 3 |
+
For more images, see
|
| 4 |
+
|
| 5 |
+
- http://sipi.usc.edu/database/database.php
|
| 6 |
+
|
| 7 |
+
"""
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import shutil
|
| 11 |
+
|
| 12 |
+
from ..util.dtype import img_as_bool
|
| 13 |
+
from ._registry import registry, registry_urls
|
| 14 |
+
|
| 15 |
+
from .. import __version__
|
| 16 |
+
|
| 17 |
+
import os.path as osp
|
| 18 |
+
import os
|
| 19 |
+
|
| 20 |
+
_LEGACY_DATA_DIR = osp.dirname(__file__)
|
| 21 |
+
_DISTRIBUTION_DIR = osp.dirname(_LEGACY_DATA_DIR)
|
| 22 |
+
|
| 23 |
+
try:
|
| 24 |
+
from pooch import file_hash
|
| 25 |
+
except ModuleNotFoundError:
|
| 26 |
+
# Function taken from
|
| 27 |
+
# https://github.com/fatiando/pooch/blob/master/pooch/utils.py
|
| 28 |
+
def file_hash(fname, alg="sha256"):
|
| 29 |
+
"""
|
| 30 |
+
Calculate the hash of a given file.
|
| 31 |
+
Useful for checking if a file has changed or been corrupted.
|
| 32 |
+
Parameters
|
| 33 |
+
----------
|
| 34 |
+
fname : str
|
| 35 |
+
The name of the file.
|
| 36 |
+
alg : str
|
| 37 |
+
The type of the hashing algorithm
|
| 38 |
+
Returns
|
| 39 |
+
-------
|
| 40 |
+
hash : str
|
| 41 |
+
The hash of the file.
|
| 42 |
+
Examples
|
| 43 |
+
--------
|
| 44 |
+
>>> fname = "test-file-for-hash.txt"
|
| 45 |
+
>>> with open(fname, "w") as f:
|
| 46 |
+
... __ = f.write("content of the file")
|
| 47 |
+
>>> print(file_hash(fname))
|
| 48 |
+
0fc74468e6a9a829f103d069aeb2bb4f8646bad58bf146bb0e3379b759ec4a00
|
| 49 |
+
>>> import os
|
| 50 |
+
>>> os.remove(fname)
|
| 51 |
+
"""
|
| 52 |
+
import hashlib
|
| 53 |
+
|
| 54 |
+
if alg not in hashlib.algorithms_available:
|
| 55 |
+
raise ValueError(f'Algorithm \'{alg}\' not available in hashlib')
|
| 56 |
+
# Calculate the hash in chunks to avoid overloading the memory
|
| 57 |
+
chunksize = 65536
|
| 58 |
+
hasher = hashlib.new(alg)
|
| 59 |
+
with open(fname, "rb") as fin:
|
| 60 |
+
buff = fin.read(chunksize)
|
| 61 |
+
while buff:
|
| 62 |
+
hasher.update(buff)
|
| 63 |
+
buff = fin.read(chunksize)
|
| 64 |
+
return hasher.hexdigest()
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _has_hash(path, expected_hash):
|
| 68 |
+
"""Check if the provided path has the expected hash."""
|
| 69 |
+
if not osp.exists(path):
|
| 70 |
+
return False
|
| 71 |
+
return file_hash(path) == expected_hash
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _create_image_fetcher(prefix=None):
|
| 75 |
+
try:
|
| 76 |
+
import pooch
|
| 77 |
+
|
| 78 |
+
# older versions of Pooch don't have a __version__ attribute
|
| 79 |
+
if not hasattr(pooch, '__version__'):
|
| 80 |
+
retry = {}
|
| 81 |
+
else:
|
| 82 |
+
retry = {'retry_if_failed': 3}
|
| 83 |
+
except ImportError:
|
| 84 |
+
# Without pooch, fallback on the standard data directory
|
| 85 |
+
# which for now, includes a few limited data samples
|
| 86 |
+
return None, _LEGACY_DATA_DIR
|
| 87 |
+
|
| 88 |
+
# Pooch expects a `+` to exist in development versions.
|
| 89 |
+
# Since scikit-image doesn't follow that convention, we have to manually
|
| 90 |
+
# remove `.dev` with a `+` if it exists.
|
| 91 |
+
# This helps pooch understand that it should look in master
|
| 92 |
+
# to find the required files
|
| 93 |
+
if '+git' in __version__:
|
| 94 |
+
skimage_version_for_pooch = __version__.replace('.dev0+git', '+git')
|
| 95 |
+
else:
|
| 96 |
+
skimage_version_for_pooch = __version__.replace('.dev', '+')
|
| 97 |
+
|
| 98 |
+
if '+' in skimage_version_for_pooch:
|
| 99 |
+
if prefix is not None:
|
| 100 |
+
url = (
|
| 101 |
+
"https://github.com/scikit-image/scikit-image/raw/"
|
| 102 |
+
"{version}/tests/skimage/"
|
| 103 |
+
)
|
| 104 |
+
else:
|
| 105 |
+
url = (
|
| 106 |
+
"https://github.com/scikit-image/scikit-image/raw/"
|
| 107 |
+
"{version}/src/skimage/"
|
| 108 |
+
)
|
| 109 |
+
else:
|
| 110 |
+
if prefix is not None:
|
| 111 |
+
url = (
|
| 112 |
+
"https://github.com/scikit-image/scikit-image/raw/"
|
| 113 |
+
"v{version}/tests/skimage/"
|
| 114 |
+
)
|
| 115 |
+
else:
|
| 116 |
+
url = (
|
| 117 |
+
"https://github.com/scikit-image/scikit-image/raw/"
|
| 118 |
+
"v{version}/src/skimage/"
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
# Create a new friend to manage your sample data storage
|
| 122 |
+
image_fetcher = pooch.create(
|
| 123 |
+
# Pooch uses appdirs to select an appropriate directory for the cache
|
| 124 |
+
# on each platform.
|
| 125 |
+
# https://github.com/ActiveState/appdirs
|
| 126 |
+
# On linux this converges to
|
| 127 |
+
# '$HOME/.cache/scikit-image'
|
| 128 |
+
# With a version qualifier
|
| 129 |
+
path=pooch.os_cache("scikit-image"),
|
| 130 |
+
base_url=url,
|
| 131 |
+
version=skimage_version_for_pooch,
|
| 132 |
+
version_dev="main",
|
| 133 |
+
env="SKIMAGE_DATADIR",
|
| 134 |
+
registry=registry,
|
| 135 |
+
urls=registry_urls,
|
| 136 |
+
# Note: this should read `retry_if_failed=3,`, but we generate that
|
| 137 |
+
# dynamically at import time above, in case installed pooch is a less
|
| 138 |
+
# recent version
|
| 139 |
+
**retry,
|
| 140 |
+
)
|
| 141 |
+
|
| 142 |
+
data_dir = osp.join(str(image_fetcher.abspath), 'data')
|
| 143 |
+
return image_fetcher, data_dir
|
| 144 |
+
|
| 145 |
+
|
| 146 |
+
_image_fetcher, data_dir = _create_image_fetcher(prefix='tests')
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
def _skip_pytest_case_requiring_pooch(data_filename):
|
| 150 |
+
"""If a test case is calling pooch, skip it.
|
| 151 |
+
|
| 152 |
+
This running the test suite in environments without internet
|
| 153 |
+
access, skipping only the tests that try to fetch external data.
|
| 154 |
+
"""
|
| 155 |
+
|
| 156 |
+
# Check if pytest is currently running.
|
| 157 |
+
# Packagers might use pytest to run the tests suite, but may not
|
| 158 |
+
# want to run it online with pooch as a dependency.
|
| 159 |
+
# As such, we will avoid failing the test, and silently skipping it.
|
| 160 |
+
if 'PYTEST_CURRENT_TEST' in os.environ:
|
| 161 |
+
# https://docs.pytest.org/en/latest/example/simple.html#pytest-current-test-environment-variable
|
| 162 |
+
import pytest
|
| 163 |
+
|
| 164 |
+
# Pytest skip raises an exception that allows the
|
| 165 |
+
# tests to be skipped
|
| 166 |
+
pytest.skip(f'Unable to download {data_filename}', allow_module_level=True)
|
| 167 |
+
|
| 168 |
+
|
| 169 |
+
def _ensure_cache_dir(*, target_dir):
|
| 170 |
+
"""Prepare local cache directory if it doesn't exist already.
|
| 171 |
+
|
| 172 |
+
Creates::
|
| 173 |
+
|
| 174 |
+
/path/to/target_dir/
|
| 175 |
+
└─ data/
|
| 176 |
+
└─ README.txt
|
| 177 |
+
"""
|
| 178 |
+
os.makedirs(osp.join(target_dir, "data"), exist_ok=True)
|
| 179 |
+
readme_src = osp.join(_DISTRIBUTION_DIR, "data/README.txt")
|
| 180 |
+
readme_dest = osp.join(target_dir, "data/README.txt")
|
| 181 |
+
if not osp.exists(readme_dest):
|
| 182 |
+
shutil.copy2(readme_src, readme_dest)
|
| 183 |
+
|
| 184 |
+
|
| 185 |
+
def _fetch(data_filename, prefix=None):
|
| 186 |
+
"""Fetch a given data file from either the local cache or the repository.
|
| 187 |
+
|
| 188 |
+
This function provides the path location of the data file given
|
| 189 |
+
its name in the scikit-image repository. If a data file is not included in the
|
| 190 |
+
distribution and pooch is available, it is downloaded and cached.
|
| 191 |
+
|
| 192 |
+
Parameters
|
| 193 |
+
----------
|
| 194 |
+
data_filename : str
|
| 195 |
+
Name of the file in the scikit-image repository. e.g.
|
| 196 |
+
'restoration/camera_rl.npy'.
|
| 197 |
+
|
| 198 |
+
Returns
|
| 199 |
+
-------
|
| 200 |
+
file_path : str
|
| 201 |
+
Path of the local file.
|
| 202 |
+
|
| 203 |
+
Raises
|
| 204 |
+
------
|
| 205 |
+
KeyError:
|
| 206 |
+
If the filename is not known to the scikit-image distribution.
|
| 207 |
+
|
| 208 |
+
ModuleNotFoundError:
|
| 209 |
+
If the filename is known to the scikit-image distribution but pooch
|
| 210 |
+
is not installed.
|
| 211 |
+
|
| 212 |
+
ConnectionError:
|
| 213 |
+
If scikit-image is unable to connect to the internet but the
|
| 214 |
+
dataset has not been downloaded yet.
|
| 215 |
+
"""
|
| 216 |
+
if prefix is not None:
|
| 217 |
+
return osp.join("tests", "skimage", data_filename)
|
| 218 |
+
|
| 219 |
+
expected_hash = registry[data_filename]
|
| 220 |
+
if _image_fetcher is None:
|
| 221 |
+
cache_dir = osp.dirname(data_dir)
|
| 222 |
+
else:
|
| 223 |
+
cache_dir = str(_image_fetcher.abspath)
|
| 224 |
+
|
| 225 |
+
# Case 1: the file is already cached in `data_cache_dir`
|
| 226 |
+
cached_file_path = osp.join(cache_dir, data_filename)
|
| 227 |
+
if _has_hash(cached_file_path, expected_hash):
|
| 228 |
+
# Nothing to be done, file is where it is expected to be
|
| 229 |
+
return cached_file_path
|
| 230 |
+
|
| 231 |
+
# Case 2: file is present in `legacy_data_dir`
|
| 232 |
+
legacy_file_path = osp.join(_DISTRIBUTION_DIR, data_filename)
|
| 233 |
+
if _has_hash(legacy_file_path, expected_hash):
|
| 234 |
+
return legacy_file_path
|
| 235 |
+
|
| 236 |
+
# Case 3: file is not present locally
|
| 237 |
+
if _image_fetcher is None:
|
| 238 |
+
_skip_pytest_case_requiring_pooch(data_filename)
|
| 239 |
+
raise ModuleNotFoundError(
|
| 240 |
+
"The requested file is part of the scikit-image distribution, "
|
| 241 |
+
"but requires the installation of an optional dependency, pooch. "
|
| 242 |
+
"To install pooch, use your preferred python package manager. "
|
| 243 |
+
"Follow installation instruction found at "
|
| 244 |
+
"https://scikit-image.org/docs/stable/user_guide/install.html"
|
| 245 |
+
)
|
| 246 |
+
# Download the data with pooch which caches it automatically
|
| 247 |
+
_ensure_cache_dir(target_dir=cache_dir)
|
| 248 |
+
try:
|
| 249 |
+
cached_file_path = _image_fetcher.fetch(data_filename)
|
| 250 |
+
return cached_file_path
|
| 251 |
+
except ConnectionError as err:
|
| 252 |
+
_skip_pytest_case_requiring_pooch(data_filename)
|
| 253 |
+
# If we decide in the future to suppress the underlying 'requests'
|
| 254 |
+
# error, change this to `raise ... from None`. See PEP 3134.
|
| 255 |
+
raise ConnectionError(
|
| 256 |
+
'Tried to download a scikit-image dataset, but no internet '
|
| 257 |
+
'connection is available. To avoid this message in the '
|
| 258 |
+
'future, try `skimage.data.download_all()` when you are '
|
| 259 |
+
'connected to the internet.'
|
| 260 |
+
) from err
|
| 261 |
+
|
| 262 |
+
|
| 263 |
+
def download_all(directory=None):
|
| 264 |
+
"""Download all datasets for use with scikit-image offline.
|
| 265 |
+
|
| 266 |
+
Scikit-image datasets are no longer shipped with the library by default.
|
| 267 |
+
This allows us to use higher quality datasets, while keeping the
|
| 268 |
+
library download size small.
|
| 269 |
+
|
| 270 |
+
This function requires the installation of an optional dependency, pooch,
|
| 271 |
+
to download the full dataset. Follow installation instruction found at
|
| 272 |
+
|
| 273 |
+
https://scikit-image.org/docs/stable/user_guide/install.html
|
| 274 |
+
|
| 275 |
+
Call this function to download all sample images making them available
|
| 276 |
+
offline on your machine.
|
| 277 |
+
|
| 278 |
+
Parameters
|
| 279 |
+
----------
|
| 280 |
+
directory : path-like, optional
|
| 281 |
+
The directory where the dataset should be stored.
|
| 282 |
+
|
| 283 |
+
Raises
|
| 284 |
+
------
|
| 285 |
+
ModuleNotFoundError:
|
| 286 |
+
If pooch is not install, this error will be raised.
|
| 287 |
+
|
| 288 |
+
Notes
|
| 289 |
+
-----
|
| 290 |
+
scikit-image will only search for images stored in the default directory.
|
| 291 |
+
Only specify the directory if you wish to download the images to your own
|
| 292 |
+
folder for a particular reason. You can access the location of the default
|
| 293 |
+
data directory by inspecting the variable ``skimage.data.data_dir``.
|
| 294 |
+
"""
|
| 295 |
+
|
| 296 |
+
if _image_fetcher is None:
|
| 297 |
+
raise ModuleNotFoundError(
|
| 298 |
+
"To download all package data, scikit-image needs an optional "
|
| 299 |
+
"dependency, pooch."
|
| 300 |
+
"To install pooch, follow our installation instructions found at "
|
| 301 |
+
"https://scikit-image.org/docs/stable/user_guide/install.html"
|
| 302 |
+
)
|
| 303 |
+
# Consider moving this kind of logic to Pooch
|
| 304 |
+
old_dir = _image_fetcher.path
|
| 305 |
+
try:
|
| 306 |
+
if directory is not None:
|
| 307 |
+
directory = osp.expanduser(directory)
|
| 308 |
+
_image_fetcher.path = directory
|
| 309 |
+
_ensure_cache_dir(target_dir=_image_fetcher.path)
|
| 310 |
+
|
| 311 |
+
for data_filename in _image_fetcher.registry:
|
| 312 |
+
file_path = _fetch(data_filename)
|
| 313 |
+
|
| 314 |
+
# Copy to `directory` or implicit cache if it is not already there
|
| 315 |
+
if not file_path.startswith(str(_image_fetcher.path)):
|
| 316 |
+
dest_path = osp.join(_image_fetcher.path, data_filename)
|
| 317 |
+
os.makedirs(osp.dirname(dest_path), exist_ok=True)
|
| 318 |
+
shutil.copy2(file_path, dest_path)
|
| 319 |
+
finally:
|
| 320 |
+
_image_fetcher.path = old_dir
|
| 321 |
+
|
| 322 |
+
|
| 323 |
+
def lbp_frontal_face_cascade_filename():
|
| 324 |
+
"""Return the path to the XML file containing the weak classifier cascade.
|
| 325 |
+
|
| 326 |
+
These classifiers were trained using LBP features. The file is part
|
| 327 |
+
of the OpenCV repository [1]_.
|
| 328 |
+
|
| 329 |
+
References
|
| 330 |
+
----------
|
| 331 |
+
.. [1] OpenCV lbpcascade trained files
|
| 332 |
+
https://github.com/opencv/opencv/tree/master/data/lbpcascades
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
return _fetch('data/lbpcascade_frontalface_opencv.xml')
|
| 336 |
+
|
| 337 |
+
|
| 338 |
+
def _load(f, as_gray=False):
|
| 339 |
+
"""Load an image file located in the data directory.
|
| 340 |
+
|
| 341 |
+
Parameters
|
| 342 |
+
----------
|
| 343 |
+
f : string
|
| 344 |
+
File name.
|
| 345 |
+
as_gray : bool, optional
|
| 346 |
+
Whether to convert the image to grayscale.
|
| 347 |
+
|
| 348 |
+
Returns
|
| 349 |
+
-------
|
| 350 |
+
img : ndarray
|
| 351 |
+
Image loaded from ``skimage.data_dir``.
|
| 352 |
+
"""
|
| 353 |
+
# importing io is quite slow since it scans all the backends
|
| 354 |
+
# we lazy import it here
|
| 355 |
+
from ..io import imread
|
| 356 |
+
|
| 357 |
+
return imread(_fetch(f), as_gray=as_gray)
|
| 358 |
+
|
| 359 |
+
|
| 360 |
+
def camera():
|
| 361 |
+
"""Gray-level "camera" image.
|
| 362 |
+
|
| 363 |
+
Can be used for segmentation and denoising examples.
|
| 364 |
+
|
| 365 |
+
Returns
|
| 366 |
+
-------
|
| 367 |
+
camera : (512, 512) uint8 ndarray
|
| 368 |
+
Camera image.
|
| 369 |
+
|
| 370 |
+
Notes
|
| 371 |
+
-----
|
| 372 |
+
No copyright restrictions. CC0 by the photographer (Lav Varshney).
|
| 373 |
+
|
| 374 |
+
.. versionchanged:: 0.18
|
| 375 |
+
This image was replaced due to copyright restrictions. For more
|
| 376 |
+
information, please see [1]_.
|
| 377 |
+
|
| 378 |
+
References
|
| 379 |
+
----------
|
| 380 |
+
.. [1] https://github.com/scikit-image/scikit-image/issues/3927
|
| 381 |
+
"""
|
| 382 |
+
return _load("data/camera.png")
|
| 383 |
+
|
| 384 |
+
|
| 385 |
+
def eagle():
|
| 386 |
+
"""A golden eagle.
|
| 387 |
+
|
| 388 |
+
Suitable for examples on segmentation, Hough transforms, and corner
|
| 389 |
+
detection.
|
| 390 |
+
|
| 391 |
+
Notes
|
| 392 |
+
-----
|
| 393 |
+
No copyright restrictions. CC0 by the photographer (Dayane Machado).
|
| 394 |
+
|
| 395 |
+
Returns
|
| 396 |
+
-------
|
| 397 |
+
eagle : (2019, 1826) uint8 ndarray
|
| 398 |
+
Eagle image.
|
| 399 |
+
"""
|
| 400 |
+
return _load("data/eagle.png")
|
| 401 |
+
|
| 402 |
+
|
| 403 |
+
def astronaut():
|
| 404 |
+
"""Color image of the astronaut Eileen Collins.
|
| 405 |
+
|
| 406 |
+
Photograph of Eileen Collins, an American astronaut. She was selected
|
| 407 |
+
as an astronaut in 1992 and first piloted the space shuttle STS-63 in
|
| 408 |
+
1995. She retired in 2006 after spending a total of 38 days, 8 hours
|
| 409 |
+
and 10 minutes in outer space.
|
| 410 |
+
|
| 411 |
+
This image was downloaded from the NASA Great Images database
|
| 412 |
+
<https://flic.kr/p/r9qvLn>`__.
|
| 413 |
+
|
| 414 |
+
No known copyright restrictions, released into the public domain.
|
| 415 |
+
|
| 416 |
+
Returns
|
| 417 |
+
-------
|
| 418 |
+
astronaut : (512, 512, 3) uint8 ndarray
|
| 419 |
+
Astronaut image.
|
| 420 |
+
"""
|
| 421 |
+
|
| 422 |
+
return _load("data/astronaut.png")
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def brick():
|
| 426 |
+
"""Brick wall.
|
| 427 |
+
|
| 428 |
+
Returns
|
| 429 |
+
-------
|
| 430 |
+
brick : (512, 512) uint8 image
|
| 431 |
+
A small section of a brick wall.
|
| 432 |
+
|
| 433 |
+
Notes
|
| 434 |
+
-----
|
| 435 |
+
The original image was downloaded from
|
| 436 |
+
`CC0Textures <https://cc0textures.com/view.php?tex=Bricks25>`_ and licensed
|
| 437 |
+
under the Creative Commons CC0 License.
|
| 438 |
+
|
| 439 |
+
A perspective transform was then applied to the image, prior to
|
| 440 |
+
rotating it by 90 degrees, cropping and scaling it to obtain the final
|
| 441 |
+
image.
|
| 442 |
+
"""
|
| 443 |
+
|
| 444 |
+
"""
|
| 445 |
+
The following code was used to obtain the final image.
|
| 446 |
+
|
| 447 |
+
>>> import sys; print(sys.version)
|
| 448 |
+
>>> import platform; print(platform.platform())
|
| 449 |
+
>>> import skimage; print(f'scikit-image version: {skimage.__version__}')
|
| 450 |
+
>>> import numpy; print(f'numpy version: {numpy.__version__}')
|
| 451 |
+
>>> import imageio; print(f'imageio version {imageio.__version__}')
|
| 452 |
+
3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
|
| 453 |
+
[GCC 7.3.0]
|
| 454 |
+
Linux-5.0.0-20-generic-x86_64-with-debian-buster-sid
|
| 455 |
+
scikit-image version: 0.16.dev0
|
| 456 |
+
numpy version: 1.16.4
|
| 457 |
+
imageio version 2.4.1
|
| 458 |
+
|
| 459 |
+
>>> import requests
|
| 460 |
+
>>> import zipfile
|
| 461 |
+
>>> url = 'https://cdn.struffelproductions.com/file/cc0textures/Bricks25/%5B2K%5DBricks25.zip'
|
| 462 |
+
>>> r = requests.get(url)
|
| 463 |
+
>>> with open('[2K]Bricks25.zip', 'bw') as f:
|
| 464 |
+
... f.write(r.content)
|
| 465 |
+
>>> with zipfile.ZipFile('[2K]Bricks25.zip') as z:
|
| 466 |
+
... z.extract('Bricks25_col.jpg')
|
| 467 |
+
|
| 468 |
+
>>> from numpy.linalg import inv
|
| 469 |
+
>>> from skimage.transform import rescale, warp, rotate
|
| 470 |
+
>>> from skimage.color import rgb2gray
|
| 471 |
+
>>> from imageio import imread, imwrite
|
| 472 |
+
>>> from skimage import img_as_ubyte
|
| 473 |
+
>>> import numpy as np
|
| 474 |
+
|
| 475 |
+
|
| 476 |
+
>>> # Obtained playing around with GIMP 2.10 with their perspective tool
|
| 477 |
+
>>> H = inv(np.asarray([[ 0.54764, -0.00219, 0],
|
| 478 |
+
... [-0.12822, 0.54688, 0],
|
| 479 |
+
... [-0.00022, 0, 1]]))
|
| 480 |
+
|
| 481 |
+
|
| 482 |
+
>>> brick_orig = imread('Bricks25_col.jpg')
|
| 483 |
+
>>> brick = warp(brick_orig, H)
|
| 484 |
+
>>> brick = rescale(brick[:1024, :1024], (0.5, 0.5, 1))
|
| 485 |
+
>>> brick = rotate(brick, -90)
|
| 486 |
+
>>> imwrite('brick.png', img_as_ubyte(rgb2gray(brick)))
|
| 487 |
+
"""
|
| 488 |
+
return _load("data/brick.png", as_gray=True)
|
| 489 |
+
|
| 490 |
+
|
| 491 |
+
def grass():
|
| 492 |
+
"""Grass.
|
| 493 |
+
|
| 494 |
+
Returns
|
| 495 |
+
-------
|
| 496 |
+
grass : (512, 512) uint8 image
|
| 497 |
+
Some grass.
|
| 498 |
+
|
| 499 |
+
Notes
|
| 500 |
+
-----
|
| 501 |
+
The original image was downloaded from
|
| 502 |
+
`DeviantArt <https://www.deviantart.com/linolafett/art/Grass-01-434853879>`__
|
| 503 |
+
and licensed under the Creative Commons CC0 License.
|
| 504 |
+
|
| 505 |
+
The downloaded image was cropped to include a region of ``(512, 512)``
|
| 506 |
+
pixels around the top left corner, converted to grayscale, then to uint8
|
| 507 |
+
prior to saving the result in PNG format.
|
| 508 |
+
|
| 509 |
+
"""
|
| 510 |
+
|
| 511 |
+
"""
|
| 512 |
+
The following code was used to obtain the final image.
|
| 513 |
+
|
| 514 |
+
>>> import sys; print(sys.version)
|
| 515 |
+
>>> import platform; print(platform.platform())
|
| 516 |
+
>>> import skimage; print(f'scikit-image version: {skimage.__version__}')
|
| 517 |
+
>>> import numpy; print(f'numpy version: {numpy.__version__}')
|
| 518 |
+
>>> import imageio; print(f'imageio version {imageio.__version__}')
|
| 519 |
+
3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
|
| 520 |
+
[GCC 7.3.0]
|
| 521 |
+
Linux-5.0.0-20-generic-x86_64-with-debian-buster-sid
|
| 522 |
+
scikit-image version: 0.16.dev0
|
| 523 |
+
numpy version: 1.16.4
|
| 524 |
+
imageio version 2.4.1
|
| 525 |
+
|
| 526 |
+
>>> import requests
|
| 527 |
+
>>> import zipfile
|
| 528 |
+
>>> url = 'https://images-wixmp-ed30a86b8c4ca887773594c2.wixmp.com/f/a407467e-4ff0-49f1-923f-c9e388e84612/d76wfef-2878b78d-5dce-43f9-be36-26ec9bc0df3b.jpg?token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiJ1cm46YXBwOjdlMGQxODg5ODIyNjQzNzNhNWYwZDQxNWVhMGQyNmUwIiwiaXNzIjoidXJuOmFwcDo3ZTBkMTg4OTgyMjY0MzczYTVmMGQ0MTVlYTBkMjZlMCIsIm9iaiI6W1t7InBhdGgiOiJcL2ZcL2E0MDc0NjdlLTRmZjAtNDlmMS05MjNmLWM5ZTM4OGU4NDYxMlwvZDc2d2ZlZi0yODc4Yjc4ZC01ZGNlLTQzZjktYmUzNi0yNmVjOWJjMGRmM2IuanBnIn1dXSwiYXVkIjpbInVybjpzZXJ2aWNlOmZpbGUuZG93bmxvYWQiXX0.98hIcOTCqXWQ67Ec5bM5eovKEn2p91mWB3uedH61ynI'
|
| 529 |
+
>>> r = requests.get(url)
|
| 530 |
+
>>> with open('grass_orig.jpg', 'bw') as f:
|
| 531 |
+
... f.write(r.content)
|
| 532 |
+
>>> grass_orig = imageio.imread('grass_orig.jpg')
|
| 533 |
+
>>> grass = skimage.img_as_ubyte(skimage.color.rgb2gray(grass_orig[:512, :512]))
|
| 534 |
+
>>> imageio.imwrite('grass.png', grass)
|
| 535 |
+
"""
|
| 536 |
+
return _load("data/grass.png", as_gray=True)
|
| 537 |
+
|
| 538 |
+
|
| 539 |
+
def gravel():
|
| 540 |
+
"""Gravel
|
| 541 |
+
|
| 542 |
+
Returns
|
| 543 |
+
-------
|
| 544 |
+
gravel : (512, 512) uint8 image
|
| 545 |
+
Grayscale gravel sample.
|
| 546 |
+
|
| 547 |
+
Notes
|
| 548 |
+
-----
|
| 549 |
+
The original image was downloaded from
|
| 550 |
+
`CC0Textures <https://cc0textures.com/view.php?tex=Gravel04>`__ and
|
| 551 |
+
licensed under the Creative Commons CC0 License.
|
| 552 |
+
|
| 553 |
+
The downloaded image was then rescaled to ``(1024, 1024)``, then the
|
| 554 |
+
top left ``(512, 512)`` pixel region was cropped prior to converting the
|
| 555 |
+
image to grayscale and uint8 data type. The result was saved using the
|
| 556 |
+
PNG format.
|
| 557 |
+
"""
|
| 558 |
+
|
| 559 |
+
"""
|
| 560 |
+
The following code was used to obtain the final image.
|
| 561 |
+
|
| 562 |
+
>>> import sys; print(sys.version)
|
| 563 |
+
>>> import platform; print(platform.platform())
|
| 564 |
+
>>> import skimage; print(f'scikit-image version: {skimage.__version__}')
|
| 565 |
+
>>> import numpy; print(f'numpy version: {numpy.__version__}')
|
| 566 |
+
>>> import imageio; print(f'imageio version {imageio.__version__}')
|
| 567 |
+
3.7.3 | packaged by conda-forge | (default, Jul 1 2019, 21:52:21)
|
| 568 |
+
[GCC 7.3.0]
|
| 569 |
+
Linux-5.0.0-20-generic-x86_64-with-debian-buster-sid
|
| 570 |
+
scikit-image version: 0.16.dev0
|
| 571 |
+
numpy version: 1.16.4
|
| 572 |
+
imageio version 2.4.1
|
| 573 |
+
|
| 574 |
+
>>> import requests
|
| 575 |
+
>>> import zipfile
|
| 576 |
+
|
| 577 |
+
>>> url = 'https://cdn.struffelproductions.com/file/cc0textures/Gravel04/%5B2K%5DGravel04.zip'
|
| 578 |
+
>>> r = requests.get(url)
|
| 579 |
+
>>> with open('[2K]Gravel04.zip', 'bw') as f:
|
| 580 |
+
... f.write(r.content)
|
| 581 |
+
|
| 582 |
+
>>> with zipfile.ZipFile('[2K]Gravel04.zip') as z:
|
| 583 |
+
... z.extract('Gravel04_col.jpg')
|
| 584 |
+
|
| 585 |
+
>>> from skimage.transform import resize
|
| 586 |
+
>>> gravel_orig = imageio.imread('Gravel04_col.jpg')
|
| 587 |
+
>>> gravel = resize(gravel_orig, (1024, 1024))
|
| 588 |
+
>>> gravel = skimage.img_as_ubyte(skimage.color.rgb2gray(gravel[:512, :512]))
|
| 589 |
+
>>> imageio.imwrite('gravel.png', gravel)
|
| 590 |
+
"""
|
| 591 |
+
return _load("data/gravel.png", as_gray=True)
|
| 592 |
+
|
| 593 |
+
|
| 594 |
+
def text():
|
| 595 |
+
"""Gray-level "text" image used for corner detection.
|
| 596 |
+
|
| 597 |
+
Notes
|
| 598 |
+
-----
|
| 599 |
+
This image was downloaded from Wikipedia
|
| 600 |
+
<https://en.wikipedia.org/wiki/File:Corner.png>`__.
|
| 601 |
+
|
| 602 |
+
No known copyright restrictions, released into the public domain.
|
| 603 |
+
|
| 604 |
+
Returns
|
| 605 |
+
-------
|
| 606 |
+
text : (172, 448) uint8 ndarray
|
| 607 |
+
Text image.
|
| 608 |
+
"""
|
| 609 |
+
|
| 610 |
+
return _load("data/text.png")
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
def checkerboard():
|
| 614 |
+
"""Checkerboard image.
|
| 615 |
+
|
| 616 |
+
Checkerboards are often used in image calibration, since the
|
| 617 |
+
corner-points are easy to locate. Because of the many parallel
|
| 618 |
+
edges, they also visualise distortions particularly well.
|
| 619 |
+
|
| 620 |
+
Returns
|
| 621 |
+
-------
|
| 622 |
+
checkerboard : (200, 200) uint8 ndarray
|
| 623 |
+
Checkerboard image.
|
| 624 |
+
"""
|
| 625 |
+
return _load("data/chessboard_GRAY.png")
|
| 626 |
+
|
| 627 |
+
|
| 628 |
+
def cells3d():
|
| 629 |
+
"""3D fluorescence microscopy image of cells.
|
| 630 |
+
|
| 631 |
+
The returned data is a 3D multichannel array with dimensions provided in
|
| 632 |
+
``(z, c, y, x)`` order. Each voxel has a size of ``(0.29 0.26 0.26)``
|
| 633 |
+
micrometer. Channel 0 contains cell membranes, channel 1 contains nuclei.
|
| 634 |
+
|
| 635 |
+
Returns
|
| 636 |
+
-------
|
| 637 |
+
cells3d: (60, 2, 256, 256) uint16 ndarray
|
| 638 |
+
The volumetric images of cells taken with an optical microscope.
|
| 639 |
+
|
| 640 |
+
Notes
|
| 641 |
+
-----
|
| 642 |
+
The data for this was provided by the Allen Institute for Cell Science.
|
| 643 |
+
|
| 644 |
+
It has been downsampled by a factor of 4 in the row and column dimensions
|
| 645 |
+
to reduce computational time.
|
| 646 |
+
|
| 647 |
+
The microscope reports the following voxel spacing in microns:
|
| 648 |
+
|
| 649 |
+
* Original voxel size is ``(0.290, 0.065, 0.065)``.
|
| 650 |
+
* Scaling factor is ``(1, 4, 4)`` in each dimension.
|
| 651 |
+
* After rescaling the voxel size is ``(0.29 0.26 0.26)``.
|
| 652 |
+
"""
|
| 653 |
+
|
| 654 |
+
return _load("data/cells3d.tif")
|
| 655 |
+
|
| 656 |
+
|
| 657 |
+
def human_mitosis():
|
| 658 |
+
"""Image of human cells undergoing mitosis.
|
| 659 |
+
|
| 660 |
+
Returns
|
| 661 |
+
-------
|
| 662 |
+
human_mitosis: (512, 512) uint8 ndarray
|
| 663 |
+
Data of human cells undergoing mitosis taken during the preparation
|
| 664 |
+
of the manuscript in [1]_.
|
| 665 |
+
|
| 666 |
+
Notes
|
| 667 |
+
-----
|
| 668 |
+
Copyright David Root. Licensed under CC-0 [2]_.
|
| 669 |
+
|
| 670 |
+
References
|
| 671 |
+
----------
|
| 672 |
+
.. [1] Moffat J, Grueneberg DA, Yang X, Kim SY, Kloepfer AM, Hinkle G,
|
| 673 |
+
Piqani B, Eisenhaure TM, Luo B, Grenier JK, Carpenter AE, Foo SY,
|
| 674 |
+
Stewart SA, Stockwell BR, Hacohen N, Hahn WC, Lander ES,
|
| 675 |
+
Sabatini DM, Root DE (2006) A lentiviral RNAi library for human and
|
| 676 |
+
mouse genes applied to an arrayed viral high-content screen. Cell,
|
| 677 |
+
124(6):1283-98 / :DOI: `10.1016/j.cell.2006.01.040` PMID 16564017
|
| 678 |
+
|
| 679 |
+
.. [2] GitHub licensing discussion
|
| 680 |
+
https://github.com/CellProfiler/examples/issues/41
|
| 681 |
+
|
| 682 |
+
"""
|
| 683 |
+
return _load('data/mitosis.tif')
|
| 684 |
+
|
| 685 |
+
|
| 686 |
+
def cell():
|
| 687 |
+
"""Cell floating in saline.
|
| 688 |
+
|
| 689 |
+
This is a quantitative phase image retrieved from a digital hologram using
|
| 690 |
+
the Python library ``qpformat``. The image shows a cell with high phase
|
| 691 |
+
value, above the background phase.
|
| 692 |
+
|
| 693 |
+
Because of a banding pattern artifact in the background, this image is a
|
| 694 |
+
good test of thresholding algorithms. The pixel spacing is 0.107 µm.
|
| 695 |
+
|
| 696 |
+
These data were part of a comparison between several refractive index
|
| 697 |
+
retrieval techniques for spherical objects as part of [1]_.
|
| 698 |
+
|
| 699 |
+
This image is CC0, dedicated to the public domain. You may copy, modify, or
|
| 700 |
+
distribute it without asking permission.
|
| 701 |
+
|
| 702 |
+
Returns
|
| 703 |
+
-------
|
| 704 |
+
cell : (660, 550) uint8 array
|
| 705 |
+
Image of a cell.
|
| 706 |
+
|
| 707 |
+
References
|
| 708 |
+
----------
|
| 709 |
+
.. [1] Paul Müller, Mirjam Schürmann, Salvatore Girardo, Gheorghe Cojoc,
|
| 710 |
+
and Jochen Guck. "Accurate evaluation of size and refractive index
|
| 711 |
+
for spherical objects in quantitative phase imaging." Optics Express
|
| 712 |
+
26(8): 10729-10743 (2018). :DOI:`10.1364/OE.26.010729`
|
| 713 |
+
"""
|
| 714 |
+
return _load('data/cell.png')
|
| 715 |
+
|
| 716 |
+
|
| 717 |
+
def coins():
|
| 718 |
+
"""Greek coins from Pompeii.
|
| 719 |
+
|
| 720 |
+
This image shows several coins outlined against a gray background.
|
| 721 |
+
It is especially useful in, e.g. segmentation tests, where
|
| 722 |
+
individual objects need to be identified against a background.
|
| 723 |
+
The background shares enough grey levels with the coins that a
|
| 724 |
+
simple segmentation is not sufficient.
|
| 725 |
+
|
| 726 |
+
Notes
|
| 727 |
+
-----
|
| 728 |
+
This image was downloaded from the
|
| 729 |
+
`Brooklyn Museum Collection
|
| 730 |
+
<https://www.brooklynmuseum.org/opencollection/archives/image/51611>`__.
|
| 731 |
+
|
| 732 |
+
No known copyright restrictions.
|
| 733 |
+
|
| 734 |
+
Returns
|
| 735 |
+
-------
|
| 736 |
+
coins : (303, 384) uint8 ndarray
|
| 737 |
+
Coins image.
|
| 738 |
+
"""
|
| 739 |
+
return _load("data/coins.png")
|
| 740 |
+
|
| 741 |
+
|
| 742 |
+
def kidney():
|
| 743 |
+
"""Mouse kidney tissue.
|
| 744 |
+
|
| 745 |
+
This biological tissue on a pre-prepared slide was imaged with confocal
|
| 746 |
+
fluorescence microscopy (Nikon C1 inverted microscope).
|
| 747 |
+
Image shape is (16, 512, 512, 3). That is 512x512 pixels in X-Y,
|
| 748 |
+
16 image slices in Z, and 3 color channels
|
| 749 |
+
(emission wavelengths 450nm, 515nm, and 605nm, respectively).
|
| 750 |
+
Real-space voxel size is 1.24 microns in X-Y, and 1.25 microns in Z.
|
| 751 |
+
Data type is unsigned 16-bit integers.
|
| 752 |
+
|
| 753 |
+
Notes
|
| 754 |
+
-----
|
| 755 |
+
This image was acquired by Genevieve Buckley at Monasoh Micro Imaging in
|
| 756 |
+
2018.
|
| 757 |
+
License: CC0
|
| 758 |
+
|
| 759 |
+
Returns
|
| 760 |
+
-------
|
| 761 |
+
kidney : (16, 512, 512, 3) uint16 ndarray
|
| 762 |
+
Kidney 3D multichannel image.
|
| 763 |
+
"""
|
| 764 |
+
return _load("data/kidney.tif")
|
| 765 |
+
|
| 766 |
+
|
| 767 |
+
def lily():
|
| 768 |
+
"""Lily of the valley plant stem.
|
| 769 |
+
|
| 770 |
+
This plant stem on a pre-prepared slide was imaged with confocal
|
| 771 |
+
fluorescence microscopy (Nikon C1 inverted microscope).
|
| 772 |
+
Image shape is (922, 922, 4). That is 922x922 pixels in X-Y,
|
| 773 |
+
with 4 color channels.
|
| 774 |
+
Real-space voxel size is 1.24 microns in X-Y.
|
| 775 |
+
Data type is unsigned 16-bit integers.
|
| 776 |
+
|
| 777 |
+
Notes
|
| 778 |
+
-----
|
| 779 |
+
This image was acquired by Genevieve Buckley at Monasoh Micro Imaging in
|
| 780 |
+
2018.
|
| 781 |
+
License: CC0
|
| 782 |
+
|
| 783 |
+
Returns
|
| 784 |
+
-------
|
| 785 |
+
lily : (922, 922, 4) uint16 ndarray
|
| 786 |
+
Lily 2D multichannel image.
|
| 787 |
+
"""
|
| 788 |
+
return _load("data/lily.tif")
|
| 789 |
+
|
| 790 |
+
|
| 791 |
+
def logo():
|
| 792 |
+
"""Scikit-image logo, a RGBA image.
|
| 793 |
+
|
| 794 |
+
Returns
|
| 795 |
+
-------
|
| 796 |
+
logo : (500, 500, 4) uint8 ndarray
|
| 797 |
+
Logo image.
|
| 798 |
+
"""
|
| 799 |
+
return _load("data/logo.png")
|
| 800 |
+
|
| 801 |
+
|
| 802 |
+
def microaneurysms():
|
| 803 |
+
"""Gray-level "microaneurysms" image.
|
| 804 |
+
|
| 805 |
+
Detail from an image of the retina (green channel).
|
| 806 |
+
The image is a crop of image 07_dr.JPG from the
|
| 807 |
+
High-Resolution Fundus (HRF) Image Database:
|
| 808 |
+
https://www5.cs.fau.de/research/data/fundus-images/
|
| 809 |
+
|
| 810 |
+
Notes
|
| 811 |
+
-----
|
| 812 |
+
No copyright restrictions. CC0 given by owner (Andreas Maier).
|
| 813 |
+
|
| 814 |
+
Returns
|
| 815 |
+
-------
|
| 816 |
+
microaneurysms : (102, 102) uint8 ndarray
|
| 817 |
+
Retina image with lesions.
|
| 818 |
+
|
| 819 |
+
References
|
| 820 |
+
----------
|
| 821 |
+
.. [1] Budai, A., Bock, R, Maier, A., Hornegger, J.,
|
| 822 |
+
Michelson, G. (2013). Robust Vessel Segmentation in Fundus
|
| 823 |
+
Images. International Journal of Biomedical Imaging, vol. 2013,
|
| 824 |
+
2013.
|
| 825 |
+
:DOI:`10.1155/2013/154860`
|
| 826 |
+
"""
|
| 827 |
+
return _load("data/microaneurysms.png")
|
| 828 |
+
|
| 829 |
+
|
| 830 |
+
def moon():
|
| 831 |
+
"""Surface of the moon.
|
| 832 |
+
|
| 833 |
+
This low-contrast image of the surface of the moon is useful for
|
| 834 |
+
illustrating histogram equalization and contrast stretching.
|
| 835 |
+
|
| 836 |
+
Returns
|
| 837 |
+
-------
|
| 838 |
+
moon : (512, 512) uint8 ndarray
|
| 839 |
+
Moon image.
|
| 840 |
+
"""
|
| 841 |
+
return _load("data/moon.png")
|
| 842 |
+
|
| 843 |
+
|
| 844 |
+
def page():
|
| 845 |
+
"""Scanned page.
|
| 846 |
+
|
| 847 |
+
This image of printed text is useful for demonstrations requiring uneven
|
| 848 |
+
background illumination.
|
| 849 |
+
|
| 850 |
+
Returns
|
| 851 |
+
-------
|
| 852 |
+
page : (191, 384) uint8 ndarray
|
| 853 |
+
Page image.
|
| 854 |
+
"""
|
| 855 |
+
return _load("data/page.png")
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
def horse():
|
| 859 |
+
"""Black and white silhouette of a horse.
|
| 860 |
+
|
| 861 |
+
This image was downloaded from
|
| 862 |
+
`openclipart <http://openclipart.org/detail/158377/horse-by-marauder>`
|
| 863 |
+
|
| 864 |
+
No copyright restrictions. CC0 given by owner (Andreas Preuss (marauder)).
|
| 865 |
+
|
| 866 |
+
Returns
|
| 867 |
+
-------
|
| 868 |
+
horse : (328, 400) bool ndarray
|
| 869 |
+
Horse image.
|
| 870 |
+
"""
|
| 871 |
+
return img_as_bool(_load("data/horse.png", as_gray=True))
|
| 872 |
+
|
| 873 |
+
|
| 874 |
+
def clock():
|
| 875 |
+
"""Motion blurred clock.
|
| 876 |
+
|
| 877 |
+
This photograph of a wall clock was taken while moving the camera in an
|
| 878 |
+
approximately horizontal direction. It may be used to illustrate
|
| 879 |
+
inverse filters and deconvolution.
|
| 880 |
+
|
| 881 |
+
Released into the public domain by the photographer (Stefan van der Walt).
|
| 882 |
+
|
| 883 |
+
Returns
|
| 884 |
+
-------
|
| 885 |
+
clock : (300, 400) uint8 ndarray
|
| 886 |
+
Clock image.
|
| 887 |
+
"""
|
| 888 |
+
return _load("data/clock_motion.png")
|
| 889 |
+
|
| 890 |
+
|
| 891 |
+
def immunohistochemistry():
|
| 892 |
+
"""Immunohistochemical (IHC) staining with hematoxylin counterstaining.
|
| 893 |
+
|
| 894 |
+
This picture shows colonic glands where the IHC expression of FHL2 protein
|
| 895 |
+
is revealed with DAB. Hematoxylin counterstaining is applied to enhance the
|
| 896 |
+
negative parts of the tissue.
|
| 897 |
+
|
| 898 |
+
This image was acquired at the Center for Microscopy And Molecular Imaging
|
| 899 |
+
(CMMI).
|
| 900 |
+
|
| 901 |
+
No known copyright restrictions.
|
| 902 |
+
|
| 903 |
+
Returns
|
| 904 |
+
-------
|
| 905 |
+
immunohistochemistry : (512, 512, 3) uint8 ndarray
|
| 906 |
+
Immunohistochemistry image.
|
| 907 |
+
"""
|
| 908 |
+
return _load("data/ihc.png")
|
| 909 |
+
|
| 910 |
+
|
| 911 |
+
def chelsea():
|
| 912 |
+
"""Chelsea the cat.
|
| 913 |
+
|
| 914 |
+
An example with texture, prominent edges in horizontal and diagonal
|
| 915 |
+
directions, as well as features of differing scales.
|
| 916 |
+
|
| 917 |
+
Notes
|
| 918 |
+
-----
|
| 919 |
+
No copyright restrictions. CC0 by the photographer (Stefan van der Walt).
|
| 920 |
+
|
| 921 |
+
Returns
|
| 922 |
+
-------
|
| 923 |
+
chelsea : (300, 451, 3) uint8 ndarray
|
| 924 |
+
Chelsea image.
|
| 925 |
+
"""
|
| 926 |
+
return _load("data/chelsea.png")
|
| 927 |
+
|
| 928 |
+
|
| 929 |
+
# Define an alias for chelsea that is more descriptive.
|
| 930 |
+
cat = chelsea
|
| 931 |
+
|
| 932 |
+
|
| 933 |
+
def coffee():
|
| 934 |
+
"""Coffee cup.
|
| 935 |
+
|
| 936 |
+
This photograph is courtesy of Pikolo Espresso Bar.
|
| 937 |
+
It contains several elliptical shapes as well as varying texture (smooth
|
| 938 |
+
porcelain to coarse wood grain).
|
| 939 |
+
|
| 940 |
+
Notes
|
| 941 |
+
-----
|
| 942 |
+
No copyright restrictions. CC0 by the photographer (Rachel Michetti).
|
| 943 |
+
|
| 944 |
+
Returns
|
| 945 |
+
-------
|
| 946 |
+
coffee : (400, 600, 3) uint8 ndarray
|
| 947 |
+
Coffee image.
|
| 948 |
+
"""
|
| 949 |
+
return _load("data/coffee.png")
|
| 950 |
+
|
| 951 |
+
|
| 952 |
+
def hubble_deep_field():
|
| 953 |
+
"""Hubble eXtreme Deep Field.
|
| 954 |
+
|
| 955 |
+
This photograph contains the Hubble Telescope's farthest ever view of
|
| 956 |
+
the universe. It can be useful as an example for multi-scale
|
| 957 |
+
detection.
|
| 958 |
+
|
| 959 |
+
Notes
|
| 960 |
+
-----
|
| 961 |
+
This image was downloaded from
|
| 962 |
+
`HubbleSite
|
| 963 |
+
<http://hubblesite.org/newscenter/archive/releases/2012/37/image/a/>`__.
|
| 964 |
+
|
| 965 |
+
The image was captured by NASA and `may be freely used in the public domain
|
| 966 |
+
<http://www.nasa.gov/audience/formedia/features/MP_Photo_Guidelines.html>`_.
|
| 967 |
+
|
| 968 |
+
Returns
|
| 969 |
+
-------
|
| 970 |
+
hubble_deep_field : (872, 1000, 3) uint8 ndarray
|
| 971 |
+
Hubble deep field image.
|
| 972 |
+
"""
|
| 973 |
+
return _load("data/hubble_deep_field.jpg")
|
| 974 |
+
|
| 975 |
+
|
| 976 |
+
def retina():
|
| 977 |
+
"""Human retina.
|
| 978 |
+
|
| 979 |
+
This image of a retina is useful for demonstrations requiring circular
|
| 980 |
+
images.
|
| 981 |
+
|
| 982 |
+
Notes
|
| 983 |
+
-----
|
| 984 |
+
This image was downloaded from
|
| 985 |
+
`wikimedia <https://commons.wikimedia.org/wiki/File:Fundus_photograph_of_normal_left_eye.jpg>`.
|
| 986 |
+
This file is made available under the Creative Commons CC0 1.0 Universal
|
| 987 |
+
Public Domain Dedication.
|
| 988 |
+
|
| 989 |
+
References
|
| 990 |
+
----------
|
| 991 |
+
.. [1] Häggström, Mikael (2014). "Medical gallery of Mikael Häggström 2014".
|
| 992 |
+
WikiJournal of Medicine 1 (2). :DOI:`10.15347/wjm/2014.008`.
|
| 993 |
+
ISSN 2002-4436. Public Domain
|
| 994 |
+
|
| 995 |
+
Returns
|
| 996 |
+
-------
|
| 997 |
+
retina : (1411, 1411, 3) uint8 ndarray
|
| 998 |
+
Retina image in RGB.
|
| 999 |
+
"""
|
| 1000 |
+
return _load("data/retina.jpg")
|
| 1001 |
+
|
| 1002 |
+
|
| 1003 |
+
def shepp_logan_phantom():
|
| 1004 |
+
"""Shepp Logan Phantom.
|
| 1005 |
+
|
| 1006 |
+
References
|
| 1007 |
+
----------
|
| 1008 |
+
.. [1] L. A. Shepp and B. F. Logan, "The Fourier reconstruction of a head
|
| 1009 |
+
section," in IEEE Transactions on Nuclear Science, vol. 21,
|
| 1010 |
+
no. 3, pp. 21-43, June 1974. :DOI:`10.1109/TNS.1974.6499235`
|
| 1011 |
+
|
| 1012 |
+
Returns
|
| 1013 |
+
-------
|
| 1014 |
+
phantom : (400, 400) float64 image
|
| 1015 |
+
Image of the Shepp-Logan phantom in grayscale.
|
| 1016 |
+
"""
|
| 1017 |
+
return _load("data/phantom.png", as_gray=True)
|
| 1018 |
+
|
| 1019 |
+
|
| 1020 |
+
def colorwheel():
|
| 1021 |
+
"""Color Wheel.
|
| 1022 |
+
|
| 1023 |
+
Returns
|
| 1024 |
+
-------
|
| 1025 |
+
colorwheel : (370, 371, 3) uint8 image
|
| 1026 |
+
A colorwheel.
|
| 1027 |
+
"""
|
| 1028 |
+
return _load("data/color.png")
|
| 1029 |
+
|
| 1030 |
+
|
| 1031 |
+
def palisades_of_vogt():
|
| 1032 |
+
"""Return image sequence of in-vivo tissue showing the palisades of Vogt.
|
| 1033 |
+
|
| 1034 |
+
In the human eye, the palisades of Vogt are normal features of the corneal
|
| 1035 |
+
limbus, which is the border between the cornea and the sclera (i.e., the
|
| 1036 |
+
white of the eye).
|
| 1037 |
+
In the image sequence, there are some dark spots due to the presence of
|
| 1038 |
+
dust on the reference mirror.
|
| 1039 |
+
|
| 1040 |
+
Returns
|
| 1041 |
+
-------
|
| 1042 |
+
palisades_of_vogt: (60, 1440, 1440) uint16 ndarray
|
| 1043 |
+
|
| 1044 |
+
Notes
|
| 1045 |
+
-----
|
| 1046 |
+
See info under `in-vivo-cornea-spots.tif` at
|
| 1047 |
+
https://gitlab.com/scikit-image/data/-/blob/master/README.md#data.
|
| 1048 |
+
|
| 1049 |
+
"""
|
| 1050 |
+
return _load('data/palisades_of_vogt.tif')
|
| 1051 |
+
|
| 1052 |
+
|
| 1053 |
+
def rocket():
|
| 1054 |
+
"""Launch photo of DSCOVR on Falcon 9 by SpaceX.
|
| 1055 |
+
|
| 1056 |
+
This is the launch photo of Falcon 9 carrying DSCOVR lifted off from
|
| 1057 |
+
SpaceX's Launch Complex 40 at Cape Canaveral Air Force Station, FL.
|
| 1058 |
+
|
| 1059 |
+
Notes
|
| 1060 |
+
-----
|
| 1061 |
+
This image was downloaded from
|
| 1062 |
+
`SpaceX Photos
|
| 1063 |
+
<https://www.flickr.com/photos/spacexphotos/16511594820/in/photostream/>`__.
|
| 1064 |
+
|
| 1065 |
+
The image was captured by SpaceX and `released in the public domain
|
| 1066 |
+
<http://arstechnica.com/tech-policy/2015/03/elon-musk-puts-spacex-photos-into-the-public-domain/>`_.
|
| 1067 |
+
|
| 1068 |
+
Returns
|
| 1069 |
+
-------
|
| 1070 |
+
rocket : (427, 640, 3) uint8 ndarray
|
| 1071 |
+
Rocket image.
|
| 1072 |
+
"""
|
| 1073 |
+
return _load("data/rocket.jpg")
|
| 1074 |
+
|
| 1075 |
+
|
| 1076 |
+
def stereo_motorcycle():
|
| 1077 |
+
"""Rectified stereo image pair with ground-truth disparities.
|
| 1078 |
+
|
| 1079 |
+
The two images are rectified such that every pixel in the left image has
|
| 1080 |
+
its corresponding pixel on the same scanline in the right image. That means
|
| 1081 |
+
that both images are warped such that they have the same orientation but a
|
| 1082 |
+
horizontal spatial offset (baseline). The ground-truth pixel offset in
|
| 1083 |
+
column direction is specified by the included disparity map.
|
| 1084 |
+
|
| 1085 |
+
The two images are part of the Middlebury 2014 stereo benchmark. The
|
| 1086 |
+
dataset was created by Nera Nesic, Porter Westling, Xi Wang, York Kitajima,
|
| 1087 |
+
Greg Krathwohl, and Daniel Scharstein at Middlebury College. A detailed
|
| 1088 |
+
description of the acquisition process can be found in [1]_.
|
| 1089 |
+
|
| 1090 |
+
The images included here are down-sampled versions of the default exposure
|
| 1091 |
+
images in the benchmark. The images are down-sampled by a factor of 4 using
|
| 1092 |
+
the function `skimage.transform.downscale_local_mean`. The calibration data
|
| 1093 |
+
in the following and the included ground-truth disparity map are valid for
|
| 1094 |
+
the down-sampled images::
|
| 1095 |
+
|
| 1096 |
+
Focal length: 994.978px
|
| 1097 |
+
Principal point x: 311.193px
|
| 1098 |
+
Principal point y: 254.877px
|
| 1099 |
+
Principal point dx: 31.086px
|
| 1100 |
+
Baseline: 193.001mm
|
| 1101 |
+
|
| 1102 |
+
Returns
|
| 1103 |
+
-------
|
| 1104 |
+
img_left : (500, 741, 3) uint8 ndarray
|
| 1105 |
+
Left stereo image.
|
| 1106 |
+
img_right : (500, 741, 3) uint8 ndarray
|
| 1107 |
+
Right stereo image.
|
| 1108 |
+
disp : (500, 741, 3) float ndarray
|
| 1109 |
+
Ground-truth disparity map, where each value describes the offset in
|
| 1110 |
+
column direction between corresponding pixels in the left and the right
|
| 1111 |
+
stereo images. E.g. the corresponding pixel of
|
| 1112 |
+
``img_left[10, 10 + disp[10, 10]]`` is ``img_right[10, 10]``.
|
| 1113 |
+
NaNs denote pixels in the left image that do not have ground-truth.
|
| 1114 |
+
|
| 1115 |
+
Notes
|
| 1116 |
+
-----
|
| 1117 |
+
The original resolution images, images with different exposure and
|
| 1118 |
+
lighting, and ground-truth depth maps can be found at the Middlebury
|
| 1119 |
+
website [2]_.
|
| 1120 |
+
|
| 1121 |
+
References
|
| 1122 |
+
----------
|
| 1123 |
+
.. [1] D. Scharstein, H. Hirschmueller, Y. Kitajima, G. Krathwohl, N.
|
| 1124 |
+
Nesic, X. Wang, and P. Westling. High-resolution stereo datasets
|
| 1125 |
+
with subpixel-accurate ground truth. In German Conference on Pattern
|
| 1126 |
+
Recognition (GCPR 2014), Muenster, Germany, September 2014.
|
| 1127 |
+
.. [2] http://vision.middlebury.edu/stereo/data/scenes2014/
|
| 1128 |
+
|
| 1129 |
+
"""
|
| 1130 |
+
filename = _fetch("data/motorcycle_disp.npz")
|
| 1131 |
+
# np.load of npz file holds onto open file handle.
|
| 1132 |
+
with np.load(filename) as data:
|
| 1133 |
+
disp = data['arr_0']
|
| 1134 |
+
return (_load("data/motorcycle_left.png"), _load("data/motorcycle_right.png"), disp)
|
| 1135 |
+
|
| 1136 |
+
|
| 1137 |
+
def lfw_subset():
|
| 1138 |
+
"""Subset of data from the LFW dataset.
|
| 1139 |
+
|
| 1140 |
+
This database is a subset of the LFW database containing:
|
| 1141 |
+
|
| 1142 |
+
* 100 faces
|
| 1143 |
+
* 100 non-faces
|
| 1144 |
+
|
| 1145 |
+
The full dataset is available at [2]_.
|
| 1146 |
+
|
| 1147 |
+
Returns
|
| 1148 |
+
-------
|
| 1149 |
+
images : (200, 25, 25) uint8 ndarray
|
| 1150 |
+
100 first images are faces and subsequent 100 are non-faces.
|
| 1151 |
+
|
| 1152 |
+
Notes
|
| 1153 |
+
-----
|
| 1154 |
+
The faces were randomly selected from the LFW dataset and the non-faces
|
| 1155 |
+
were extracted from the background of the same dataset. The cropped ROIs
|
| 1156 |
+
have been resized to a 25 x 25 pixels.
|
| 1157 |
+
|
| 1158 |
+
References
|
| 1159 |
+
----------
|
| 1160 |
+
.. [1] Huang, G., Mattar, M., Lee, H., & Learned-Miller, E. G. (2012).
|
| 1161 |
+
Learning to align from scratch. In Advances in Neural Information
|
| 1162 |
+
Processing Systems (pp. 764-772).
|
| 1163 |
+
.. [2] http://vis-www.cs.umass.edu/lfw/
|
| 1164 |
+
|
| 1165 |
+
"""
|
| 1166 |
+
return np.load(_fetch('data/lfw_subset.npy'))
|
| 1167 |
+
|
| 1168 |
+
|
| 1169 |
+
def skin():
|
| 1170 |
+
"""Microscopy image of dermis and epidermis (skin layers).
|
| 1171 |
+
|
| 1172 |
+
Hematoxylin and eosin stained slide at 10x of normal epidermis and dermis
|
| 1173 |
+
with a benign intradermal nevus.
|
| 1174 |
+
|
| 1175 |
+
Notes
|
| 1176 |
+
-----
|
| 1177 |
+
This image requires an Internet connection the first time it is called,
|
| 1178 |
+
and to have the ``pooch`` package installed, in order to fetch the image
|
| 1179 |
+
file from the scikit-image datasets repository.
|
| 1180 |
+
|
| 1181 |
+
The source of this image is
|
| 1182 |
+
https://en.wikipedia.org/wiki/File:Normal_Epidermis_and_Dermis_with_Intradermal_Nevus_10x.JPG
|
| 1183 |
+
|
| 1184 |
+
The image was released in the public domain by its author Kilbad.
|
| 1185 |
+
|
| 1186 |
+
Returns
|
| 1187 |
+
-------
|
| 1188 |
+
skin : (960, 1280, 3) RGB image of uint8
|
| 1189 |
+
"""
|
| 1190 |
+
return _load('data/skin.jpg')
|
| 1191 |
+
|
| 1192 |
+
|
| 1193 |
+
def nickel_solidification():
|
| 1194 |
+
"""Image sequence of synchrotron x-radiographs showing the rapid
|
| 1195 |
+
solidification of a nickel alloy sample.
|
| 1196 |
+
|
| 1197 |
+
Returns
|
| 1198 |
+
-------
|
| 1199 |
+
nickel_solidification: (11, 384, 512) uint16 ndarray
|
| 1200 |
+
|
| 1201 |
+
Notes
|
| 1202 |
+
-----
|
| 1203 |
+
See info under `nickel_solidification.tif` at
|
| 1204 |
+
https://gitlab.com/scikit-image/data/-/blob/master/README.md#data.
|
| 1205 |
+
|
| 1206 |
+
"""
|
| 1207 |
+
return _load('data/solidification.tif')
|
| 1208 |
+
|
| 1209 |
+
|
| 1210 |
+
def protein_transport():
|
| 1211 |
+
"""Microscopy image sequence with fluorescence tagging of proteins
|
| 1212 |
+
re-localizing from the cytoplasmic area to the nuclear envelope.
|
| 1213 |
+
|
| 1214 |
+
Returns
|
| 1215 |
+
-------
|
| 1216 |
+
protein_transport: (15, 2, 180, 183) uint8 ndarray
|
| 1217 |
+
|
| 1218 |
+
Notes
|
| 1219 |
+
-----
|
| 1220 |
+
See info under `NPCsingleNucleus.tif` at
|
| 1221 |
+
https://gitlab.com/scikit-image/data/-/blob/master/README.md#data.
|
| 1222 |
+
|
| 1223 |
+
"""
|
| 1224 |
+
return _load('data/protein_transport.tif')
|
| 1225 |
+
|
| 1226 |
+
|
| 1227 |
+
def brain():
|
| 1228 |
+
"""Subset of data from the University of North Carolina Volume Rendering
|
| 1229 |
+
Test Data Set.
|
| 1230 |
+
|
| 1231 |
+
The full dataset is available at [1]_.
|
| 1232 |
+
|
| 1233 |
+
Returns
|
| 1234 |
+
-------
|
| 1235 |
+
image : (10, 256, 256) uint16 ndarray
|
| 1236 |
+
|
| 1237 |
+
Notes
|
| 1238 |
+
-----
|
| 1239 |
+
The 3D volume consists of 10 layers from the larger volume.
|
| 1240 |
+
|
| 1241 |
+
References
|
| 1242 |
+
----------
|
| 1243 |
+
.. [1] https://graphics.stanford.edu/data/voldata/
|
| 1244 |
+
|
| 1245 |
+
"""
|
| 1246 |
+
return _load("data/brain.tiff")
|
| 1247 |
+
|
| 1248 |
+
|
| 1249 |
+
def vortex():
|
| 1250 |
+
"""Case B1 image pair from the first PIV challenge.
|
| 1251 |
+
|
| 1252 |
+
Returns
|
| 1253 |
+
-------
|
| 1254 |
+
image0, image1 : (512, 512) grayscale images
|
| 1255 |
+
A pair of images featuring synthetic moving particles.
|
| 1256 |
+
|
| 1257 |
+
Notes
|
| 1258 |
+
-----
|
| 1259 |
+
This image was licensed as CC0 by its author, Prof. Koji Okamoto, with
|
| 1260 |
+
thanks to Prof. Jun Sakakibara, who maintains the PIV Challenge site.
|
| 1261 |
+
|
| 1262 |
+
References
|
| 1263 |
+
----------
|
| 1264 |
+
.. [1] Particle Image Velocimetry (PIV) Challenge site
|
| 1265 |
+
http://pivchallenge.org
|
| 1266 |
+
.. [2] 1st PIV challenge Case B: http://pivchallenge.org/pub/index.html#b
|
| 1267 |
+
"""
|
| 1268 |
+
return (
|
| 1269 |
+
_load('data/pivchallenge-B-B001_1.tif'),
|
| 1270 |
+
_load('data/pivchallenge-B-B001_2.tif'),
|
| 1271 |
+
)
|
envs/kitoverlay/skimage/data/_registry.py
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Registry of datafiles that can be downloaded along with their SHA256 hashes
|
| 2 |
+
# To generate the SHA256 hash, use the command
|
| 3 |
+
# openssl sha256 filename
|
| 4 |
+
registry = {
|
| 5 |
+
"color/data/lab_array_a_10.npy": "a3ef76f1530e374f9121020f1f220bc89767dc866f4bbd1b1f47e5b84891a38c",
|
| 6 |
+
"color/data/lab_array_a_2.npy": "793d5981cbffceb14b5fb589f998a2b1acdb5ff9c14d364c8e9e8bd45a80b275",
|
| 7 |
+
"color/data/lab_array_a_r.npy": "3d3613da109d0c87827525fc49b58111aefc12438fa6426654979f66807b9227",
|
| 8 |
+
"color/data/lab_array_b_10.npy": "e8d648b28077c1bfcef55ec6dc8679819612b56a01647f8c0a78625bb06f99b6",
|
| 9 |
+
"color/data/lab_array_b_2.npy": "da9c6aa99e4ab3af8ec3107bbf11647cc483a0760285dd5c9fb66988be393ca1",
|
| 10 |
+
"color/data/lab_array_b_r.npy": "d9eee96f4d65a2fbba82039508aac8c18304752ee8e33233e2a013e65bb91464",
|
| 11 |
+
"color/data/lab_array_c_10.npy": "88b4ff2a2d2c4f48e7bb265609221d4b9ef439a4e2d8a86989696bfdb47790e6",
|
| 12 |
+
"color/data/lab_array_c_2.npy": "e1b8acfdc7284ab9cd339de66948134304073b6f734ecf9ad42f8297b83d3405",
|
| 13 |
+
"color/data/lab_array_c_r.npy": "09ffba2ed69e467864fea883493cd2d2706da028433464e3e858a8086842867e",
|
| 14 |
+
"color/data/lab_array_d50_10.npy": "42e2ff26cb10e2a98fcf1bc06c2483302ff4fabf971fe8d49b530f490b5d24c7",
|
| 15 |
+
"color/data/lab_array_d50_2.npy": "4aa03b7018ff7276643d3c082123cf07304f9d8d898ae92a5756a86955de4faf",
|
| 16 |
+
"color/data/lab_array_d50_r.npy": "57db02009f9a68dade33ce1ecffead0418d8ac8113b2a589fc02a20e6bf7e799",
|
| 17 |
+
"color/data/lab_array_d55_10.npy": "ab4f21368b6d8351578ab093381c44b49ae87a6b7f25c11aa094b07f215eed7d",
|
| 18 |
+
"color/data/lab_array_d55_2.npy": "0319723de4632a252bae828b7c96d038fb075a7df05beadfbad653da05efe372",
|
| 19 |
+
"color/data/lab_array_d55_r.npy": "060ebc446f7b4da4df58a60f0006133dbca735da87ba61854f4a75d28db67a3a",
|
| 20 |
+
"color/data/lab_array_d65_10.npy": "5cb9e9c384d2577aaf8b7d2d21ff5b505708b80605a2f59d10e89d22c3d308d2",
|
| 21 |
+
"color/data/lab_array_d65_2.npy": "16e847160f7ba4f19806d8194ed44a6654c9367e5a2cb240aa6e7eece44a6649",
|
| 22 |
+
"color/data/lab_array_d65_r.npy": "82d0dd7a46741f627b8868793e64cdc2f9944fe1e049b573f752a93760a1577c",
|
| 23 |
+
"color/data/lab_array_d75_10.npy": "c2d3de5422c785c925926b0c6223aeaf50b9393619d1c30830190d433606cbe1",
|
| 24 |
+
"color/data/lab_array_d75_2.npy": "c94d53da398d36e076471ff7e0dafcaffc64ce4ba33b4d04849c32d19c87494a",
|
| 25 |
+
"color/data/lab_array_e_2.npy": "ac05f17a83961b020ceccbdd46bddc86943d43e678dabcc898caf4a1e4be6165",
|
| 26 |
+
"color/data/luv_array_a_10.npy": "c8af67f9fd64a6e9c610ac0c12c5315a49ca229363f048e5d851409d4a3ae5b6",
|
| 27 |
+
"color/data/luv_array_a_2.npy": "eaf05dc61f4a70ece367d5e751a14d42b7c397c7b1c2df4cfecec9ddf26e1c1a",
|
| 28 |
+
"color/data/luv_array_a_r.npy": "2c0891add787ec757601f9c61ad14dd9621dd969af4e32753f2e64df437081b7",
|
| 29 |
+
"color/data/luv_array_b_10.npy": "a5407736b8a43071139ca178d12cdf930f32f52a0644f0b13f89d8895c8b43db",
|
| 30 |
+
"color/data/luv_array_b_2.npy": "8e74173d54dc549b6c0ebd1f1d70489d2905cad87744e41ed74384f21f22986d",
|
| 31 |
+
"color/data/luv_array_b_r.npy": "0a74c41df369cbb5fc0a00c16d60dc6f946ebf144bc5e506545b0d160fa53dfa",
|
| 32 |
+
"color/data/luv_array_c_10.npy": "3a5f975ffa57f69a1be9e02b153e8161f83040ce3002ea1b0a05b9fbdd0d8ec4",
|
| 33 |
+
"color/data/luv_array_c_2.npy": "32506cd50ea2181997cb88d3511e275740e8151d6c693cd178f5eafd8b0c6e47",
|
| 34 |
+
"color/data/luv_array_c_r.npy": "c0fbf98cc0e62ed426ab4d228986d6660089444a7bbfcc64cbb1c632644067bb",
|
| 35 |
+
"color/data/luv_array_d50_10.npy": "fe223db556222ce3a59198bed3a3324c2c719b8083fb84dc5b00f214b4773b16",
|
| 36 |
+
"color/data/luv_array_d50_2.npy": "48e8989048904bdf2c3c1ada265c1c29c5eff60f02f848a25cde622982c84901",
|
| 37 |
+
"color/data/luv_array_d50_r.npy": "f93f0def9c93f872dd10ce4a91fdb3f06eea61ddb6e72387b7669909827d4f9c",
|
| 38 |
+
"color/data/luv_array_d55_10.npy": "d88d53d2bad230c2331442187712ec52ffdee62bf0f60b200c33411bfed76c60",
|
| 39 |
+
"color/data/luv_array_d55_2.npy": "c761b40475df591ae9c0475d54ef712d067190ca4652efc6308b69080a652061",
|
| 40 |
+
"color/data/luv_array_d55_r.npy": "05fbd57e3602ee4d5202b9f18f9b5fc05b545891a9b4456d2a88aa798a5a774a",
|
| 41 |
+
"color/data/luv_array_d65_10.npy": "41a5452ffac4d31dd579d9528e725432c60d77b5f505d801898d9401429c89bf",
|
| 42 |
+
"color/data/luv_array_d65_2.npy": "962ce180132c6c11798cbc423b2b204d1d10187670f6eb5dec1058eaad301e0e",
|
| 43 |
+
"color/data/luv_array_d65_r.npy": "78db8c19af26dd802ce98b039a33855f7c8d6a103a2721d094b1d9c619717449",
|
| 44 |
+
"color/data/luv_array_d75_10.npy": "e1cc70d56eb6789633d4c2a4059b9533f616a7c8592c9bd342403e41d72f45e4",
|
| 45 |
+
"color/data/luv_array_d75_2.npy": "07db3bd59bd89de8e5ff62dad786fe5f4b299133495ba9bea30495b375133a98",
|
| 46 |
+
"color/data/luv_array_e_2.npy": "41b1037d81b267305ffe9e8e97e0affa9fa54b18e60413b01b8f11861cb32213",
|
| 47 |
+
"color/ciede2000_test_data.txt": "2e005c6f76ddfb7bbcc8f68490f1f7b4b4a2a4b06b36a80c985677a2799c0e40",
|
| 48 |
+
"data/astronaut.png": "88431cd9653ccd539741b555fb0a46b61558b301d4110412b5bc28b5e3ea6cb5",
|
| 49 |
+
"data/brick.png": "7966caf324f6ba843118d98f7a07746d22f6a343430add0233eca5f6eaaa8fcf",
|
| 50 |
+
"data/cell.png": "8d23a7fb81f7cc877cd09f330357fc7f595651306e84e17252f6e0a1b3f61515",
|
| 51 |
+
"data/camera.png": "b0793d2adda0fa6ae899c03989482bff9a42d3d5690fc7e3648f2795d730c23a",
|
| 52 |
+
"data/chessboard_GRAY.png": "3e51870774515af4d07d820bd8827364c70839bf9b573c746e485095e893df90",
|
| 53 |
+
"data/chessboard_RGB.png": "1ac01eff2d4e50f4eda55a2ddecdc28a6576623a58d7a7ef84513c5cc19a0331",
|
| 54 |
+
"data/chelsea.png": "596aa1e7cb875eb79f437e310381d26b338a81c2da23439704a73c4651e8c4bb",
|
| 55 |
+
"data/clock_motion.png": "f029226b28b642e80113d86622e9b215ee067a0966feaf5e60604a1e05733955",
|
| 56 |
+
"data/coffee.png": "cc02f8ca188b167c775a7101b5d767d1e71792cf762c33d6fa15a4599b5a8de7",
|
| 57 |
+
"data/coins.png": "f8d773fc9cfa6f4d8e5942dc34d0a0788fcaed2a4fefbbed0aef5398d7ef4cba",
|
| 58 |
+
"data/color.png": "7d2df993de2b4fa2a78e04e5df8050f49a9c511aa75e59ab3bd56ac9c98aef7e",
|
| 59 |
+
"data/eagle.png": "928f1bbe7403b533265f56db3a6b07c835dfa8e2513f5c5075ca2f1960f6179e",
|
| 60 |
+
"data/horse.png": "c7fb60789fe394c485f842291ea3b21e50d140f39d6dcb5fb9917cc178225455",
|
| 61 |
+
"data/grass.png": "b6b6022426b38936c43a4ac09635cd78af074e90f42ffa8227ac8b7452d39f89",
|
| 62 |
+
"data/hubble_deep_field.jpg": "3a19c5dd8a927a9334bb1229a6d63711b1c0c767fb27e2286e7c84a3e2c2f5f4",
|
| 63 |
+
"data/ihc.png": "f8dd1aa387ddd1f49d8ad13b50921b237df8e9b262606d258770687b0ef93cef",
|
| 64 |
+
"data/logo.png": "f2c57fe8af089f08b5ba523d95573c26e62904ac5967f4c8851b27d033690168",
|
| 65 |
+
"data/lfw_subset.npy": "9560ec2f5edfac01973f63a8a99d00053fecd11e21877e18038fbe500f8e872c",
|
| 66 |
+
"data/microaneurysms.png": "a1e1be59aa447f8ce082f7fa809997ab369a2b137cb6c4202abc647c7ccf6456",
|
| 67 |
+
"data/moon.png": "78739619d11f7eb9c165bb5d2efd4772cee557812ec847532dbb1d92ef71f577",
|
| 68 |
+
"data/motorcycle_left.png": "db18e9c4157617403c3537a6ba355dfeafe9a7eabb6b9b94cb33f6525dd49179",
|
| 69 |
+
"data/motorcycle_right.png": "5fc913ae870e42a4b662314bc904d1786bcad8e2f0b9b67dba5a229406357797",
|
| 70 |
+
"data/motorcycle_disp.npz": "2e49c8cebff3fa20359a0cc6880c82e1c03bbb106da81a177218281bc2f113d7",
|
| 71 |
+
"data/mssim_matlab_output.npz": "cc11a14bfa040c75b02db32282439f2e2e3e96779196c171498afaa70528ed7a",
|
| 72 |
+
"data/page.png": "341a6f0a61557662b02734a9b6e56ec33a915b2c41886b97509dedf2a43b47a3",
|
| 73 |
+
"data/phantom.png": "552ff698167aa402cceb17981130607a228a0a0aa7c519299eaa4d5f301ba36c",
|
| 74 |
+
"data/retina.jpg": "38a07f36f27f095e818aea7b96d34202c05176d30253c66733f2e00379e9e0e6",
|
| 75 |
+
"data/rocket.jpg": "c2dd0de7c538df8d111e479619b129464d0269d0ae5fd18ca91d33a7fdfea95c",
|
| 76 |
+
"data/gravel.png": "c48615b451bf1e606fbd72c0aa9f8cc0f068ab7111ef7d93bb9b0f2586440c12",
|
| 77 |
+
"data/text.png": "bd84aa3a6e3c9887850d45d606c96b2e59433fbef50338570b63c319e668e6d1",
|
| 78 |
+
"data/chessboard_GRAY_U16.tif": "9fd3392c5b6cbc5f686d8ff83eb57ef91d038ee0852ac26817e5ac99df4c7f45",
|
| 79 |
+
"data/chessboard_GRAY_U16B.tif": "b0a9270751f0fc340c90b8b615b62b88187b9ab5995942717566735d523cddb2",
|
| 80 |
+
"data/chessboard_GRAY_U8.npy": "71f394694b721e8a33760a355b3666c9b7d7fc1188ff96b3cd23c2a1d73a38d8",
|
| 81 |
+
"data/lbpcascade_frontalface_opencv.xml": "03097789a3dcbb0e40d20b9ef82537dbc3b670b6a7f2268d735470f22e003a91",
|
| 82 |
+
"data/astronaut_GRAY_hog_L1.npy": "5d8ab22b166d1dd49c12caeff9d178ed28132efea3852b952e9d75f7f7f94954",
|
| 83 |
+
"data/astronaut_GRAY_hog_L2-Hys.npy": "c4dd6e50d1129aada358311cf8880ce8c775f31e0e550fc322c16e43a96d56fe",
|
| 84 |
+
"data/rank_filter_tests.npz": "efaf5699630f4a53255e91681dc72a965acd4a8aa1f84671c686fb93e7df046d",
|
| 85 |
+
"data/rank_filters_tests_3d.npz": "1741c2b978424e93558a07d345b2a0d9bfbb33c095c123da147fca066714ab16",
|
| 86 |
+
"data/palette_color.png": "c4e817035fb9f7730fe95cff1da3866dea01728efc72b6e703d78f7ab9717bdd",
|
| 87 |
+
"data/palette_gray.png": "bace7f73783bf3ab3b7fdaf701707e4fa09f0dbd0ea72cf5b12ddc73d50b02a9",
|
| 88 |
+
"data/green_palette.png": "42d49d94be8f9bc76e50639d3701ed0484258721f6b0bd7f50bb1b9274a010f0",
|
| 89 |
+
"data/truncated.jpg": "4c226038acc78012d335efba29c6119a24444a886842182b7e18db378f4a557d",
|
| 90 |
+
"data/multipage.tif": "4da0ad0d3df4807a9847247d1b5e565b50d46481f643afb5c37c14802c78130f",
|
| 91 |
+
"data/multipage_rgb.tif": "1d23b844fd38dce0e2d06f30432817cdb85e52070d8f5460a2ba58aebf34a0de",
|
| 92 |
+
"data/no_time_for_that_tiny.gif": "20abe94ba9e45f18de416c5fbef8d1f57a499600be40f9a200fae246010eefce",
|
| 93 |
+
"data/foo3x5x4indexed.png": "48a64c25c6da000ffdb5fcc34ebafe9ba3b1c9b61d7984ea7ca6dc54f9312dfa",
|
| 94 |
+
"data/gray_morph_output.npz": "49a0dae607cd8d31e134b4bfcbf0d86b13751fdce9667d8bf1ade93d435191b1",
|
| 95 |
+
"data/disk-matlab-output.npz": "8a39d5c866f6216d6a9c9166312aa4bbf4d18fab3d0dcd963c024985bde5856b",
|
| 96 |
+
"data/diamond-matlab-output.npz": "02fca68907e2b252b501dfe977eef71ae39fadaaa3702ebdc855195422ae1cc2",
|
| 97 |
+
"data/bw_text.png": "308c2b09f8975a69b212e103b18520e8cbb7a4eccfce0f757836cd371f1b9094",
|
| 98 |
+
"data/bw_text_skeleton.npy": "9ff4fc23c6a01497d7987f14e3a97cbcc39cce54b2b3b7ee33b84c1b661d0ae1",
|
| 99 |
+
"data/_blobs_3d_fiji_skeleton.tif": "e3449ad9819425959952050c147278555e5ffe1c2c4a30df29f6a1f9023e10c3",
|
| 100 |
+
"data/checker_bilevel.png": "2e207e486545874a2a3e69ba653b28fdef923157be9017559540e65d1bcb8e28",
|
| 101 |
+
"restoration/astronaut_rl.npy": "3f8373e2c6182a89366e51cef6624e3625deac75fdda1079cbdad2a33322152c",
|
| 102 |
+
"restoration/camera_rl.npy": "fd4f59af84dd471fbbe79ee70c1b7e68a69864c461f0db5ac587e7975363f78f",
|
| 103 |
+
"restoration/camera_unsup.npy": "3de10a0b97267352b18886b25d66a967f9e1d78ada61050577d78586cab82baa",
|
| 104 |
+
"restoration/camera_unsup2.npy": "29cdc60605eb528c5f014baa8564d7d1ba0bd4b3170a66522058cbe5aed0960b",
|
| 105 |
+
"restoration/camera_wiener.npy": "4505ea8b0d63d03250c6d756560d615751b76dd6ffc4a95972fa260c0c84633e",
|
| 106 |
+
"registration/data/OriginalX-130Y130.png": "bf24a06d99ae131c97e582ef5e1cd0c648a8dad0caab31281f3564045492811f",
|
| 107 |
+
"registration/data/OriginalX130Y130.png": "7fdd4c06d504fec35ee0703bd7ed2c08830b075a74c8506bae4a70d682f5a2db",
|
| 108 |
+
"registration/data/OriginalX75Y75.png": "c5cd58893c93140df02896df80b13ecf432f5c86eeaaf8fb311aec52a65c7016",
|
| 109 |
+
"registration/data/TransformedX-130Y130.png": "1cda90ed69c921eb7605b73b76d141cf4ea03fb8ce3336445ca08080e40d7375",
|
| 110 |
+
"registration/data/TransformedX130Y130.png": "bb10c6ae3f91a313b0ac543efdb7ca69c4b95e55674c65a88472a6c4f4692a25",
|
| 111 |
+
"registration/data/TransformedX75Y75.png": "a1e9ead5f8e4a0f604271e1f9c50e89baf53f068f1d19fab2876af4938e695ea",
|
| 112 |
+
"data/brain.tiff": "bcdbaf424fbad7b1fb0f855f608c68e5a838f35affc323ff04ea17f678eef5c6",
|
| 113 |
+
"data/cells3d.tif": "afc7c7d80d38bfde09788b4064ac1e64ec14e88454ab785ebdc8dbba5ca3b222",
|
| 114 |
+
"data/palisades_of_vogt.tif": "7f205b626407e194974cead67c4d3909344cf59c42d229a349da0198183e5bd0",
|
| 115 |
+
"data/kidney.tif": "80c0799bc58b08cf6eaa53ecd202305eb42fd7bc73746cb6c5064dbeae7e8476",
|
| 116 |
+
"data/lily.tif": "395c2f0194c25b9824a8cd79266920362a0816bc9e906dd392adce2d8309af03",
|
| 117 |
+
"data/mitosis.tif": "2751ba667c4067c5d30817cff004aa06f6f6287f1cdbb5b8c9c6a500308cb456",
|
| 118 |
+
"data/skin.jpg": "8759fe080509712163453f4b17106582b8513e73b0788d80160abf840e272075",
|
| 119 |
+
"data/pivchallenge-B-B001_1.tif": "e95e09abbcecba723df283ac7d361766328abd943701a2ec2f345d4a2014da2a",
|
| 120 |
+
"data/pivchallenge-B-B001_2.tif": "4ceb5407e4e333476a0f264c14b7a3f6c0e753fcdc99ee1c4b8196e5f823805e",
|
| 121 |
+
"data/protein_transport.tif": "a8e24e8d187f33e92ee28508d5615286c850ca75374af7e74e527d290e8b06ea",
|
| 122 |
+
"data/solidification.tif": "50ef9a52c621b7c0c506ad1fe1b8ee8a158a4d7c8e50ddfce1e273a422dca3f9",
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
registry_urls = {
|
| 126 |
+
"data/brain.tiff": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/brain.tiff",
|
| 127 |
+
"data/cells3d.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/cells3d.tif",
|
| 128 |
+
"data/palisades_of_vogt.tif": "https://gitlab.com/scikit-image/data/-/raw/b2bc880f3bac23a583724befe8388dae368c52fe/in-vivo-cornea-spots.tif",
|
| 129 |
+
"data/eagle.png": "https://gitlab.com/scikit-image/data/-/raw/1e4f62ac31ba4553d176d4473a5967ad1b076d62/eagle.png",
|
| 130 |
+
"data/kidney.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/kidney-tissue-fluorescence.tif",
|
| 131 |
+
"data/lily.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/lily-of-the-valley-fluorescence.tif",
|
| 132 |
+
"data/mitosis.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/AS_09125_050116030001_D03f00d0.tif",
|
| 133 |
+
"data/rank_filters_tests_3d.npz": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/Tests_besides_Equalize_Otsu/add18_entropy/rank_filters_tests_3d.npz",
|
| 134 |
+
"data/skin.jpg": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/Normal_Epidermis_and_Dermis_with_Intradermal_Nevus_10x.JPG",
|
| 135 |
+
"data/pivchallenge-B-B001_1.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/pivchallenge/B/B001_1.tif",
|
| 136 |
+
"data/pivchallenge-B-B001_2.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/pivchallenge/B/B001_2.tif",
|
| 137 |
+
"data/protein_transport.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/NPCsingleNucleus.tif",
|
| 138 |
+
"data/solidification.tif": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/nickel_solidification.tif",
|
| 139 |
+
"restoration/astronaut_rl.npy": "https://gitlab.com/scikit-image/data/-/raw/2cdc5ce89b334d28f06a58c9f0ca21aa6992a5ba/astronaut_rl.npy",
|
| 140 |
+
"data/gray_morph_output.npz": "https://gitlab.com/scikit-image/data/-/raw/806548e112bcf2b708a9a32275d335cb592480fd/Tests_besides_Equalize_Otsu/gray_morph_output.npz",
|
| 141 |
+
"data/_blobs_3d_fiji_skeleton.tif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/_blobs_3d_fiji_skeleton.tif",
|
| 142 |
+
"data/astronaut.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/astronaut.png",
|
| 143 |
+
"data/astronaut_GRAY_hog_L1.npy": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/astronaut_GRAY_hog_L1.npy",
|
| 144 |
+
"data/astronaut_GRAY_hog_L2-Hys.npy": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/astronaut_GRAY_hog_L2-Hys.npy",
|
| 145 |
+
"data/brick.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/brick.png",
|
| 146 |
+
"data/bw_text.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/bw_text.png",
|
| 147 |
+
"data/bw_text_skeleton.npy": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/bw_text_skeleton.npy",
|
| 148 |
+
"data/camera.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/camera.png",
|
| 149 |
+
"data/cell.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/cell.png",
|
| 150 |
+
"data/checker_bilevel.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/checker_bilevel.png",
|
| 151 |
+
"data/chelsea.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chelsea.png",
|
| 152 |
+
"data/chessboard_GRAY.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chessboard_GRAY.png",
|
| 153 |
+
"data/chessboard_GRAY_U16.tif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chessboard_GRAY_U16.tif",
|
| 154 |
+
"data/chessboard_GRAY_U16B.tif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chessboard_GRAY_U16B.tif",
|
| 155 |
+
"data/chessboard_GRAY_U8.npy": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chessboard_GRAY_U8.npy",
|
| 156 |
+
"data/chessboard_RGB.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/chessboard_RGB.png",
|
| 157 |
+
"data/clock_motion.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/clock_motion.png",
|
| 158 |
+
"data/coffee.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/coffee.png",
|
| 159 |
+
"data/coins.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/coins.png",
|
| 160 |
+
"data/color.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/color.png",
|
| 161 |
+
"data/diamond-matlab-output.npz": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/diamond-matlab-output.npz",
|
| 162 |
+
"data/disk-matlab-output.npz": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/disk-matlab-output.npz",
|
| 163 |
+
"data/foo3x5x4indexed.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/foo3x5x4indexed.png",
|
| 164 |
+
"data/grass.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/grass.png",
|
| 165 |
+
"data/gravel.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/gravel.png",
|
| 166 |
+
"data/green_palette.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/green_palette.png",
|
| 167 |
+
"data/horse.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/horse.png",
|
| 168 |
+
"data/hubble_deep_field.jpg": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/hubble_deep_field.jpg",
|
| 169 |
+
"data/ihc.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/ihc.png",
|
| 170 |
+
"data/lbpcascade_frontalface_opencv.xml": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/lbpcascade_frontalface_opencv.xml",
|
| 171 |
+
"data/lfw_subset.npy": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/lfw_subset.npy",
|
| 172 |
+
"data/logo.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/logo.png",
|
| 173 |
+
"data/microaneurysms.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/microaneurysms.png",
|
| 174 |
+
"data/moon.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/moon.png",
|
| 175 |
+
"data/motorcycle_disp.npz": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/motorcycle_disp.npz",
|
| 176 |
+
"data/motorcycle_left.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/motorcycle_left.png",
|
| 177 |
+
"data/motorcycle_right.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/motorcycle_right.png",
|
| 178 |
+
"data/mssim_matlab_output.npz": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/mssim_matlab_output.npz",
|
| 179 |
+
"data/multipage.tif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/multipage.tif",
|
| 180 |
+
"data/multipage_rgb.tif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/multipage_rgb.tif",
|
| 181 |
+
"data/no_time_for_that_tiny.gif": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/no_time_for_that_tiny.gif",
|
| 182 |
+
"data/page.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/page.png",
|
| 183 |
+
"data/palette_color.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/palette_color.png",
|
| 184 |
+
"data/palette_gray.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/palette_gray.png",
|
| 185 |
+
"data/phantom.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/phantom.png",
|
| 186 |
+
"data/rank_filter_tests.npz": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/rank_filter_tests.npz",
|
| 187 |
+
"data/retina.jpg": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/retina.jpg",
|
| 188 |
+
"data/rocket.jpg": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/rocket.jpg",
|
| 189 |
+
"data/text.png": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/text.png",
|
| 190 |
+
"data/truncated.jpg": "https://gitlab.com/scikit-image/data/-/raw/5c090b56df3988d988ff97928e2ef2d2cbe38e1b/truncated.jpg",
|
| 191 |
+
}
|
envs/kitoverlay/skimage/data/lbpcascade_frontalface_opencv.xml
ADDED
|
@@ -0,0 +1,1505 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<?xml version="1.0"?>
|
| 2 |
+
<!--
|
| 3 |
+
number of positive samples 3000
|
| 4 |
+
number of negative samples 1500
|
| 5 |
+
-->
|
| 6 |
+
<opencv_storage>
|
| 7 |
+
<cascade type_id="opencv-cascade-classifier">
|
| 8 |
+
<stageType>BOOST</stageType>
|
| 9 |
+
<featureType>LBP</featureType>
|
| 10 |
+
<height>24</height>
|
| 11 |
+
<width>24</width>
|
| 12 |
+
<stageParams>
|
| 13 |
+
<boostType>GAB</boostType>
|
| 14 |
+
<minHitRate>0.9950000047683716</minHitRate>
|
| 15 |
+
<maxFalseAlarm>0.5000000000000000</maxFalseAlarm>
|
| 16 |
+
<weightTrimRate>0.9500000000000000</weightTrimRate>
|
| 17 |
+
<maxDepth>1</maxDepth>
|
| 18 |
+
<maxWeakCount>100</maxWeakCount></stageParams>
|
| 19 |
+
<featuhreParams>
|
| 20 |
+
<maxCatCount>256</maxCatCount></featuhreParams>
|
| 21 |
+
<stageNum>20</stageNum>
|
| 22 |
+
<stages>
|
| 23 |
+
<!-- stage 0 -->
|
| 24 |
+
<_>
|
| 25 |
+
<maxWeakCount>3</maxWeakCount>
|
| 26 |
+
<stageThreshold>-0.7520892024040222</stageThreshold>
|
| 27 |
+
<weakClassifiers>
|
| 28 |
+
<!-- tree 0 -->
|
| 29 |
+
<_>
|
| 30 |
+
<internalNodes>
|
| 31 |
+
0 -1 46 -67130709 -21569 -1426120013 -1275125205 -21585
|
| 32 |
+
-16385 587145899 -24005</internalNodes>
|
| 33 |
+
<leafValues>
|
| 34 |
+
-0.6543210148811340 0.8888888955116272</leafValues></_>
|
| 35 |
+
<!-- tree 1 -->
|
| 36 |
+
<_>
|
| 37 |
+
<internalNodes>
|
| 38 |
+
0 -1 13 -163512766 -769593758 -10027009 -262145 -514457854
|
| 39 |
+
-193593353 -524289 -1</internalNodes>
|
| 40 |
+
<leafValues>
|
| 41 |
+
-0.7739216089248657 0.7278633713722229</leafValues></_>
|
| 42 |
+
<!-- tree 2 -->
|
| 43 |
+
<_>
|
| 44 |
+
<internalNodes>
|
| 45 |
+
0 -1 2 -363936790 -893203669 -1337948010 -136907894
|
| 46 |
+
1088782736 -134217726 -741544961 -1590337</internalNodes>
|
| 47 |
+
<leafValues>
|
| 48 |
+
-0.7068563103675842 0.6761534214019775</leafValues></_></weakClassifiers></_>
|
| 49 |
+
<!-- stage 1 -->
|
| 50 |
+
<_>
|
| 51 |
+
<maxWeakCount>4</maxWeakCount>
|
| 52 |
+
<stageThreshold>-0.4872078299522400</stageThreshold>
|
| 53 |
+
<weakClassifiers>
|
| 54 |
+
<!-- tree 0 -->
|
| 55 |
+
<_>
|
| 56 |
+
<internalNodes>
|
| 57 |
+
0 -1 84 2147483647 1946124287 -536870913 2147450879
|
| 58 |
+
738132490 1061101567 243204619 2147446655</internalNodes>
|
| 59 |
+
<leafValues>
|
| 60 |
+
-0.8083735704421997 0.7685696482658386</leafValues></_>
|
| 61 |
+
<!-- tree 1 -->
|
| 62 |
+
<_>
|
| 63 |
+
<internalNodes>
|
| 64 |
+
0 -1 21 2147483647 263176079 1879048191 254749487 1879048191
|
| 65 |
+
-134252545 -268435457 801111999</internalNodes>
|
| 66 |
+
<leafValues>
|
| 67 |
+
-0.7698410153388977 0.6592915654182434</leafValues></_>
|
| 68 |
+
<!-- tree 2 -->
|
| 69 |
+
<_>
|
| 70 |
+
<internalNodes>
|
| 71 |
+
0 -1 106 -98110272 1610939566 -285484400 -850010381
|
| 72 |
+
-189334372 -1671954433 -571026695 -262145</internalNodes>
|
| 73 |
+
<leafValues>
|
| 74 |
+
-0.7506558895111084 0.5444605946540833</leafValues></_>
|
| 75 |
+
<!-- tree 3 -->
|
| 76 |
+
<_>
|
| 77 |
+
<internalNodes>
|
| 78 |
+
0 -1 48 -798690576 -131075 1095771153 -237144073 -65569 -1
|
| 79 |
+
-216727745 -69206049</internalNodes>
|
| 80 |
+
<leafValues>
|
| 81 |
+
-0.7775990366935730 0.5465461611747742</leafValues></_></weakClassifiers></_>
|
| 82 |
+
<!-- stage 2 -->
|
| 83 |
+
<_>
|
| 84 |
+
<maxWeakCount>4</maxWeakCount>
|
| 85 |
+
<stageThreshold>-1.1592328548431396</stageThreshold>
|
| 86 |
+
<weakClassifiers>
|
| 87 |
+
<!-- tree 0 -->
|
| 88 |
+
<_>
|
| 89 |
+
<internalNodes>
|
| 90 |
+
0 -1 47 -21585 -20549 -100818262 -738254174 -20561 -36865
|
| 91 |
+
-151016790 -134238549</internalNodes>
|
| 92 |
+
<leafValues>
|
| 93 |
+
-0.5601882934570313 0.7743113040924072</leafValues></_>
|
| 94 |
+
<!-- tree 1 -->
|
| 95 |
+
<_>
|
| 96 |
+
<internalNodes>
|
| 97 |
+
0 -1 12 -286003217 183435247 -268994614 -421330945
|
| 98 |
+
-402686081 1090387966 -286785545 -402653185</internalNodes>
|
| 99 |
+
<leafValues>
|
| 100 |
+
-0.6124526262283325 0.6978127956390381</leafValues></_>
|
| 101 |
+
<!-- tree 2 -->
|
| 102 |
+
<_>
|
| 103 |
+
<internalNodes>
|
| 104 |
+
0 -1 26 -50347012 970882927 -50463492 -1253377 -134218251
|
| 105 |
+
-50364513 -33619992 -172490753</internalNodes>
|
| 106 |
+
<leafValues>
|
| 107 |
+
-0.6114496588706970 0.6537628173828125</leafValues></_>
|
| 108 |
+
<!-- tree 3 -->
|
| 109 |
+
<_>
|
| 110 |
+
<internalNodes>
|
| 111 |
+
0 -1 8 -273 -135266321 1877977738 -2088243418 -134217987
|
| 112 |
+
2146926575 -18910642 1095231247</internalNodes>
|
| 113 |
+
<leafValues>
|
| 114 |
+
-0.6854077577590942 0.5403239130973816</leafValues></_></weakClassifiers></_>
|
| 115 |
+
<!-- stage 3 -->
|
| 116 |
+
<_>
|
| 117 |
+
<maxWeakCount>5</maxWeakCount>
|
| 118 |
+
<stageThreshold>-0.7562355995178223</stageThreshold>
|
| 119 |
+
<weakClassifiers>
|
| 120 |
+
<!-- tree 0 -->
|
| 121 |
+
<_>
|
| 122 |
+
<internalNodes>
|
| 123 |
+
0 -1 96 -1273 1870659519 -20971602 -67633153 -134250731
|
| 124 |
+
2004875127 -250 -150995969</internalNodes>
|
| 125 |
+
<leafValues>
|
| 126 |
+
-0.4051094949245453 0.7584033608436585</leafValues></_>
|
| 127 |
+
<!-- tree 1 -->
|
| 128 |
+
<_>
|
| 129 |
+
<internalNodes>
|
| 130 |
+
0 -1 33 -868162224 -76810262 -4262145 -257 1465211989
|
| 131 |
+
-268959873 -2656269 -524289</internalNodes>
|
| 132 |
+
<leafValues>
|
| 133 |
+
-0.7388162612915039 0.5340843200683594</leafValues></_>
|
| 134 |
+
<!-- tree 2 -->
|
| 135 |
+
<_>
|
| 136 |
+
<internalNodes>
|
| 137 |
+
0 -1 57 -12817 -49 -541103378 -152950 -38993 -20481 -1153876
|
| 138 |
+
-72478976</internalNodes>
|
| 139 |
+
<leafValues>
|
| 140 |
+
-0.6582943797111511 0.5339496731758118</leafValues></_>
|
| 141 |
+
<!-- tree 3 -->
|
| 142 |
+
<_>
|
| 143 |
+
<internalNodes>
|
| 144 |
+
0 -1 125 -269484161 -452984961 -319816180 -1594032130 -2111
|
| 145 |
+
-990117891 -488975296 -520947741</internalNodes>
|
| 146 |
+
<leafValues>
|
| 147 |
+
-0.5981323719024658 0.5323504805564880</leafValues></_>
|
| 148 |
+
<!-- tree 4 -->
|
| 149 |
+
<_>
|
| 150 |
+
<internalNodes>
|
| 151 |
+
0 -1 53 557787431 670265215 -1342193665 -1075892225
|
| 152 |
+
1998528318 1056964607 -33570977 -1</internalNodes>
|
| 153 |
+
<leafValues>
|
| 154 |
+
-0.6498787999153137 0.4913350641727448</leafValues></_></weakClassifiers></_>
|
| 155 |
+
<!-- stage 4 -->
|
| 156 |
+
<_>
|
| 157 |
+
<maxWeakCount>5</maxWeakCount>
|
| 158 |
+
<stageThreshold>-0.8085358142852783</stageThreshold>
|
| 159 |
+
<weakClassifiers>
|
| 160 |
+
<!-- tree 0 -->
|
| 161 |
+
<_>
|
| 162 |
+
<internalNodes>
|
| 163 |
+
0 -1 60 -536873708 880195381 -16842788 -20971521 -176687276
|
| 164 |
+
-168427659 -16777260 -33554626</internalNodes>
|
| 165 |
+
<leafValues>
|
| 166 |
+
-0.5278195738792419 0.6946372389793396</leafValues></_>
|
| 167 |
+
<!-- tree 1 -->
|
| 168 |
+
<_>
|
| 169 |
+
<internalNodes>
|
| 170 |
+
0 -1 7 -1 -62981529 -1090591130 805330978 -8388827 -41945787
|
| 171 |
+
-39577 -531118985</internalNodes>
|
| 172 |
+
<leafValues>
|
| 173 |
+
-0.5206505060195923 0.6329920291900635</leafValues></_>
|
| 174 |
+
<!-- tree 2 -->
|
| 175 |
+
<_>
|
| 176 |
+
<internalNodes>
|
| 177 |
+
0 -1 98 -725287348 1347747543 -852489 -16809993 1489881036
|
| 178 |
+
-167903241 -1 -1</internalNodes>
|
| 179 |
+
<leafValues>
|
| 180 |
+
-0.7516061067581177 0.4232024252414703</leafValues></_>
|
| 181 |
+
<!-- tree 3 -->
|
| 182 |
+
<_>
|
| 183 |
+
<internalNodes>
|
| 184 |
+
0 -1 44 -32777 1006582562 -65 935312171 -8388609 -1078198273
|
| 185 |
+
-1 733886267</internalNodes>
|
| 186 |
+
<leafValues>
|
| 187 |
+
-0.7639313936233521 0.4123568832874298</leafValues></_>
|
| 188 |
+
<!-- tree 4 -->
|
| 189 |
+
<_>
|
| 190 |
+
<internalNodes>
|
| 191 |
+
0 -1 24 -85474705 2138828511 -1036436754 817625855
|
| 192 |
+
1123369029 -58796809 -1013468481 -194513409</internalNodes>
|
| 193 |
+
<leafValues>
|
| 194 |
+
-0.5123769044876099 0.5791834592819214</leafValues></_></weakClassifiers></_>
|
| 195 |
+
<!-- stage 5 -->
|
| 196 |
+
<_>
|
| 197 |
+
<maxWeakCount>5</maxWeakCount>
|
| 198 |
+
<stageThreshold>-0.5549971461296082</stageThreshold>
|
| 199 |
+
<weakClassifiers>
|
| 200 |
+
<!-- tree 0 -->
|
| 201 |
+
<_>
|
| 202 |
+
<internalNodes>
|
| 203 |
+
0 -1 42 -17409 -20481 -268457797 -134239493 -17473 -1 -21829
|
| 204 |
+
-21846</internalNodes>
|
| 205 |
+
<leafValues>
|
| 206 |
+
-0.3763174116611481 0.7298233509063721</leafValues></_>
|
| 207 |
+
<!-- tree 1 -->
|
| 208 |
+
<_>
|
| 209 |
+
<internalNodes>
|
| 210 |
+
0 -1 6 -805310737 -2098262358 -269504725 682502698
|
| 211 |
+
2147483519 1740574719 -1090519233 -268472385</internalNodes>
|
| 212 |
+
<leafValues>
|
| 213 |
+
-0.5352765917778015 0.5659480094909668</leafValues></_>
|
| 214 |
+
<!-- tree 2 -->
|
| 215 |
+
<_>
|
| 216 |
+
<internalNodes>
|
| 217 |
+
0 -1 61 -67109678 -6145 -8 -87884584 -20481 -1073762305
|
| 218 |
+
-50856216 -16849696</internalNodes>
|
| 219 |
+
<leafValues>
|
| 220 |
+
-0.5678374171257019 0.4961479902267456</leafValues></_>
|
| 221 |
+
<!-- tree 3 -->
|
| 222 |
+
<_>
|
| 223 |
+
<internalNodes>
|
| 224 |
+
0 -1 123 -138428633 1002418167 -1359008245 -1908670465
|
| 225 |
+
-1346685918 910098423 -1359010520 -1346371657</internalNodes>
|
| 226 |
+
<leafValues>
|
| 227 |
+
-0.5706262588500977 0.4572288393974304</leafValues></_>
|
| 228 |
+
<!-- tree 4 -->
|
| 229 |
+
<_>
|
| 230 |
+
<internalNodes>
|
| 231 |
+
0 -1 9 -89138513 -4196353 1256531674 -1330665426 1216308261
|
| 232 |
+
-36190633 33498198 -151796633</internalNodes>
|
| 233 |
+
<leafValues>
|
| 234 |
+
-0.5344601869583130 0.4672054052352905</leafValues></_></weakClassifiers></_>
|
| 235 |
+
<!-- stage 6 -->
|
| 236 |
+
<_>
|
| 237 |
+
<maxWeakCount>5</maxWeakCount>
|
| 238 |
+
<stageThreshold>-0.8776460289955139</stageThreshold>
|
| 239 |
+
<weakClassifiers>
|
| 240 |
+
<!-- tree 0 -->
|
| 241 |
+
<_>
|
| 242 |
+
<internalNodes>
|
| 243 |
+
0 -1 105 1073769576 206601725 -34013449 -33554433 -789514004
|
| 244 |
+
-101384321 -690225153 -264193</internalNodes>
|
| 245 |
+
<leafValues>
|
| 246 |
+
-0.7700348496437073 0.5943940877914429</leafValues></_>
|
| 247 |
+
<!-- tree 1 -->
|
| 248 |
+
<_>
|
| 249 |
+
<internalNodes>
|
| 250 |
+
0 -1 30 -1432340997 -823623681 -49153 -34291724 -269484035
|
| 251 |
+
-1342767105 -1078198273 -1277955</internalNodes>
|
| 252 |
+
<leafValues>
|
| 253 |
+
-0.5043668746948242 0.6151274442672730</leafValues></_>
|
| 254 |
+
<!-- tree 2 -->
|
| 255 |
+
<_>
|
| 256 |
+
<internalNodes>
|
| 257 |
+
0 -1 35 -1067385040 -195758209 -436748425 -134217731
|
| 258 |
+
-50855988 -129 -1 -1</internalNodes>
|
| 259 |
+
<leafValues>
|
| 260 |
+
-0.6808040738105774 0.4667325913906097</leafValues></_>
|
| 261 |
+
<!-- tree 3 -->
|
| 262 |
+
<_>
|
| 263 |
+
<internalNodes>
|
| 264 |
+
0 -1 119 832534325 -34111555 -26050561 -423659521 -268468364
|
| 265 |
+
2105014143 -2114244 -17367185</internalNodes>
|
| 266 |
+
<leafValues>
|
| 267 |
+
-0.4927591383457184 0.5401885509490967</leafValues></_>
|
| 268 |
+
<!-- tree 4 -->
|
| 269 |
+
<_>
|
| 270 |
+
<internalNodes>
|
| 271 |
+
0 -1 82 -1089439888 -1080524865 2143059967 -1114121
|
| 272 |
+
-1140949004 -3 -2361356 -739516</internalNodes>
|
| 273 |
+
<leafValues>
|
| 274 |
+
-0.6445107460021973 0.4227822124958038</leafValues></_></weakClassifiers></_>
|
| 275 |
+
<!-- stage 7 -->
|
| 276 |
+
<_>
|
| 277 |
+
<maxWeakCount>6</maxWeakCount>
|
| 278 |
+
<stageThreshold>-1.1139287948608398</stageThreshold>
|
| 279 |
+
<weakClassifiers>
|
| 280 |
+
<!-- tree 0 -->
|
| 281 |
+
<_>
|
| 282 |
+
<internalNodes>
|
| 283 |
+
0 -1 52 -1074071553 -1074003969 -1 -1280135430 -5324817 -1
|
| 284 |
+
-335548482 582134442</internalNodes>
|
| 285 |
+
<leafValues>
|
| 286 |
+
-0.5307556986808777 0.6258179545402527</leafValues></_>
|
| 287 |
+
<!-- tree 1 -->
|
| 288 |
+
<_>
|
| 289 |
+
<internalNodes>
|
| 290 |
+
0 -1 99 -706937396 -705364068 -540016724 -570495027
|
| 291 |
+
-570630659 -587857963 -33628164 -35848193</internalNodes>
|
| 292 |
+
<leafValues>
|
| 293 |
+
-0.5227634310722351 0.5049746036529541</leafValues></_>
|
| 294 |
+
<!-- tree 2 -->
|
| 295 |
+
<_>
|
| 296 |
+
<internalNodes>
|
| 297 |
+
0 -1 18 -2035630093 42119158 -268503053 -1671444 261017599
|
| 298 |
+
1325432815 1954394111 -805306449</internalNodes>
|
| 299 |
+
<leafValues>
|
| 300 |
+
-0.4983572661876679 0.5106441378593445</leafValues></_>
|
| 301 |
+
<!-- tree 3 -->
|
| 302 |
+
<_>
|
| 303 |
+
<internalNodes>
|
| 304 |
+
0 -1 111 -282529488 -1558073088 1426018736 -170526448
|
| 305 |
+
-546832487 -5113037 -34243375 -570427929</internalNodes>
|
| 306 |
+
<leafValues>
|
| 307 |
+
-0.4990860521793366 0.5060507059097290</leafValues></_>
|
| 308 |
+
<!-- tree 4 -->
|
| 309 |
+
<_>
|
| 310 |
+
<internalNodes>
|
| 311 |
+
0 -1 92 1016332500 -606301707 915094269 -1080086049
|
| 312 |
+
-1837027144 -1361600280 2147318747 1067975613</internalNodes>
|
| 313 |
+
<leafValues>
|
| 314 |
+
-0.5695009231567383 0.4460467398166657</leafValues></_>
|
| 315 |
+
<!-- tree 5 -->
|
| 316 |
+
<_>
|
| 317 |
+
<internalNodes>
|
| 318 |
+
0 -1 51 -656420166 -15413034 -141599534 -603435836
|
| 319 |
+
1505950458 -787556946 -79823438 -1326199134</internalNodes>
|
| 320 |
+
<leafValues>
|
| 321 |
+
-0.6590405106544495 0.3616424500942230</leafValues></_></weakClassifiers></_>
|
| 322 |
+
<!-- stage 8 -->
|
| 323 |
+
<_>
|
| 324 |
+
<maxWeakCount>7</maxWeakCount>
|
| 325 |
+
<stageThreshold>-0.8243625760078430</stageThreshold>
|
| 326 |
+
<weakClassifiers>
|
| 327 |
+
<!-- tree 0 -->
|
| 328 |
+
<_>
|
| 329 |
+
<internalNodes>
|
| 330 |
+
0 -1 28 -901591776 -201916417 -262 -67371009 -143312112
|
| 331 |
+
-524289 -41943178 -1</internalNodes>
|
| 332 |
+
<leafValues>
|
| 333 |
+
-0.4972776770591736 0.6027074456214905</leafValues></_>
|
| 334 |
+
<!-- tree 1 -->
|
| 335 |
+
<_>
|
| 336 |
+
<internalNodes>
|
| 337 |
+
0 -1 112 -4507851 -411340929 -268437513 -67502145 -17350859
|
| 338 |
+
-32901 -71344315 -29377</internalNodes>
|
| 339 |
+
<leafValues>
|
| 340 |
+
-0.4383158981800079 0.5966237187385559</leafValues></_>
|
| 341 |
+
<!-- tree 2 -->
|
| 342 |
+
<_>
|
| 343 |
+
<internalNodes>
|
| 344 |
+
0 -1 69 -75894785 -117379438 -239063587 -12538500 1485072126
|
| 345 |
+
2076233213 2123118847 801906927</internalNodes>
|
| 346 |
+
<leafValues>
|
| 347 |
+
-0.6386105418205261 0.3977999985218048</leafValues></_>
|
| 348 |
+
<!-- tree 3 -->
|
| 349 |
+
<_>
|
| 350 |
+
<internalNodes>
|
| 351 |
+
0 -1 19 -823480413 786628589 -16876049 -1364262914 242165211
|
| 352 |
+
1315930109 -696268833 -455082829</internalNodes>
|
| 353 |
+
<leafValues>
|
| 354 |
+
-0.5512794256210327 0.4282079637050629</leafValues></_>
|
| 355 |
+
<!-- tree 4 -->
|
| 356 |
+
<_>
|
| 357 |
+
<internalNodes>
|
| 358 |
+
0 -1 73 -521411968 6746762 -1396236286 -2038436114
|
| 359 |
+
-185612509 57669627 -143132877 -1041235973</internalNodes>
|
| 360 |
+
<leafValues>
|
| 361 |
+
-0.6418755054473877 0.3549866080284119</leafValues></_>
|
| 362 |
+
<!-- tree 5 -->
|
| 363 |
+
<_>
|
| 364 |
+
<internalNodes>
|
| 365 |
+
0 -1 126 -478153869 1076028979 -1645895615 1365298272
|
| 366 |
+
-557859073 -339771473 1442574528 -1058802061</internalNodes>
|
| 367 |
+
<leafValues>
|
| 368 |
+
-0.4841901361942291 0.4668019413948059</leafValues></_>
|
| 369 |
+
<!-- tree 6 -->
|
| 370 |
+
<_>
|
| 371 |
+
<internalNodes>
|
| 372 |
+
0 -1 45 -246350404 -1650402048 -1610612745 -788400696
|
| 373 |
+
1467604861 -2787397 1476263935 -4481349</internalNodes>
|
| 374 |
+
<leafValues>
|
| 375 |
+
-0.5855734348297119 0.3879135847091675</leafValues></_></weakClassifiers></_>
|
| 376 |
+
<!-- stage 9 -->
|
| 377 |
+
<_>
|
| 378 |
+
<maxWeakCount>7</maxWeakCount>
|
| 379 |
+
<stageThreshold>-1.2237116098403931</stageThreshold>
|
| 380 |
+
<weakClassifiers>
|
| 381 |
+
<!-- tree 0 -->
|
| 382 |
+
<_>
|
| 383 |
+
<internalNodes>
|
| 384 |
+
0 -1 114 -24819 1572863935 -16809993 -67108865 2146778388
|
| 385 |
+
1433927541 -268608444 -34865205</internalNodes>
|
| 386 |
+
<leafValues>
|
| 387 |
+
-0.2518476545810700 0.7088654041290283</leafValues></_>
|
| 388 |
+
<!-- tree 1 -->
|
| 389 |
+
<_>
|
| 390 |
+
<internalNodes>
|
| 391 |
+
0 -1 97 -1841359 -134271049 -32769 -5767369 -1116675 -2185
|
| 392 |
+
-8231 -33603327</internalNodes>
|
| 393 |
+
<leafValues>
|
| 394 |
+
-0.4303432404994965 0.5283288359642029</leafValues></_>
|
| 395 |
+
<!-- tree 2 -->
|
| 396 |
+
<_>
|
| 397 |
+
<internalNodes>
|
| 398 |
+
0 -1 25 -1359507589 -1360593090 -1073778729 -269553812
|
| 399 |
+
-809512977 1744707583 -41959433 -134758978</internalNodes>
|
| 400 |
+
<leafValues>
|
| 401 |
+
-0.4259553551673889 0.5440809130668640</leafValues></_>
|
| 402 |
+
<!-- tree 3 -->
|
| 403 |
+
<_>
|
| 404 |
+
<internalNodes>
|
| 405 |
+
0 -1 34 729753407 -134270989 -1140907329 -235200777
|
| 406 |
+
658456383 2147467263 -1140900929 -16385</internalNodes>
|
| 407 |
+
<leafValues>
|
| 408 |
+
-0.5605589151382446 0.4220733344554901</leafValues></_>
|
| 409 |
+
<!-- tree 4 -->
|
| 410 |
+
<_>
|
| 411 |
+
<internalNodes>
|
| 412 |
+
0 -1 134 -310380553 -420675595 -193005472 -353568129
|
| 413 |
+
1205338070 -990380036 887604324 -420544526</internalNodes>
|
| 414 |
+
<leafValues>
|
| 415 |
+
-0.5192656517028809 0.4399855434894562</leafValues></_>
|
| 416 |
+
<!-- tree 5 -->
|
| 417 |
+
<_>
|
| 418 |
+
<internalNodes>
|
| 419 |
+
0 -1 16 -1427119361 1978920959 -287119734 -487068946
|
| 420 |
+
114759245 -540578051 -707510259 -671660453</internalNodes>
|
| 421 |
+
<leafValues>
|
| 422 |
+
-0.5013077259063721 0.4570254683494568</leafValues></_>
|
| 423 |
+
<!-- tree 6 -->
|
| 424 |
+
<_>
|
| 425 |
+
<internalNodes>
|
| 426 |
+
0 -1 74 -738463762 -889949281 -328301948 -121832450
|
| 427 |
+
-1142658284 -1863576559 2146417353 -263185</internalNodes>
|
| 428 |
+
<leafValues>
|
| 429 |
+
-0.4631414115428925 0.4790246188640595</leafValues></_></weakClassifiers></_>
|
| 430 |
+
<!-- stage 10 -->
|
| 431 |
+
<_>
|
| 432 |
+
<maxWeakCount>7</maxWeakCount>
|
| 433 |
+
<stageThreshold>-0.5544230937957764</stageThreshold>
|
| 434 |
+
<weakClassifiers>
|
| 435 |
+
<!-- tree 0 -->
|
| 436 |
+
<_>
|
| 437 |
+
<internalNodes>
|
| 438 |
+
0 -1 113 -76228780 -65538 -1 -67174401 -148007 -33 -221796
|
| 439 |
+
-272842924</internalNodes>
|
| 440 |
+
<leafValues>
|
| 441 |
+
-0.3949716091156006 0.6082032322883606</leafValues></_>
|
| 442 |
+
<!-- tree 1 -->
|
| 443 |
+
<_>
|
| 444 |
+
<internalNodes>
|
| 445 |
+
0 -1 110 369147696 -1625232112 2138570036 -1189900 790708019
|
| 446 |
+
-1212613127 799948719 -4456483</internalNodes>
|
| 447 |
+
<leafValues>
|
| 448 |
+
-0.4855885505676270 0.4785369932651520</leafValues></_>
|
| 449 |
+
<!-- tree 2 -->
|
| 450 |
+
<_>
|
| 451 |
+
<internalNodes>
|
| 452 |
+
0 -1 37 784215839 -290015241 536832799 -402984963
|
| 453 |
+
-1342414991 -838864897 -176769 -268456129</internalNodes>
|
| 454 |
+
<leafValues>
|
| 455 |
+
-0.4620285332202911 0.4989669024944305</leafValues></_>
|
| 456 |
+
<!-- tree 3 -->
|
| 457 |
+
<_>
|
| 458 |
+
<internalNodes>
|
| 459 |
+
0 -1 41 -486418688 -171915327 -340294900 -21938 -519766032
|
| 460 |
+
-772751172 -73096060 -585322623</internalNodes>
|
| 461 |
+
<leafValues>
|
| 462 |
+
-0.6420643329620361 0.3624351918697357</leafValues></_>
|
| 463 |
+
<!-- tree 4 -->
|
| 464 |
+
<_>
|
| 465 |
+
<internalNodes>
|
| 466 |
+
0 -1 117 -33554953 -475332625 -1423463824 -2077230421
|
| 467 |
+
-4849669 -2080505925 -219032928 -1071915349</internalNodes>
|
| 468 |
+
<leafValues>
|
| 469 |
+
-0.4820112884044647 0.4632140696048737</leafValues></_>
|
| 470 |
+
<!-- tree 5 -->
|
| 471 |
+
<_>
|
| 472 |
+
<internalNodes>
|
| 473 |
+
0 -1 65 -834130468 -134217476 -1349314083 -1073803559
|
| 474 |
+
-619913764 -1449131844 -1386890321 -1979118423</internalNodes>
|
| 475 |
+
<leafValues>
|
| 476 |
+
-0.4465552568435669 0.5061788558959961</leafValues></_>
|
| 477 |
+
<!-- tree 6 -->
|
| 478 |
+
<_>
|
| 479 |
+
<internalNodes>
|
| 480 |
+
0 -1 56 -285249779 1912569855 -16530 -1731022870 -1161904146
|
| 481 |
+
-1342177297 -268439634 -1464078708</internalNodes>
|
| 482 |
+
<leafValues>
|
| 483 |
+
-0.5190586447715759 0.4441480338573456</leafValues></_></weakClassifiers></_>
|
| 484 |
+
<!-- stage 11 -->
|
| 485 |
+
<_>
|
| 486 |
+
<maxWeakCount>7</maxWeakCount>
|
| 487 |
+
<stageThreshold>-0.7161560654640198</stageThreshold>
|
| 488 |
+
<weakClassifiers>
|
| 489 |
+
<!-- tree 0 -->
|
| 490 |
+
<_>
|
| 491 |
+
<internalNodes>
|
| 492 |
+
0 -1 20 1246232575 1078001186 -10027057 60102 -277348353
|
| 493 |
+
-43646987 -1210581153 1195769615</internalNodes>
|
| 494 |
+
<leafValues>
|
| 495 |
+
-0.4323809444904327 0.5663768053054810</leafValues></_>
|
| 496 |
+
<!-- tree 1 -->
|
| 497 |
+
<_>
|
| 498 |
+
<internalNodes>
|
| 499 |
+
0 -1 15 -778583572 -612921106 -578775890 -4036478
|
| 500 |
+
-1946580497 -1164766570 -1986687009 -12103599</internalNodes>
|
| 501 |
+
<leafValues>
|
| 502 |
+
-0.4588732719421387 0.4547033011913300</leafValues></_>
|
| 503 |
+
<!-- tree 2 -->
|
| 504 |
+
<_>
|
| 505 |
+
<internalNodes>
|
| 506 |
+
0 -1 129 -1073759445 2013231743 -1363169553 -1082459201
|
| 507 |
+
-1414286549 868185983 -1356133589 -1077936257</internalNodes>
|
| 508 |
+
<leafValues>
|
| 509 |
+
-0.5218553543090820 0.4111092388629913</leafValues></_>
|
| 510 |
+
<!-- tree 3 -->
|
| 511 |
+
<_>
|
| 512 |
+
<internalNodes>
|
| 513 |
+
0 -1 102 -84148365 -2093417722 -1204850272 564290299
|
| 514 |
+
-67121221 -1342177350 -1309195902 -776734797</internalNodes>
|
| 515 |
+
<leafValues>
|
| 516 |
+
-0.4920000731945038 0.4326725304126740</leafValues></_>
|
| 517 |
+
<!-- tree 4 -->
|
| 518 |
+
<_>
|
| 519 |
+
<internalNodes>
|
| 520 |
+
0 -1 88 -25694458 67104495 -290216278 -168563037 2083877442
|
| 521 |
+
1702788383 -144191964 -234882162</internalNodes>
|
| 522 |
+
<leafValues>
|
| 523 |
+
-0.4494568109512329 0.4448510706424713</leafValues></_>
|
| 524 |
+
<!-- tree 5 -->
|
| 525 |
+
<_>
|
| 526 |
+
<internalNodes>
|
| 527 |
+
0 -1 59 -857980836 904682741 -1612267521 232279415
|
| 528 |
+
1550862252 -574825221 -357380888 -4579409</internalNodes>
|
| 529 |
+
<leafValues>
|
| 530 |
+
-0.5180826783180237 0.3888972699642181</leafValues></_>
|
| 531 |
+
<!-- tree 6 -->
|
| 532 |
+
<_>
|
| 533 |
+
<internalNodes>
|
| 534 |
+
0 -1 27 -98549440 -137838400 494928389 -246013630 939541351
|
| 535 |
+
-1196072350 -620603549 2137216273</internalNodes>
|
| 536 |
+
<leafValues>
|
| 537 |
+
-0.6081240773200989 0.3333222270011902</leafValues></_></weakClassifiers></_>
|
| 538 |
+
<!-- stage 12 -->
|
| 539 |
+
<_>
|
| 540 |
+
<maxWeakCount>8</maxWeakCount>
|
| 541 |
+
<stageThreshold>-0.6743940711021423</stageThreshold>
|
| 542 |
+
<weakClassifiers>
|
| 543 |
+
<!-- tree 0 -->
|
| 544 |
+
<_>
|
| 545 |
+
<internalNodes>
|
| 546 |
+
0 -1 29 -150995201 2071191945 -1302151626 536934335
|
| 547 |
+
-1059008937 914128709 1147328110 -268369925</internalNodes>
|
| 548 |
+
<leafValues>
|
| 549 |
+
-0.1790193915367127 0.6605972051620483</leafValues></_>
|
| 550 |
+
<!-- tree 1 -->
|
| 551 |
+
<_>
|
| 552 |
+
<internalNodes>
|
| 553 |
+
0 -1 128 -134509479 1610575703 -1342177289 1861484541
|
| 554 |
+
-1107833788 1577058173 -333558568 -136319041</internalNodes>
|
| 555 |
+
<leafValues>
|
| 556 |
+
-0.3681024610996246 0.5139749646186829</leafValues></_>
|
| 557 |
+
<!-- tree 2 -->
|
| 558 |
+
<_>
|
| 559 |
+
<internalNodes>
|
| 560 |
+
0 -1 70 -1 1060154476 -1090984524 -630918524 -539492875
|
| 561 |
+
779616255 -839568424 -321</internalNodes>
|
| 562 |
+
<leafValues>
|
| 563 |
+
-0.3217232525348663 0.6171553134918213</leafValues></_>
|
| 564 |
+
<!-- tree 3 -->
|
| 565 |
+
<_>
|
| 566 |
+
<internalNodes>
|
| 567 |
+
0 -1 4 -269562385 -285029906 -791084350 -17923776 235286671
|
| 568 |
+
1275504943 1344390399 -966276889</internalNodes>
|
| 569 |
+
<leafValues>
|
| 570 |
+
-0.4373284578323364 0.4358185231685638</leafValues></_>
|
| 571 |
+
<!-- tree 4 -->
|
| 572 |
+
<_>
|
| 573 |
+
<internalNodes>
|
| 574 |
+
0 -1 76 17825984 -747628419 595427229 1474759671 575672208
|
| 575 |
+
-1684005538 872217086 -1155858277</internalNodes>
|
| 576 |
+
<leafValues>
|
| 577 |
+
-0.4404836893081665 0.4601220190525055</leafValues></_>
|
| 578 |
+
<!-- tree 5 -->
|
| 579 |
+
<_>
|
| 580 |
+
<internalNodes>
|
| 581 |
+
0 -1 124 -336593039 1873735591 -822231622 -355795238
|
| 582 |
+
-470820869 -1997537409 -1057132384 -1015285005</internalNodes>
|
| 583 |
+
<leafValues>
|
| 584 |
+
-0.4294152259826660 0.4452161788940430</leafValues></_>
|
| 585 |
+
<!-- tree 6 -->
|
| 586 |
+
<_>
|
| 587 |
+
<internalNodes>
|
| 588 |
+
0 -1 54 -834212130 -593694721 -322142257 -364892500
|
| 589 |
+
-951029539 -302125121 -1615106053 -79249765</internalNodes>
|
| 590 |
+
<leafValues>
|
| 591 |
+
-0.3973052501678467 0.4854526817798615</leafValues></_>
|
| 592 |
+
<!-- tree 7 -->
|
| 593 |
+
<_>
|
| 594 |
+
<internalNodes>
|
| 595 |
+
0 -1 95 1342144479 2147431935 -33554561 -47873 -855685912 -1
|
| 596 |
+
1988052447 536827383</internalNodes>
|
| 597 |
+
<leafValues>
|
| 598 |
+
-0.7054683566093445 0.2697997391223908</leafValues></_></weakClassifiers></_>
|
| 599 |
+
<!-- stage 13 -->
|
| 600 |
+
<_>
|
| 601 |
+
<maxWeakCount>9</maxWeakCount>
|
| 602 |
+
<stageThreshold>-1.2042298316955566</stageThreshold>
|
| 603 |
+
<weakClassifiers>
|
| 604 |
+
<!-- tree 0 -->
|
| 605 |
+
<_>
|
| 606 |
+
<internalNodes>
|
| 607 |
+
0 -1 39 1431368960 -183437936 -537002499 -137497097
|
| 608 |
+
1560590321 -84611081 -2097193 -513</internalNodes>
|
| 609 |
+
<leafValues>
|
| 610 |
+
-0.5905947685241699 0.5101932883262634</leafValues></_>
|
| 611 |
+
<!-- tree 1 -->
|
| 612 |
+
<_>
|
| 613 |
+
<internalNodes>
|
| 614 |
+
0 -1 120 -1645259691 2105491231 2130706431 1458995007
|
| 615 |
+
-8567536 -42483883 -33780003 -21004417</internalNodes>
|
| 616 |
+
<leafValues>
|
| 617 |
+
-0.4449204802513123 0.4490709304809570</leafValues></_>
|
| 618 |
+
<!-- tree 2 -->
|
| 619 |
+
<_>
|
| 620 |
+
<internalNodes>
|
| 621 |
+
0 -1 89 -612381022 -505806938 -362027516 -452985106
|
| 622 |
+
275854917 1920431639 -12600561 -134221825</internalNodes>
|
| 623 |
+
<leafValues>
|
| 624 |
+
-0.4693818688392639 0.4061094820499420</leafValues></_>
|
| 625 |
+
<!-- tree 3 -->
|
| 626 |
+
<_>
|
| 627 |
+
<internalNodes>
|
| 628 |
+
0 -1 14 -805573153 -161 -554172679 -530519488 -16779441
|
| 629 |
+
2000682871 -33604275 -150997129</internalNodes>
|
| 630 |
+
<leafValues>
|
| 631 |
+
-0.3600351214408875 0.5056326985359192</leafValues></_>
|
| 632 |
+
<!-- tree 4 -->
|
| 633 |
+
<_>
|
| 634 |
+
<internalNodes>
|
| 635 |
+
0 -1 67 6192 435166195 1467449341 2046691505 -1608493775
|
| 636 |
+
-4755729 -1083162625 -71365637</internalNodes>
|
| 637 |
+
<leafValues>
|
| 638 |
+
-0.4459891915321350 0.4132415652275085</leafValues></_>
|
| 639 |
+
<!-- tree 5 -->
|
| 640 |
+
<_>
|
| 641 |
+
<internalNodes>
|
| 642 |
+
0 -1 86 -41689215 -3281034 1853357967 -420712635 -415924289
|
| 643 |
+
-270209208 -1088293113 -825311232</internalNodes>
|
| 644 |
+
<leafValues>
|
| 645 |
+
-0.4466069042682648 0.4135067760944367</leafValues></_>
|
| 646 |
+
<!-- tree 6 -->
|
| 647 |
+
<_>
|
| 648 |
+
<internalNodes>
|
| 649 |
+
0 -1 80 -117391116 -42203396 2080374461 -188709 -542008165
|
| 650 |
+
-356831940 -1091125345 -1073796897</internalNodes>
|
| 651 |
+
<leafValues>
|
| 652 |
+
-0.3394956290721893 0.5658645033836365</leafValues></_>
|
| 653 |
+
<!-- tree 7 -->
|
| 654 |
+
<_>
|
| 655 |
+
<internalNodes>
|
| 656 |
+
0 -1 75 -276830049 1378714472 -1342181951 757272098
|
| 657 |
+
1073740607 -282199241 -415761549 170896931</internalNodes>
|
| 658 |
+
<leafValues>
|
| 659 |
+
-0.5346512198448181 0.3584479391574860</leafValues></_>
|
| 660 |
+
<!-- tree 8 -->
|
| 661 |
+
<_>
|
| 662 |
+
<internalNodes>
|
| 663 |
+
0 -1 55 -796075825 -123166849 2113667055 -217530421
|
| 664 |
+
-1107432194 -16385 -806359809 -391188771</internalNodes>
|
| 665 |
+
<leafValues>
|
| 666 |
+
-0.4379335641860962 0.4123645126819611</leafValues></_></weakClassifiers></_>
|
| 667 |
+
<!-- stage 14 -->
|
| 668 |
+
<_>
|
| 669 |
+
<maxWeakCount>10</maxWeakCount>
|
| 670 |
+
<stageThreshold>-0.8402050137519836</stageThreshold>
|
| 671 |
+
<weakClassifiers>
|
| 672 |
+
<!-- tree 0 -->
|
| 673 |
+
<_>
|
| 674 |
+
<internalNodes>
|
| 675 |
+
0 -1 71 -890246622 15525883 -487690486 47116238 -1212319899
|
| 676 |
+
-1291847681 -68159890 -469829921</internalNodes>
|
| 677 |
+
<leafValues>
|
| 678 |
+
-0.2670986354351044 0.6014143228530884</leafValues></_>
|
| 679 |
+
<!-- tree 1 -->
|
| 680 |
+
<_>
|
| 681 |
+
<internalNodes>
|
| 682 |
+
0 -1 31 -1361180685 -1898008841 -1090588811 -285410071
|
| 683 |
+
-1074016265 -840443905 2147221487 -262145</internalNodes>
|
| 684 |
+
<leafValues>
|
| 685 |
+
-0.4149844348430634 0.4670888185501099</leafValues></_>
|
| 686 |
+
<!-- tree 2 -->
|
| 687 |
+
<_>
|
| 688 |
+
<internalNodes>
|
| 689 |
+
0 -1 40 1426190596 1899364271 2142731795 -142607505
|
| 690 |
+
-508232452 -21563393 -41960001 -65</internalNodes>
|
| 691 |
+
<leafValues>
|
| 692 |
+
-0.4985891580581665 0.3719584941864014</leafValues></_>
|
| 693 |
+
<!-- tree 3 -->
|
| 694 |
+
<_>
|
| 695 |
+
<internalNodes>
|
| 696 |
+
0 -1 109 -201337965 10543906 -236498096 -746195597
|
| 697 |
+
1974565825 -15204415 921907633 -190058309</internalNodes>
|
| 698 |
+
<leafValues>
|
| 699 |
+
-0.4568729996681213 0.3965812027454376</leafValues></_>
|
| 700 |
+
<!-- tree 4 -->
|
| 701 |
+
<_>
|
| 702 |
+
<internalNodes>
|
| 703 |
+
0 -1 130 -595026732 -656401928 -268649235 -571490699
|
| 704 |
+
-440600392 -133131 -358810952 -2004088646</internalNodes>
|
| 705 |
+
<leafValues>
|
| 706 |
+
-0.4770836830139160 0.3862601518630981</leafValues></_>
|
| 707 |
+
<!-- tree 5 -->
|
| 708 |
+
<_>
|
| 709 |
+
<internalNodes>
|
| 710 |
+
0 -1 66 941674740 -1107882114 1332789109 -67691015
|
| 711 |
+
-1360463693 -1556612430 -609108546 733546933</internalNodes>
|
| 712 |
+
<leafValues>
|
| 713 |
+
-0.4877715110778809 0.3778986334800720</leafValues></_>
|
| 714 |
+
<!-- tree 6 -->
|
| 715 |
+
<_>
|
| 716 |
+
<internalNodes>
|
| 717 |
+
0 -1 49 -17114945 -240061474 1552871558 -82775604 -932393844
|
| 718 |
+
-1308544889 -532635478 -99042357</internalNodes>
|
| 719 |
+
<leafValues>
|
| 720 |
+
-0.3721654713153839 0.4994400143623352</leafValues></_>
|
| 721 |
+
<!-- tree 7 -->
|
| 722 |
+
<_>
|
| 723 |
+
<internalNodes>
|
| 724 |
+
0 -1 133 -655906006 1405502603 -939205164 1884929228
|
| 725 |
+
-498859222 559417357 -1928559445 -286264385</internalNodes>
|
| 726 |
+
<leafValues>
|
| 727 |
+
-0.3934195041656494 0.4769641458988190</leafValues></_>
|
| 728 |
+
<!-- tree 8 -->
|
| 729 |
+
<_>
|
| 730 |
+
<internalNodes>
|
| 731 |
+
0 -1 0 -335837777 1860677295 -90 -1946186226 931096183
|
| 732 |
+
251612987 2013265917 -671232197</internalNodes>
|
| 733 |
+
<leafValues>
|
| 734 |
+
-0.4323300719261169 0.4342164099216461</leafValues></_>
|
| 735 |
+
<!-- tree 9 -->
|
| 736 |
+
<_>
|
| 737 |
+
<internalNodes>
|
| 738 |
+
0 -1 103 37769424 -137772680 374692301 2002666345 -536176194
|
| 739 |
+
-1644484728 807009019 1069089930</internalNodes>
|
| 740 |
+
<leafValues>
|
| 741 |
+
-0.4993278682231903 0.3665378093719482</leafValues></_></weakClassifiers></_>
|
| 742 |
+
<!-- stage 15 -->
|
| 743 |
+
<_>
|
| 744 |
+
<maxWeakCount>9</maxWeakCount>
|
| 745 |
+
<stageThreshold>-1.1974394321441650</stageThreshold>
|
| 746 |
+
<weakClassifiers>
|
| 747 |
+
<!-- tree 0 -->
|
| 748 |
+
<_>
|
| 749 |
+
<internalNodes>
|
| 750 |
+
0 -1 43 -5505 2147462911 2143265466 -4511070 -16450 -257
|
| 751 |
+
-201348440 -71333206</internalNodes>
|
| 752 |
+
<leafValues>
|
| 753 |
+
-0.3310225307941437 0.5624626278877258</leafValues></_>
|
| 754 |
+
<!-- tree 1 -->
|
| 755 |
+
<_>
|
| 756 |
+
<internalNodes>
|
| 757 |
+
0 -1 90 -136842268 -499330741 2015250980 -87107126
|
| 758 |
+
-641665744 -788524639 -1147864792 -134892563</internalNodes>
|
| 759 |
+
<leafValues>
|
| 760 |
+
-0.5266560912132263 0.3704403042793274</leafValues></_>
|
| 761 |
+
<!-- tree 2 -->
|
| 762 |
+
<_>
|
| 763 |
+
<internalNodes>
|
| 764 |
+
0 -1 104 -146800880 -1780368555 2111170033 -140904684
|
| 765 |
+
-16777551 -1946681885 -1646463595 -839131947</internalNodes>
|
| 766 |
+
<leafValues>
|
| 767 |
+
-0.4171888828277588 0.4540435671806335</leafValues></_>
|
| 768 |
+
<!-- tree 3 -->
|
| 769 |
+
<_>
|
| 770 |
+
<internalNodes>
|
| 771 |
+
0 -1 85 -832054034 -981663763 -301990281 -578814081
|
| 772 |
+
-932319000 -1997406723 -33555201 -69206017</internalNodes>
|
| 773 |
+
<leafValues>
|
| 774 |
+
-0.4556705355644226 0.3704262077808380</leafValues></_>
|
| 775 |
+
<!-- tree 4 -->
|
| 776 |
+
<_>
|
| 777 |
+
<internalNodes>
|
| 778 |
+
0 -1 24 -118492417 -1209026825 1119023838 -1334313353
|
| 779 |
+
1112948738 -297319313 1378887291 -139469193</internalNodes>
|
| 780 |
+
<leafValues>
|
| 781 |
+
-0.4182529747486115 0.4267231225967407</leafValues></_>
|
| 782 |
+
<!-- tree 5 -->
|
| 783 |
+
<_>
|
| 784 |
+
<internalNodes>
|
| 785 |
+
0 -1 78 -1714382628 -2353704 -112094959 -549613092
|
| 786 |
+
-1567058760 -1718550464 -342315012 -1074972227</internalNodes>
|
| 787 |
+
<leafValues>
|
| 788 |
+
-0.3625369668006897 0.4684656262397766</leafValues></_>
|
| 789 |
+
<!-- tree 6 -->
|
| 790 |
+
<_>
|
| 791 |
+
<internalNodes>
|
| 792 |
+
0 -1 5 -85219702 316836394 -33279 1904970288 2117267315
|
| 793 |
+
-260901769 -621461759 -88607770</internalNodes>
|
| 794 |
+
<leafValues>
|
| 795 |
+
-0.4742925167083740 0.3689507246017456</leafValues></_>
|
| 796 |
+
<!-- tree 7 -->
|
| 797 |
+
<_>
|
| 798 |
+
<internalNodes>
|
| 799 |
+
0 -1 11 -294654041 -353603585 -1641159686 -50331921
|
| 800 |
+
-2080899877 1145569279 -143132713 -152044037</internalNodes>
|
| 801 |
+
<leafValues>
|
| 802 |
+
-0.3666271567344666 0.4580127298831940</leafValues></_>
|
| 803 |
+
<!-- tree 8 -->
|
| 804 |
+
<_>
|
| 805 |
+
<internalNodes>
|
| 806 |
+
0 -1 32 1887453658 -638545712 -1877976819 -34320972
|
| 807 |
+
-1071067983 -661345416 -583338277 1060190561</internalNodes>
|
| 808 |
+
<leafValues>
|
| 809 |
+
-0.4567637443542481 0.3894708156585693</leafValues></_></weakClassifiers></_>
|
| 810 |
+
<!-- stage 16 -->
|
| 811 |
+
<_>
|
| 812 |
+
<maxWeakCount>9</maxWeakCount>
|
| 813 |
+
<stageThreshold>-0.5733128190040588</stageThreshold>
|
| 814 |
+
<weakClassifiers>
|
| 815 |
+
<!-- tree 0 -->
|
| 816 |
+
<_>
|
| 817 |
+
<internalNodes>
|
| 818 |
+
0 -1 122 -994063296 1088745462 -318837116 -319881377
|
| 819 |
+
1102566613 1165490103 -121679694 -134744129</internalNodes>
|
| 820 |
+
<leafValues>
|
| 821 |
+
-0.4055117964744568 0.5487945079803467</leafValues></_>
|
| 822 |
+
<!-- tree 1 -->
|
| 823 |
+
<_>
|
| 824 |
+
<internalNodes>
|
| 825 |
+
0 -1 68 -285233233 -538992907 1811935199 -369234005 -529
|
| 826 |
+
-20593 -20505 -1561401854</internalNodes>
|
| 827 |
+
<leafValues>
|
| 828 |
+
-0.3787897229194641 0.4532003402709961</leafValues></_>
|
| 829 |
+
<!-- tree 2 -->
|
| 830 |
+
<_>
|
| 831 |
+
<internalNodes>
|
| 832 |
+
0 -1 58 -1335245632 1968917183 1940861695 536816369
|
| 833 |
+
-1226071367 -570908176 457026619 1000020667</internalNodes>
|
| 834 |
+
<leafValues>
|
| 835 |
+
-0.4258328974246979 0.4202791750431061</leafValues></_>
|
| 836 |
+
<!-- tree 3 -->
|
| 837 |
+
<_>
|
| 838 |
+
<internalNodes>
|
| 839 |
+
0 -1 94 -1360318719 -1979797897 -50435249 -18646473
|
| 840 |
+
-608879292 -805306691 -269304244 -17840167</internalNodes>
|
| 841 |
+
<leafValues>
|
| 842 |
+
-0.4561023116111755 0.4002747833728790</leafValues></_>
|
| 843 |
+
<!-- tree 4 -->
|
| 844 |
+
<_>
|
| 845 |
+
<internalNodes>
|
| 846 |
+
0 -1 87 2062765935 -16449 -1275080721 -16406 45764335
|
| 847 |
+
-1090552065 -772846337 -570464322</internalNodes>
|
| 848 |
+
<leafValues>
|
| 849 |
+
-0.4314672648906708 0.4086346626281738</leafValues></_>
|
| 850 |
+
<!-- tree 5 -->
|
| 851 |
+
<_>
|
| 852 |
+
<internalNodes>
|
| 853 |
+
0 -1 127 -536896021 1080817663 -738234288 -965478709
|
| 854 |
+
-2082767969 1290855887 1993822934 -990381609</internalNodes>
|
| 855 |
+
<leafValues>
|
| 856 |
+
-0.4174543321132660 0.4249868988990784</leafValues></_>
|
| 857 |
+
<!-- tree 6 -->
|
| 858 |
+
<_>
|
| 859 |
+
<internalNodes>
|
| 860 |
+
0 -1 3 -818943025 168730891 -293610428 -79249354 669224671
|
| 861 |
+
621166734 1086506807 1473768907</internalNodes>
|
| 862 |
+
<leafValues>
|
| 863 |
+
-0.4321364760398865 0.4090838730335236</leafValues></_>
|
| 864 |
+
<!-- tree 7 -->
|
| 865 |
+
<_>
|
| 866 |
+
<internalNodes>
|
| 867 |
+
0 -1 79 -68895696 -67107736 -1414315879 -841676168
|
| 868 |
+
-619843344 -1180610531 -1081990469 1043203389</internalNodes>
|
| 869 |
+
<leafValues>
|
| 870 |
+
-0.5018386244773865 0.3702533841133118</leafValues></_>
|
| 871 |
+
<!-- tree 8 -->
|
| 872 |
+
<_>
|
| 873 |
+
<internalNodes>
|
| 874 |
+
0 -1 116 -54002134 -543485719 -2124882422 -1437445858
|
| 875 |
+
-115617074 -1195787391 -1096024366 -2140472445</internalNodes>
|
| 876 |
+
<leafValues>
|
| 877 |
+
-0.5037505626678467 0.3564981222152710</leafValues></_></weakClassifiers></_>
|
| 878 |
+
<!-- stage 17 -->
|
| 879 |
+
<_>
|
| 880 |
+
<maxWeakCount>9</maxWeakCount>
|
| 881 |
+
<stageThreshold>-0.4892596900463104</stageThreshold>
|
| 882 |
+
<weakClassifiers>
|
| 883 |
+
<!-- tree 0 -->
|
| 884 |
+
<_>
|
| 885 |
+
<internalNodes>
|
| 886 |
+
0 -1 132 -67113211 2003808111 1862135111 846461923 -2752
|
| 887 |
+
2002237273 -273154752 1937223539</internalNodes>
|
| 888 |
+
<leafValues>
|
| 889 |
+
-0.2448196411132813 0.5689709186553955</leafValues></_>
|
| 890 |
+
<!-- tree 1 -->
|
| 891 |
+
<_>
|
| 892 |
+
<internalNodes>
|
| 893 |
+
0 -1 62 1179423888 -78064940 -611839555 -539167899
|
| 894 |
+
-1289358360 -1650810108 -892540499 -1432827684</internalNodes>
|
| 895 |
+
<leafValues>
|
| 896 |
+
-0.4633283913135529 0.3587929606437683</leafValues></_>
|
| 897 |
+
<!-- tree 2 -->
|
| 898 |
+
<_>
|
| 899 |
+
<internalNodes>
|
| 900 |
+
0 -1 23 -285212705 -78450761 -656212031 -264050110 -27787425
|
| 901 |
+
-1334349961 -547662981 -135796924</internalNodes>
|
| 902 |
+
<leafValues>
|
| 903 |
+
-0.3731099069118500 0.4290455579757690</leafValues></_>
|
| 904 |
+
<!-- tree 3 -->
|
| 905 |
+
<_>
|
| 906 |
+
<internalNodes>
|
| 907 |
+
0 -1 77 341863476 403702016 -550588417 1600194541
|
| 908 |
+
-1080690735 951127993 -1388580949 -1153717473</internalNodes>
|
| 909 |
+
<leafValues>
|
| 910 |
+
-0.3658909499645233 0.4556473195552826</leafValues></_>
|
| 911 |
+
<!-- tree 4 -->
|
| 912 |
+
<_>
|
| 913 |
+
<internalNodes>
|
| 914 |
+
0 -1 22 -586880702 -204831512 -100644596 -39319550
|
| 915 |
+
-1191150794 705692513 457203315 -75806957</internalNodes>
|
| 916 |
+
<leafValues>
|
| 917 |
+
-0.5214384198188782 0.3221037387847900</leafValues></_>
|
| 918 |
+
<!-- tree 5 -->
|
| 919 |
+
<_>
|
| 920 |
+
<internalNodes>
|
| 921 |
+
0 -1 72 -416546870 545911370 -673716192 -775559454
|
| 922 |
+
-264113598 139424 -183369982 -204474641</internalNodes>
|
| 923 |
+
<leafValues>
|
| 924 |
+
-0.4289036989212036 0.4004956185817719</leafValues></_>
|
| 925 |
+
<!-- tree 6 -->
|
| 926 |
+
<_>
|
| 927 |
+
<internalNodes>
|
| 928 |
+
0 -1 50 -1026505020 -589692154 -1740499937 -1563770497
|
| 929 |
+
1348491006 -60710713 -1109853489 -633909413</internalNodes>
|
| 930 |
+
<leafValues>
|
| 931 |
+
-0.4621542394161224 0.3832748532295227</leafValues></_>
|
| 932 |
+
<!-- tree 7 -->
|
| 933 |
+
<_>
|
| 934 |
+
<internalNodes>
|
| 935 |
+
0 -1 108 -1448872304 -477895040 -1778390608 -772418127
|
| 936 |
+
-1789923416 -1612057181 -805306693 -1415842113</internalNodes>
|
| 937 |
+
<leafValues>
|
| 938 |
+
-0.3711548447608948 0.4612701535224915</leafValues></_>
|
| 939 |
+
<!-- tree 8 -->
|
| 940 |
+
<_>
|
| 941 |
+
<internalNodes>
|
| 942 |
+
0 -1 92 407905424 -582449988 52654751 -1294472 -285103725
|
| 943 |
+
-74633006 1871559083 1057955850</internalNodes>
|
| 944 |
+
<leafValues>
|
| 945 |
+
-0.5180652141571045 0.3205870389938355</leafValues></_></weakClassifiers></_>
|
| 946 |
+
<!-- stage 18 -->
|
| 947 |
+
<_>
|
| 948 |
+
<maxWeakCount>10</maxWeakCount>
|
| 949 |
+
<stageThreshold>-0.5911940932273865</stageThreshold>
|
| 950 |
+
<weakClassifiers>
|
| 951 |
+
<!-- tree 0 -->
|
| 952 |
+
<_>
|
| 953 |
+
<internalNodes>
|
| 954 |
+
0 -1 81 4112 -1259563825 -846671428 -100902460 1838164148
|
| 955 |
+
-74153752 -90653988 -1074263896</internalNodes>
|
| 956 |
+
<leafValues>
|
| 957 |
+
-0.2592592537403107 0.5873016119003296</leafValues></_>
|
| 958 |
+
<!-- tree 1 -->
|
| 959 |
+
<_>
|
| 960 |
+
<internalNodes>
|
| 961 |
+
0 -1 1 -285216785 -823206977 -1085589 -1081346 1207959293
|
| 962 |
+
1157103471 2097133565 -2097169</internalNodes>
|
| 963 |
+
<leafValues>
|
| 964 |
+
-0.3801195919513702 0.4718827307224274</leafValues></_>
|
| 965 |
+
<!-- tree 2 -->
|
| 966 |
+
<_>
|
| 967 |
+
<internalNodes>
|
| 968 |
+
0 -1 121 -12465 -536875169 2147478367 2130706303 -37765492
|
| 969 |
+
-866124467 -318782328 -1392509185</internalNodes>
|
| 970 |
+
<leafValues>
|
| 971 |
+
-0.3509117066860199 0.5094807147979736</leafValues></_>
|
| 972 |
+
<!-- tree 3 -->
|
| 973 |
+
<_>
|
| 974 |
+
<internalNodes>
|
| 975 |
+
0 -1 38 2147449663 -20741 -16794757 1945873146 -16710 -1
|
| 976 |
+
-8406341 -67663041</internalNodes>
|
| 977 |
+
<leafValues>
|
| 978 |
+
-0.4068757295608521 0.4130136370658875</leafValues></_>
|
| 979 |
+
<!-- tree 4 -->
|
| 980 |
+
<_>
|
| 981 |
+
<internalNodes>
|
| 982 |
+
0 -1 17 -155191713 866117231 1651407483 548272812 -479201468
|
| 983 |
+
-447742449 1354229504 -261884429</internalNodes>
|
| 984 |
+
<leafValues>
|
| 985 |
+
-0.4557141065597534 0.3539792001247406</leafValues></_>
|
| 986 |
+
<!-- tree 5 -->
|
| 987 |
+
<_>
|
| 988 |
+
<internalNodes>
|
| 989 |
+
0 -1 100 -225319378 -251682065 -492783986 -792341777
|
| 990 |
+
-1287261695 1393643841 -11274182 -213909521</internalNodes>
|
| 991 |
+
<leafValues>
|
| 992 |
+
-0.4117803275585175 0.4118592441082001</leafValues></_>
|
| 993 |
+
<!-- tree 6 -->
|
| 994 |
+
<_>
|
| 995 |
+
<internalNodes>
|
| 996 |
+
0 -1 63 -382220122 -2002072729 -51404800 -371201558
|
| 997 |
+
-923011069 -2135301457 -2066104743 -1042557441</internalNodes>
|
| 998 |
+
<leafValues>
|
| 999 |
+
-0.4008397758007050 0.4034757018089294</leafValues></_>
|
| 1000 |
+
<!-- tree 7 -->
|
| 1001 |
+
<_>
|
| 1002 |
+
<internalNodes>
|
| 1003 |
+
0 -1 101 -627353764 -48295149 1581203952 -436258614
|
| 1004 |
+
-105268268 -1435893445 -638126888 -1061107126</internalNodes>
|
| 1005 |
+
<leafValues>
|
| 1006 |
+
-0.5694189667701721 0.2964762747287750</leafValues></_>
|
| 1007 |
+
<!-- tree 8 -->
|
| 1008 |
+
<_>
|
| 1009 |
+
<internalNodes>
|
| 1010 |
+
0 -1 118 -8399181 1058107691 -621022752 -251003468 -12582915
|
| 1011 |
+
-574619739 -994397789 -1648362021</internalNodes>
|
| 1012 |
+
<leafValues>
|
| 1013 |
+
-0.3195341229438782 0.5294018983840942</leafValues></_>
|
| 1014 |
+
<!-- tree 9 -->
|
| 1015 |
+
<_>
|
| 1016 |
+
<internalNodes>
|
| 1017 |
+
0 -1 92 -348343812 -1078389516 1717960437 364735981
|
| 1018 |
+
-1783841602 -4883137 -457572354 -1076950384</internalNodes>
|
| 1019 |
+
<leafValues>
|
| 1020 |
+
-0.3365339040756226 0.5067458748817444</leafValues></_></weakClassifiers></_>
|
| 1021 |
+
<!-- stage 19 -->
|
| 1022 |
+
<_>
|
| 1023 |
+
<maxWeakCount>10</maxWeakCount>
|
| 1024 |
+
<stageThreshold>-0.7612916231155396</stageThreshold>
|
| 1025 |
+
<weakClassifiers>
|
| 1026 |
+
<!-- tree 0 -->
|
| 1027 |
+
<_>
|
| 1028 |
+
<internalNodes>
|
| 1029 |
+
0 -1 10 -1976661318 -287957604 -1659497122 -782068 43591089
|
| 1030 |
+
-453637880 1435470000 -1077438561</internalNodes>
|
| 1031 |
+
<leafValues>
|
| 1032 |
+
-0.4204545319080353 0.5165745615959168</leafValues></_>
|
| 1033 |
+
<!-- tree 1 -->
|
| 1034 |
+
<_>
|
| 1035 |
+
<internalNodes>
|
| 1036 |
+
0 -1 131 -67110925 14874979 -142633168 -1338923040
|
| 1037 |
+
2046713291 -2067933195 1473503712 -789579837</internalNodes>
|
| 1038 |
+
<leafValues>
|
| 1039 |
+
-0.3762553930282593 0.4075302779674530</leafValues></_>
|
| 1040 |
+
<!-- tree 2 -->
|
| 1041 |
+
<_>
|
| 1042 |
+
<internalNodes>
|
| 1043 |
+
0 -1 83 -272814301 -1577073 -1118685 -305156120 -1052289
|
| 1044 |
+
-1073813756 -538971154 -355523038</internalNodes>
|
| 1045 |
+
<leafValues>
|
| 1046 |
+
-0.4253497421741486 0.3728055357933044</leafValues></_>
|
| 1047 |
+
<!-- tree 3 -->
|
| 1048 |
+
<_>
|
| 1049 |
+
<internalNodes>
|
| 1050 |
+
0 -1 135 -2233 -214486242 -538514758 573747007 -159390971
|
| 1051 |
+
1994225489 -973738098 -203424005</internalNodes>
|
| 1052 |
+
<leafValues>
|
| 1053 |
+
-0.3601998090744019 0.4563256204128265</leafValues></_>
|
| 1054 |
+
<!-- tree 4 -->
|
| 1055 |
+
<_>
|
| 1056 |
+
<internalNodes>
|
| 1057 |
+
0 -1 115 -261031688 -1330369299 -641860609 1029570301
|
| 1058 |
+
-1306461192 -1196149518 -1529767778 683139823</internalNodes>
|
| 1059 |
+
<leafValues>
|
| 1060 |
+
-0.4034293889999390 0.4160816967487335</leafValues></_>
|
| 1061 |
+
<!-- tree 5 -->
|
| 1062 |
+
<_>
|
| 1063 |
+
<internalNodes>
|
| 1064 |
+
0 -1 64 -572993608 -34042628 -417865 -111109 -1433365268
|
| 1065 |
+
-19869715 -1920939864 -1279457063</internalNodes>
|
| 1066 |
+
<leafValues>
|
| 1067 |
+
-0.3620899617671967 0.4594142735004425</leafValues></_>
|
| 1068 |
+
<!-- tree 6 -->
|
| 1069 |
+
<_>
|
| 1070 |
+
<internalNodes>
|
| 1071 |
+
0 -1 36 -626275097 -615256993 1651946018 805366393
|
| 1072 |
+
2016559730 -430780849 -799868165 -16580645</internalNodes>
|
| 1073 |
+
<leafValues>
|
| 1074 |
+
-0.3903816640377045 0.4381459355354309</leafValues></_>
|
| 1075 |
+
<!-- tree 7 -->
|
| 1076 |
+
<_>
|
| 1077 |
+
<internalNodes>
|
| 1078 |
+
0 -1 93 1354797300 -1090957603 1976418270 -1342502178
|
| 1079 |
+
-1851873892 -1194637077 -1153521668 -1108399474</internalNodes>
|
| 1080 |
+
<leafValues>
|
| 1081 |
+
-0.3591445386409760 0.4624078869819641</leafValues></_>
|
| 1082 |
+
<!-- tree 8 -->
|
| 1083 |
+
<_>
|
| 1084 |
+
<internalNodes>
|
| 1085 |
+
0 -1 91 68157712 1211368313 -304759523 1063017136 798797750
|
| 1086 |
+
-275513546 648167355 -1145357350</internalNodes>
|
| 1087 |
+
<leafValues>
|
| 1088 |
+
-0.4297670423984528 0.4023293554782867</leafValues></_>
|
| 1089 |
+
<!-- tree 9 -->
|
| 1090 |
+
<_>
|
| 1091 |
+
<internalNodes>
|
| 1092 |
+
0 -1 107 -546318240 -1628569602 -163577944 -537002306
|
| 1093 |
+
-545456389 -1325465645 -380446736 -1058473386</internalNodes>
|
| 1094 |
+
<leafValues>
|
| 1095 |
+
-0.5727006793022156 0.2995934784412384</leafValues></_></weakClassifiers></_></stages>
|
| 1096 |
+
<features>
|
| 1097 |
+
<_>
|
| 1098 |
+
<rect>
|
| 1099 |
+
0 0 3 5</rect></_>
|
| 1100 |
+
<_>
|
| 1101 |
+
<rect>
|
| 1102 |
+
0 0 4 2</rect></_>
|
| 1103 |
+
<_>
|
| 1104 |
+
<rect>
|
| 1105 |
+
0 0 6 3</rect></_>
|
| 1106 |
+
<_>
|
| 1107 |
+
<rect>
|
| 1108 |
+
0 1 2 3</rect></_>
|
| 1109 |
+
<_>
|
| 1110 |
+
<rect>
|
| 1111 |
+
0 1 3 3</rect></_>
|
| 1112 |
+
<_>
|
| 1113 |
+
<rect>
|
| 1114 |
+
0 1 3 7</rect></_>
|
| 1115 |
+
<_>
|
| 1116 |
+
<rect>
|
| 1117 |
+
0 4 3 3</rect></_>
|
| 1118 |
+
<_>
|
| 1119 |
+
<rect>
|
| 1120 |
+
0 11 3 4</rect></_>
|
| 1121 |
+
<_>
|
| 1122 |
+
<rect>
|
| 1123 |
+
0 12 8 4</rect></_>
|
| 1124 |
+
<_>
|
| 1125 |
+
<rect>
|
| 1126 |
+
0 14 4 3</rect></_>
|
| 1127 |
+
<_>
|
| 1128 |
+
<rect>
|
| 1129 |
+
1 0 5 3</rect></_>
|
| 1130 |
+
<_>
|
| 1131 |
+
<rect>
|
| 1132 |
+
1 1 2 2</rect></_>
|
| 1133 |
+
<_>
|
| 1134 |
+
<rect>
|
| 1135 |
+
1 3 3 1</rect></_>
|
| 1136 |
+
<_>
|
| 1137 |
+
<rect>
|
| 1138 |
+
1 7 4 4</rect></_>
|
| 1139 |
+
<_>
|
| 1140 |
+
<rect>
|
| 1141 |
+
1 12 2 2</rect></_>
|
| 1142 |
+
<_>
|
| 1143 |
+
<rect>
|
| 1144 |
+
1 13 4 1</rect></_>
|
| 1145 |
+
<_>
|
| 1146 |
+
<rect>
|
| 1147 |
+
1 14 4 3</rect></_>
|
| 1148 |
+
<_>
|
| 1149 |
+
<rect>
|
| 1150 |
+
1 17 3 2</rect></_>
|
| 1151 |
+
<_>
|
| 1152 |
+
<rect>
|
| 1153 |
+
2 0 2 3</rect></_>
|
| 1154 |
+
<_>
|
| 1155 |
+
<rect>
|
| 1156 |
+
2 1 2 2</rect></_>
|
| 1157 |
+
<_>
|
| 1158 |
+
<rect>
|
| 1159 |
+
2 2 4 6</rect></_>
|
| 1160 |
+
<_>
|
| 1161 |
+
<rect>
|
| 1162 |
+
2 3 4 4</rect></_>
|
| 1163 |
+
<_>
|
| 1164 |
+
<rect>
|
| 1165 |
+
2 7 2 1</rect></_>
|
| 1166 |
+
<_>
|
| 1167 |
+
<rect>
|
| 1168 |
+
2 11 2 3</rect></_>
|
| 1169 |
+
<_>
|
| 1170 |
+
<rect>
|
| 1171 |
+
2 17 3 2</rect></_>
|
| 1172 |
+
<_>
|
| 1173 |
+
<rect>
|
| 1174 |
+
3 0 2 2</rect></_>
|
| 1175 |
+
<_>
|
| 1176 |
+
<rect>
|
| 1177 |
+
3 1 7 3</rect></_>
|
| 1178 |
+
<_>
|
| 1179 |
+
<rect>
|
| 1180 |
+
3 7 2 1</rect></_>
|
| 1181 |
+
<_>
|
| 1182 |
+
<rect>
|
| 1183 |
+
3 7 2 4</rect></_>
|
| 1184 |
+
<_>
|
| 1185 |
+
<rect>
|
| 1186 |
+
3 18 2 2</rect></_>
|
| 1187 |
+
<_>
|
| 1188 |
+
<rect>
|
| 1189 |
+
4 0 2 3</rect></_>
|
| 1190 |
+
<_>
|
| 1191 |
+
<rect>
|
| 1192 |
+
4 3 2 1</rect></_>
|
| 1193 |
+
<_>
|
| 1194 |
+
<rect>
|
| 1195 |
+
4 6 2 1</rect></_>
|
| 1196 |
+
<_>
|
| 1197 |
+
<rect>
|
| 1198 |
+
4 6 2 5</rect></_>
|
| 1199 |
+
<_>
|
| 1200 |
+
<rect>
|
| 1201 |
+
4 7 5 2</rect></_>
|
| 1202 |
+
<_>
|
| 1203 |
+
<rect>
|
| 1204 |
+
4 8 4 3</rect></_>
|
| 1205 |
+
<_>
|
| 1206 |
+
<rect>
|
| 1207 |
+
4 18 2 2</rect></_>
|
| 1208 |
+
<_>
|
| 1209 |
+
<rect>
|
| 1210 |
+
5 0 2 2</rect></_>
|
| 1211 |
+
<_>
|
| 1212 |
+
<rect>
|
| 1213 |
+
5 3 4 4</rect></_>
|
| 1214 |
+
<_>
|
| 1215 |
+
<rect>
|
| 1216 |
+
5 6 2 5</rect></_>
|
| 1217 |
+
<_>
|
| 1218 |
+
<rect>
|
| 1219 |
+
5 9 2 2</rect></_>
|
| 1220 |
+
<_>
|
| 1221 |
+
<rect>
|
| 1222 |
+
5 10 2 2</rect></_>
|
| 1223 |
+
<_>
|
| 1224 |
+
<rect>
|
| 1225 |
+
6 3 4 4</rect></_>
|
| 1226 |
+
<_>
|
| 1227 |
+
<rect>
|
| 1228 |
+
6 4 4 3</rect></_>
|
| 1229 |
+
<_>
|
| 1230 |
+
<rect>
|
| 1231 |
+
6 5 2 3</rect></_>
|
| 1232 |
+
<_>
|
| 1233 |
+
<rect>
|
| 1234 |
+
6 5 2 5</rect></_>
|
| 1235 |
+
<_>
|
| 1236 |
+
<rect>
|
| 1237 |
+
6 5 4 3</rect></_>
|
| 1238 |
+
<_>
|
| 1239 |
+
<rect>
|
| 1240 |
+
6 6 4 2</rect></_>
|
| 1241 |
+
<_>
|
| 1242 |
+
<rect>
|
| 1243 |
+
6 6 4 4</rect></_>
|
| 1244 |
+
<_>
|
| 1245 |
+
<rect>
|
| 1246 |
+
6 18 1 2</rect></_>
|
| 1247 |
+
<_>
|
| 1248 |
+
<rect>
|
| 1249 |
+
6 21 2 1</rect></_>
|
| 1250 |
+
<_>
|
| 1251 |
+
<rect>
|
| 1252 |
+
7 0 3 7</rect></_>
|
| 1253 |
+
<_>
|
| 1254 |
+
<rect>
|
| 1255 |
+
7 4 2 3</rect></_>
|
| 1256 |
+
<_>
|
| 1257 |
+
<rect>
|
| 1258 |
+
7 9 5 1</rect></_>
|
| 1259 |
+
<_>
|
| 1260 |
+
<rect>
|
| 1261 |
+
7 21 2 1</rect></_>
|
| 1262 |
+
<_>
|
| 1263 |
+
<rect>
|
| 1264 |
+
8 0 1 4</rect></_>
|
| 1265 |
+
<_>
|
| 1266 |
+
<rect>
|
| 1267 |
+
8 5 2 2</rect></_>
|
| 1268 |
+
<_>
|
| 1269 |
+
<rect>
|
| 1270 |
+
8 5 3 2</rect></_>
|
| 1271 |
+
<_>
|
| 1272 |
+
<rect>
|
| 1273 |
+
8 17 3 1</rect></_>
|
| 1274 |
+
<_>
|
| 1275 |
+
<rect>
|
| 1276 |
+
8 18 1 2</rect></_>
|
| 1277 |
+
<_>
|
| 1278 |
+
<rect>
|
| 1279 |
+
9 0 5 3</rect></_>
|
| 1280 |
+
<_>
|
| 1281 |
+
<rect>
|
| 1282 |
+
9 2 2 6</rect></_>
|
| 1283 |
+
<_>
|
| 1284 |
+
<rect>
|
| 1285 |
+
9 5 1 1</rect></_>
|
| 1286 |
+
<_>
|
| 1287 |
+
<rect>
|
| 1288 |
+
9 11 1 1</rect></_>
|
| 1289 |
+
<_>
|
| 1290 |
+
<rect>
|
| 1291 |
+
9 16 1 1</rect></_>
|
| 1292 |
+
<_>
|
| 1293 |
+
<rect>
|
| 1294 |
+
9 16 2 1</rect></_>
|
| 1295 |
+
<_>
|
| 1296 |
+
<rect>
|
| 1297 |
+
9 17 1 1</rect></_>
|
| 1298 |
+
<_>
|
| 1299 |
+
<rect>
|
| 1300 |
+
9 18 1 1</rect></_>
|
| 1301 |
+
<_>
|
| 1302 |
+
<rect>
|
| 1303 |
+
10 5 1 2</rect></_>
|
| 1304 |
+
<_>
|
| 1305 |
+
<rect>
|
| 1306 |
+
10 5 3 3</rect></_>
|
| 1307 |
+
<_>
|
| 1308 |
+
<rect>
|
| 1309 |
+
10 7 1 5</rect></_>
|
| 1310 |
+
<_>
|
| 1311 |
+
<rect>
|
| 1312 |
+
10 8 1 1</rect></_>
|
| 1313 |
+
<_>
|
| 1314 |
+
<rect>
|
| 1315 |
+
10 9 1 1</rect></_>
|
| 1316 |
+
<_>
|
| 1317 |
+
<rect>
|
| 1318 |
+
10 10 1 1</rect></_>
|
| 1319 |
+
<_>
|
| 1320 |
+
<rect>
|
| 1321 |
+
10 10 1 2</rect></_>
|
| 1322 |
+
<_>
|
| 1323 |
+
<rect>
|
| 1324 |
+
10 14 3 3</rect></_>
|
| 1325 |
+
<_>
|
| 1326 |
+
<rect>
|
| 1327 |
+
10 15 1 1</rect></_>
|
| 1328 |
+
<_>
|
| 1329 |
+
<rect>
|
| 1330 |
+
10 15 2 1</rect></_>
|
| 1331 |
+
<_>
|
| 1332 |
+
<rect>
|
| 1333 |
+
10 16 1 1</rect></_>
|
| 1334 |
+
<_>
|
| 1335 |
+
<rect>
|
| 1336 |
+
10 16 2 1</rect></_>
|
| 1337 |
+
<_>
|
| 1338 |
+
<rect>
|
| 1339 |
+
10 17 1 1</rect></_>
|
| 1340 |
+
<_>
|
| 1341 |
+
<rect>
|
| 1342 |
+
10 21 1 1</rect></_>
|
| 1343 |
+
<_>
|
| 1344 |
+
<rect>
|
| 1345 |
+
11 3 2 2</rect></_>
|
| 1346 |
+
<_>
|
| 1347 |
+
<rect>
|
| 1348 |
+
11 5 1 2</rect></_>
|
| 1349 |
+
<_>
|
| 1350 |
+
<rect>
|
| 1351 |
+
11 5 3 3</rect></_>
|
| 1352 |
+
<_>
|
| 1353 |
+
<rect>
|
| 1354 |
+
11 5 4 6</rect></_>
|
| 1355 |
+
<_>
|
| 1356 |
+
<rect>
|
| 1357 |
+
11 6 1 1</rect></_>
|
| 1358 |
+
<_>
|
| 1359 |
+
<rect>
|
| 1360 |
+
11 7 2 2</rect></_>
|
| 1361 |
+
<_>
|
| 1362 |
+
<rect>
|
| 1363 |
+
11 8 1 2</rect></_>
|
| 1364 |
+
<_>
|
| 1365 |
+
<rect>
|
| 1366 |
+
11 10 1 1</rect></_>
|
| 1367 |
+
<_>
|
| 1368 |
+
<rect>
|
| 1369 |
+
11 10 1 2</rect></_>
|
| 1370 |
+
<_>
|
| 1371 |
+
<rect>
|
| 1372 |
+
11 15 1 1</rect></_>
|
| 1373 |
+
<_>
|
| 1374 |
+
<rect>
|
| 1375 |
+
11 17 1 1</rect></_>
|
| 1376 |
+
<_>
|
| 1377 |
+
<rect>
|
| 1378 |
+
11 18 1 1</rect></_>
|
| 1379 |
+
<_>
|
| 1380 |
+
<rect>
|
| 1381 |
+
12 0 2 2</rect></_>
|
| 1382 |
+
<_>
|
| 1383 |
+
<rect>
|
| 1384 |
+
12 1 2 5</rect></_>
|
| 1385 |
+
<_>
|
| 1386 |
+
<rect>
|
| 1387 |
+
12 2 4 1</rect></_>
|
| 1388 |
+
<_>
|
| 1389 |
+
<rect>
|
| 1390 |
+
12 3 1 3</rect></_>
|
| 1391 |
+
<_>
|
| 1392 |
+
<rect>
|
| 1393 |
+
12 7 3 4</rect></_>
|
| 1394 |
+
<_>
|
| 1395 |
+
<rect>
|
| 1396 |
+
12 10 3 2</rect></_>
|
| 1397 |
+
<_>
|
| 1398 |
+
<rect>
|
| 1399 |
+
12 11 1 1</rect></_>
|
| 1400 |
+
<_>
|
| 1401 |
+
<rect>
|
| 1402 |
+
12 12 3 2</rect></_>
|
| 1403 |
+
<_>
|
| 1404 |
+
<rect>
|
| 1405 |
+
12 14 4 3</rect></_>
|
| 1406 |
+
<_>
|
| 1407 |
+
<rect>
|
| 1408 |
+
12 17 1 1</rect></_>
|
| 1409 |
+
<_>
|
| 1410 |
+
<rect>
|
| 1411 |
+
12 21 2 1</rect></_>
|
| 1412 |
+
<_>
|
| 1413 |
+
<rect>
|
| 1414 |
+
13 6 2 5</rect></_>
|
| 1415 |
+
<_>
|
| 1416 |
+
<rect>
|
| 1417 |
+
13 7 3 5</rect></_>
|
| 1418 |
+
<_>
|
| 1419 |
+
<rect>
|
| 1420 |
+
13 11 3 2</rect></_>
|
| 1421 |
+
<_>
|
| 1422 |
+
<rect>
|
| 1423 |
+
13 17 2 2</rect></_>
|
| 1424 |
+
<_>
|
| 1425 |
+
<rect>
|
| 1426 |
+
13 17 3 2</rect></_>
|
| 1427 |
+
<_>
|
| 1428 |
+
<rect>
|
| 1429 |
+
13 18 1 2</rect></_>
|
| 1430 |
+
<_>
|
| 1431 |
+
<rect>
|
| 1432 |
+
13 18 2 2</rect></_>
|
| 1433 |
+
<_>
|
| 1434 |
+
<rect>
|
| 1435 |
+
14 0 2 2</rect></_>
|
| 1436 |
+
<_>
|
| 1437 |
+
<rect>
|
| 1438 |
+
14 1 1 3</rect></_>
|
| 1439 |
+
<_>
|
| 1440 |
+
<rect>
|
| 1441 |
+
14 2 3 2</rect></_>
|
| 1442 |
+
<_>
|
| 1443 |
+
<rect>
|
| 1444 |
+
14 7 2 1</rect></_>
|
| 1445 |
+
<_>
|
| 1446 |
+
<rect>
|
| 1447 |
+
14 13 2 1</rect></_>
|
| 1448 |
+
<_>
|
| 1449 |
+
<rect>
|
| 1450 |
+
14 13 3 3</rect></_>
|
| 1451 |
+
<_>
|
| 1452 |
+
<rect>
|
| 1453 |
+
14 17 2 2</rect></_>
|
| 1454 |
+
<_>
|
| 1455 |
+
<rect>
|
| 1456 |
+
15 0 2 2</rect></_>
|
| 1457 |
+
<_>
|
| 1458 |
+
<rect>
|
| 1459 |
+
15 0 2 3</rect></_>
|
| 1460 |
+
<_>
|
| 1461 |
+
<rect>
|
| 1462 |
+
15 4 3 2</rect></_>
|
| 1463 |
+
<_>
|
| 1464 |
+
<rect>
|
| 1465 |
+
15 4 3 6</rect></_>
|
| 1466 |
+
<_>
|
| 1467 |
+
<rect>
|
| 1468 |
+
15 6 3 2</rect></_>
|
| 1469 |
+
<_>
|
| 1470 |
+
<rect>
|
| 1471 |
+
15 11 3 4</rect></_>
|
| 1472 |
+
<_>
|
| 1473 |
+
<rect>
|
| 1474 |
+
15 13 3 2</rect></_>
|
| 1475 |
+
<_>
|
| 1476 |
+
<rect>
|
| 1477 |
+
15 17 2 2</rect></_>
|
| 1478 |
+
<_>
|
| 1479 |
+
<rect>
|
| 1480 |
+
15 17 3 2</rect></_>
|
| 1481 |
+
<_>
|
| 1482 |
+
<rect>
|
| 1483 |
+
16 1 2 3</rect></_>
|
| 1484 |
+
<_>
|
| 1485 |
+
<rect>
|
| 1486 |
+
16 3 2 4</rect></_>
|
| 1487 |
+
<_>
|
| 1488 |
+
<rect>
|
| 1489 |
+
16 6 1 1</rect></_>
|
| 1490 |
+
<_>
|
| 1491 |
+
<rect>
|
| 1492 |
+
16 16 2 2</rect></_>
|
| 1493 |
+
<_>
|
| 1494 |
+
<rect>
|
| 1495 |
+
17 1 2 2</rect></_>
|
| 1496 |
+
<_>
|
| 1497 |
+
<rect>
|
| 1498 |
+
17 1 2 5</rect></_>
|
| 1499 |
+
<_>
|
| 1500 |
+
<rect>
|
| 1501 |
+
17 12 2 2</rect></_>
|
| 1502 |
+
<_>
|
| 1503 |
+
<rect>
|
| 1504 |
+
18 0 2 2</rect></_></features></cascade>
|
| 1505 |
+
</opencv_storage>
|
envs/kitoverlay/skimage/data/multipage.tif
ADDED
|
|
envs/kitoverlay/skimage/data/multipage_rgb.tif
ADDED
|
|
envs/kitoverlay/skimage/feature/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Feature detection and extraction, e.g., texture analysis, corners, etc."""
|
| 2 |
+
|
| 3 |
+
import lazy_loader as _lazy
|
| 4 |
+
|
| 5 |
+
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|
envs/kitoverlay/skimage/feature/__init__.pyi
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Explicitly setting `__all__` is necessary for type inference engines
|
| 2 |
+
# to know which symbols are exported. See
|
| 3 |
+
# https://peps.python.org/pep-0484/#stub-files
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
'canny',
|
| 7 |
+
'Cascade',
|
| 8 |
+
'daisy',
|
| 9 |
+
'hog',
|
| 10 |
+
'graycomatrix',
|
| 11 |
+
'graycoprops',
|
| 12 |
+
'local_binary_pattern',
|
| 13 |
+
'multiblock_lbp',
|
| 14 |
+
'draw_multiblock_lbp',
|
| 15 |
+
'peak_local_max',
|
| 16 |
+
'structure_tensor',
|
| 17 |
+
'structure_tensor_eigenvalues',
|
| 18 |
+
'hessian_matrix',
|
| 19 |
+
'hessian_matrix_det',
|
| 20 |
+
'hessian_matrix_eigvals',
|
| 21 |
+
'shape_index',
|
| 22 |
+
'corner_kitchen_rosenfeld',
|
| 23 |
+
'corner_harris',
|
| 24 |
+
'corner_shi_tomasi',
|
| 25 |
+
'corner_foerstner',
|
| 26 |
+
'corner_subpix',
|
| 27 |
+
'corner_peaks',
|
| 28 |
+
'corner_moravec',
|
| 29 |
+
'corner_fast',
|
| 30 |
+
'corner_orientations',
|
| 31 |
+
'match_template',
|
| 32 |
+
'BRIEF',
|
| 33 |
+
'CENSURE',
|
| 34 |
+
'ORB',
|
| 35 |
+
'SIFT',
|
| 36 |
+
'match_descriptors',
|
| 37 |
+
'plot_matched_features',
|
| 38 |
+
'blob_dog',
|
| 39 |
+
'blob_doh',
|
| 40 |
+
'blob_log',
|
| 41 |
+
'haar_like_feature',
|
| 42 |
+
'haar_like_feature_coord',
|
| 43 |
+
'draw_haar_like_feature',
|
| 44 |
+
'multiscale_basic_features',
|
| 45 |
+
'learn_gmm',
|
| 46 |
+
'fisher_vector',
|
| 47 |
+
]
|
| 48 |
+
|
| 49 |
+
from ._canny import canny
|
| 50 |
+
from ._cascade import Cascade
|
| 51 |
+
from ._daisy import daisy
|
| 52 |
+
from ._hog import hog
|
| 53 |
+
from .texture import (
|
| 54 |
+
graycomatrix,
|
| 55 |
+
graycoprops,
|
| 56 |
+
local_binary_pattern,
|
| 57 |
+
multiblock_lbp,
|
| 58 |
+
draw_multiblock_lbp,
|
| 59 |
+
)
|
| 60 |
+
from .peak import peak_local_max
|
| 61 |
+
from .corner import (
|
| 62 |
+
corner_kitchen_rosenfeld,
|
| 63 |
+
corner_harris,
|
| 64 |
+
corner_shi_tomasi,
|
| 65 |
+
corner_foerstner,
|
| 66 |
+
corner_subpix,
|
| 67 |
+
corner_peaks,
|
| 68 |
+
corner_fast,
|
| 69 |
+
structure_tensor,
|
| 70 |
+
structure_tensor_eigenvalues,
|
| 71 |
+
hessian_matrix,
|
| 72 |
+
hessian_matrix_eigvals,
|
| 73 |
+
hessian_matrix_det,
|
| 74 |
+
corner_moravec,
|
| 75 |
+
corner_orientations,
|
| 76 |
+
shape_index,
|
| 77 |
+
)
|
| 78 |
+
from .template import match_template
|
| 79 |
+
from .brief import BRIEF
|
| 80 |
+
from .censure import CENSURE
|
| 81 |
+
from .orb import ORB
|
| 82 |
+
from .sift import SIFT
|
| 83 |
+
from .match import match_descriptors
|
| 84 |
+
from .util import plot_matched_features
|
| 85 |
+
from .blob import blob_dog, blob_log, blob_doh
|
| 86 |
+
from .haar import haar_like_feature, haar_like_feature_coord, draw_haar_like_feature
|
| 87 |
+
from ._basic_features import multiscale_basic_features
|
| 88 |
+
from ._fisher_vector import learn_gmm, fisher_vector
|
envs/kitoverlay/skimage/feature/__pycache__/_hog.cpython-311.pyc
ADDED
|
Binary file (12.6 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/censure.cpython-311.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/orb.cpython-311.pyc
ADDED
|
Binary file (15.7 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/peak.cpython-311.pyc
ADDED
|
Binary file (15.9 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/_basic_features.py
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from itertools import combinations_with_replacement
|
| 2 |
+
import itertools
|
| 3 |
+
import numpy as np
|
| 4 |
+
from skimage import filters, feature
|
| 5 |
+
from skimage.util.dtype import img_as_float32
|
| 6 |
+
from .._shared._dependency_checks import is_wasm
|
| 7 |
+
|
| 8 |
+
if not is_wasm:
|
| 9 |
+
from concurrent.futures import ThreadPoolExecutor as PoolExecutor
|
| 10 |
+
else:
|
| 11 |
+
from contextlib import AbstractContextManager
|
| 12 |
+
|
| 13 |
+
# Threading isn't supported on WASM, mock ThreadPoolExecutor as a fallback
|
| 14 |
+
class PoolExecutor(AbstractContextManager):
|
| 15 |
+
def __init__(self, *_, **__):
|
| 16 |
+
pass
|
| 17 |
+
|
| 18 |
+
def __exit__(self, exc_type, exc_val, exc_tb):
|
| 19 |
+
pass
|
| 20 |
+
|
| 21 |
+
def map(self, fn, iterables):
|
| 22 |
+
return map(fn, iterables)
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def _texture_filter(gaussian_filtered):
|
| 26 |
+
H_elems = [
|
| 27 |
+
np.gradient(np.gradient(gaussian_filtered)[ax0], axis=ax1)
|
| 28 |
+
for ax0, ax1 in combinations_with_replacement(range(gaussian_filtered.ndim), 2)
|
| 29 |
+
]
|
| 30 |
+
eigvals = feature.hessian_matrix_eigvals(H_elems)
|
| 31 |
+
return eigvals
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _singlescale_basic_features_singlechannel(
|
| 35 |
+
img, sigma, intensity=True, edges=True, texture=True
|
| 36 |
+
):
|
| 37 |
+
results = ()
|
| 38 |
+
gaussian_filtered = filters.gaussian(img, sigma=sigma, preserve_range=False)
|
| 39 |
+
if intensity:
|
| 40 |
+
results += (gaussian_filtered,)
|
| 41 |
+
if edges:
|
| 42 |
+
results += (filters.sobel(gaussian_filtered),)
|
| 43 |
+
if texture:
|
| 44 |
+
results += (*_texture_filter(gaussian_filtered),)
|
| 45 |
+
return results
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
def _mutiscale_basic_features_singlechannel(
|
| 49 |
+
img,
|
| 50 |
+
intensity=True,
|
| 51 |
+
edges=True,
|
| 52 |
+
texture=True,
|
| 53 |
+
sigma_min=0.5,
|
| 54 |
+
sigma_max=16,
|
| 55 |
+
num_sigma=None,
|
| 56 |
+
workers=None,
|
| 57 |
+
):
|
| 58 |
+
"""Features for a single channel nd image.
|
| 59 |
+
|
| 60 |
+
Parameters
|
| 61 |
+
----------
|
| 62 |
+
img : ndarray
|
| 63 |
+
Input image, which can be grayscale or multichannel.
|
| 64 |
+
intensity : bool, default True
|
| 65 |
+
If True, pixel intensities averaged over the different scales
|
| 66 |
+
are added to the feature set.
|
| 67 |
+
edges : bool, default True
|
| 68 |
+
If True, intensities of local gradients averaged over the different
|
| 69 |
+
scales are added to the feature set.
|
| 70 |
+
texture : bool, default True
|
| 71 |
+
If True, eigenvalues of the Hessian matrix after Gaussian blurring
|
| 72 |
+
at different scales are added to the feature set.
|
| 73 |
+
sigma_min : float, optional
|
| 74 |
+
Smallest value of the Gaussian kernel used to average local
|
| 75 |
+
neighborhoods before extracting features.
|
| 76 |
+
sigma_max : float, optional
|
| 77 |
+
Largest value of the Gaussian kernel used to average local
|
| 78 |
+
neighborhoods before extracting features.
|
| 79 |
+
num_sigma : int, optional
|
| 80 |
+
Number of values of the Gaussian kernel between sigma_min and sigma_max.
|
| 81 |
+
If None, sigma_min multiplied by powers of 2 are used.
|
| 82 |
+
workers : int or None, optional
|
| 83 |
+
The number of parallel threads to use. If set to ``None``, the full
|
| 84 |
+
set of available cores are used.
|
| 85 |
+
|
| 86 |
+
Returns
|
| 87 |
+
-------
|
| 88 |
+
features : list
|
| 89 |
+
List of features, each element of the list is an array of shape as img.
|
| 90 |
+
"""
|
| 91 |
+
# computations are faster as float32
|
| 92 |
+
img = np.ascontiguousarray(img_as_float32(img))
|
| 93 |
+
if num_sigma is None:
|
| 94 |
+
num_sigma = int(np.log2(sigma_max) - np.log2(sigma_min) + 1)
|
| 95 |
+
sigmas = np.logspace(
|
| 96 |
+
np.log2(sigma_min),
|
| 97 |
+
np.log2(sigma_max),
|
| 98 |
+
num=num_sigma,
|
| 99 |
+
base=2,
|
| 100 |
+
endpoint=True,
|
| 101 |
+
)
|
| 102 |
+
with PoolExecutor(max_workers=workers) as ex:
|
| 103 |
+
out_sigmas = list(
|
| 104 |
+
ex.map(
|
| 105 |
+
lambda s: _singlescale_basic_features_singlechannel(
|
| 106 |
+
img, s, intensity=intensity, edges=edges, texture=texture
|
| 107 |
+
),
|
| 108 |
+
sigmas,
|
| 109 |
+
)
|
| 110 |
+
)
|
| 111 |
+
features = itertools.chain.from_iterable(out_sigmas)
|
| 112 |
+
return features
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def multiscale_basic_features(
|
| 116 |
+
image,
|
| 117 |
+
intensity=True,
|
| 118 |
+
edges=True,
|
| 119 |
+
texture=True,
|
| 120 |
+
sigma_min=0.5,
|
| 121 |
+
sigma_max=16,
|
| 122 |
+
num_sigma=None,
|
| 123 |
+
workers=None,
|
| 124 |
+
*,
|
| 125 |
+
channel_axis=None,
|
| 126 |
+
):
|
| 127 |
+
"""Local features for a single- or multi-channel nd image.
|
| 128 |
+
|
| 129 |
+
Intensity, gradient intensity and local structure are computed at
|
| 130 |
+
different scales thanks to Gaussian blurring.
|
| 131 |
+
|
| 132 |
+
Parameters
|
| 133 |
+
----------
|
| 134 |
+
image : ndarray
|
| 135 |
+
Input image, which can be grayscale or multichannel.
|
| 136 |
+
intensity : bool, default True
|
| 137 |
+
If True, pixel intensities averaged over the different scales
|
| 138 |
+
are added to the feature set.
|
| 139 |
+
edges : bool, default True
|
| 140 |
+
If True, intensities of local gradients averaged over the different
|
| 141 |
+
scales are added to the feature set.
|
| 142 |
+
texture : bool, default True
|
| 143 |
+
If True, eigenvalues of the Hessian matrix after Gaussian blurring
|
| 144 |
+
at different scales are added to the feature set.
|
| 145 |
+
sigma_min : float, optional
|
| 146 |
+
Smallest value of the Gaussian kernel used to average local
|
| 147 |
+
neighborhoods before extracting features.
|
| 148 |
+
sigma_max : float, optional
|
| 149 |
+
Largest value of the Gaussian kernel used to average local
|
| 150 |
+
neighborhoods before extracting features.
|
| 151 |
+
num_sigma : int, optional
|
| 152 |
+
Number of values of the Gaussian kernel between sigma_min and sigma_max.
|
| 153 |
+
If None, sigma_min multiplied by powers of 2 are used.
|
| 154 |
+
workers : int or None, optional
|
| 155 |
+
The number of parallel threads to use. If set to ``None``, the full
|
| 156 |
+
set of available cores are used.
|
| 157 |
+
channel_axis : int or None, optional
|
| 158 |
+
If None, the image is assumed to be a grayscale (single channel) image.
|
| 159 |
+
Otherwise, this parameter indicates which axis of the array corresponds
|
| 160 |
+
to channels.
|
| 161 |
+
|
| 162 |
+
.. versionadded:: 0.19
|
| 163 |
+
``channel_axis`` was added in 0.19.
|
| 164 |
+
|
| 165 |
+
Returns
|
| 166 |
+
-------
|
| 167 |
+
features : np.ndarray
|
| 168 |
+
Array of shape ``image.shape + (n_features,)``. When `channel_axis` is
|
| 169 |
+
not None, all channels are concatenated along the features dimension.
|
| 170 |
+
(i.e. ``n_features == n_features_singlechannel * n_channels``)
|
| 171 |
+
"""
|
| 172 |
+
if not any([intensity, edges, texture]):
|
| 173 |
+
raise ValueError(
|
| 174 |
+
"At least one of `intensity`, `edges` or `textures`"
|
| 175 |
+
"must be True for features to be computed."
|
| 176 |
+
)
|
| 177 |
+
if channel_axis is None:
|
| 178 |
+
image = image[..., np.newaxis]
|
| 179 |
+
channel_axis = -1
|
| 180 |
+
elif channel_axis != -1:
|
| 181 |
+
image = np.moveaxis(image, channel_axis, -1)
|
| 182 |
+
|
| 183 |
+
all_results = (
|
| 184 |
+
_mutiscale_basic_features_singlechannel(
|
| 185 |
+
image[..., dim],
|
| 186 |
+
intensity=intensity,
|
| 187 |
+
edges=edges,
|
| 188 |
+
texture=texture,
|
| 189 |
+
sigma_min=sigma_min,
|
| 190 |
+
sigma_max=sigma_max,
|
| 191 |
+
num_sigma=num_sigma,
|
| 192 |
+
workers=workers,
|
| 193 |
+
)
|
| 194 |
+
for dim in range(image.shape[-1])
|
| 195 |
+
)
|
| 196 |
+
features = list(itertools.chain.from_iterable(all_results))
|
| 197 |
+
out = np.stack(features, axis=-1)
|
| 198 |
+
return out
|
envs/kitoverlay/skimage/feature/_canny.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
canny.py - Canny Edge detector
|
| 3 |
+
|
| 4 |
+
Reference: Canny, J., A Computational Approach To Edge Detection, IEEE Trans.
|
| 5 |
+
Pattern Analysis and Machine Intelligence, 8:679-714, 1986
|
| 6 |
+
"""
|
| 7 |
+
|
| 8 |
+
import numpy as np
|
| 9 |
+
import scipy.ndimage as ndi
|
| 10 |
+
|
| 11 |
+
from ..util.dtype import dtype_limits
|
| 12 |
+
from .._shared.filters import gaussian
|
| 13 |
+
from .._shared.utils import _supported_float_type, check_nD
|
| 14 |
+
from ._canny_cy import _nonmaximum_suppression_bilinear
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
def _preprocess(image, mask, sigma, mode, cval):
|
| 18 |
+
"""Generate a smoothed image and an eroded mask.
|
| 19 |
+
|
| 20 |
+
The image is smoothed using a gaussian filter ignoring masked
|
| 21 |
+
pixels and the mask is eroded.
|
| 22 |
+
|
| 23 |
+
Parameters
|
| 24 |
+
----------
|
| 25 |
+
image : array
|
| 26 |
+
Image to be smoothed.
|
| 27 |
+
mask : array
|
| 28 |
+
Mask with 1's for significant pixels, 0's for masked pixels.
|
| 29 |
+
sigma : scalar or sequence of scalars
|
| 30 |
+
Standard deviation for Gaussian kernel. The standard
|
| 31 |
+
deviations of the Gaussian filter are given for each axis as a
|
| 32 |
+
sequence, or as a single number, in which case it is equal for
|
| 33 |
+
all axes.
|
| 34 |
+
mode : str, {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}
|
| 35 |
+
The ``mode`` parameter determines how the array borders are
|
| 36 |
+
handled, where ``cval`` is the value when mode is equal to
|
| 37 |
+
'constant'.
|
| 38 |
+
cval : float, optional
|
| 39 |
+
Value to fill past edges of input if `mode` is 'constant'.
|
| 40 |
+
|
| 41 |
+
Returns
|
| 42 |
+
-------
|
| 43 |
+
smoothed_image : ndarray
|
| 44 |
+
The smoothed array
|
| 45 |
+
eroded_mask : ndarray
|
| 46 |
+
The eroded mask.
|
| 47 |
+
|
| 48 |
+
Notes
|
| 49 |
+
-----
|
| 50 |
+
This function calculates the fractional contribution of masked pixels
|
| 51 |
+
by applying the function to the mask (which gets you the fraction of
|
| 52 |
+
the pixel data that's due to significant points). We then mask the image
|
| 53 |
+
and apply the function. The resulting values will be lower by the
|
| 54 |
+
bleed-over fraction, so you can recalibrate by dividing by the function
|
| 55 |
+
on the mask to recover the effect of smoothing from just the significant
|
| 56 |
+
pixels.
|
| 57 |
+
"""
|
| 58 |
+
gaussian_kwargs = dict(sigma=sigma, mode=mode, cval=cval, preserve_range=False)
|
| 59 |
+
compute_bleedover = mode == 'constant' or mask is not None
|
| 60 |
+
float_type = _supported_float_type(image.dtype)
|
| 61 |
+
if mask is None:
|
| 62 |
+
if compute_bleedover:
|
| 63 |
+
mask = np.ones(image.shape, dtype=float_type)
|
| 64 |
+
masked_image = image
|
| 65 |
+
|
| 66 |
+
eroded_mask = np.ones(image.shape, dtype=bool)
|
| 67 |
+
eroded_mask[:1, :] = 0
|
| 68 |
+
eroded_mask[-1:, :] = 0
|
| 69 |
+
eroded_mask[:, :1] = 0
|
| 70 |
+
eroded_mask[:, -1:] = 0
|
| 71 |
+
|
| 72 |
+
else:
|
| 73 |
+
mask = mask.astype(bool, copy=False)
|
| 74 |
+
masked_image = np.zeros_like(image)
|
| 75 |
+
masked_image[mask] = image[mask]
|
| 76 |
+
|
| 77 |
+
# Make the eroded mask. Setting the border value to zero will wipe
|
| 78 |
+
# out the image edges for us.
|
| 79 |
+
s = ndi.generate_binary_structure(2, 2)
|
| 80 |
+
eroded_mask = ndi.binary_erosion(mask, s, border_value=0)
|
| 81 |
+
|
| 82 |
+
if compute_bleedover:
|
| 83 |
+
# Compute the fractional contribution of masked pixels by applying
|
| 84 |
+
# the function to the mask (which gets you the fraction of the
|
| 85 |
+
# pixel data that's due to significant points)
|
| 86 |
+
bleed_over = (
|
| 87 |
+
gaussian(mask.astype(float_type, copy=False), **gaussian_kwargs)
|
| 88 |
+
+ np.finfo(float_type).eps
|
| 89 |
+
)
|
| 90 |
+
|
| 91 |
+
# Smooth the masked image
|
| 92 |
+
smoothed_image = gaussian(masked_image, **gaussian_kwargs)
|
| 93 |
+
|
| 94 |
+
# Lower the result by the bleed-over fraction, so you can
|
| 95 |
+
# recalibrate by dividing by the function on the mask to recover
|
| 96 |
+
# the effect of smoothing from just the significant pixels.
|
| 97 |
+
if compute_bleedover:
|
| 98 |
+
smoothed_image /= bleed_over
|
| 99 |
+
|
| 100 |
+
return smoothed_image, eroded_mask
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def canny(
|
| 104 |
+
image,
|
| 105 |
+
sigma=1.0,
|
| 106 |
+
low_threshold=None,
|
| 107 |
+
high_threshold=None,
|
| 108 |
+
mask=None,
|
| 109 |
+
use_quantiles=False,
|
| 110 |
+
*,
|
| 111 |
+
mode='constant',
|
| 112 |
+
cval=0.0,
|
| 113 |
+
):
|
| 114 |
+
"""Edge filter an image using the Canny algorithm.
|
| 115 |
+
|
| 116 |
+
Parameters
|
| 117 |
+
----------
|
| 118 |
+
image : 2D array
|
| 119 |
+
Grayscale input image to detect edges on; can be of any dtype.
|
| 120 |
+
sigma : float, optional
|
| 121 |
+
Standard deviation of the Gaussian filter.
|
| 122 |
+
low_threshold : float, optional
|
| 123 |
+
Lower bound for hysteresis thresholding (linking edges).
|
| 124 |
+
If None, low_threshold is set to 10% of dtype's max.
|
| 125 |
+
high_threshold : float, optional
|
| 126 |
+
Upper bound for hysteresis thresholding (linking edges).
|
| 127 |
+
If None, high_threshold is set to 20% of dtype's max.
|
| 128 |
+
mask : array, dtype=bool, optional
|
| 129 |
+
Mask to limit the application of Canny to a certain area.
|
| 130 |
+
use_quantiles : bool, optional
|
| 131 |
+
If ``True`` then treat low_threshold and high_threshold as
|
| 132 |
+
quantiles of the edge magnitude image, rather than absolute
|
| 133 |
+
edge magnitude values. If ``True`` then the thresholds must be
|
| 134 |
+
in the range [0, 1].
|
| 135 |
+
mode : str, {'reflect', 'constant', 'nearest', 'mirror', 'wrap'}
|
| 136 |
+
The ``mode`` parameter determines how the array borders are
|
| 137 |
+
handled during Gaussian filtering, where ``cval`` is the value when
|
| 138 |
+
mode is equal to 'constant'.
|
| 139 |
+
cval : float, optional
|
| 140 |
+
Value to fill past edges of input if `mode` is 'constant'.
|
| 141 |
+
|
| 142 |
+
Returns
|
| 143 |
+
-------
|
| 144 |
+
output : 2D array (image)
|
| 145 |
+
The binary edge map.
|
| 146 |
+
|
| 147 |
+
See also
|
| 148 |
+
--------
|
| 149 |
+
skimage.filters.sobel
|
| 150 |
+
|
| 151 |
+
Notes
|
| 152 |
+
-----
|
| 153 |
+
The steps of the algorithm are as follows:
|
| 154 |
+
|
| 155 |
+
* Smooth the image using a Gaussian with ``sigma`` width.
|
| 156 |
+
|
| 157 |
+
* Apply the horizontal and vertical Sobel operators to get the gradients
|
| 158 |
+
within the image. The edge strength is the norm of the gradient.
|
| 159 |
+
|
| 160 |
+
* Thin potential edges to 1-pixel wide curves. First, find the normal
|
| 161 |
+
to the edge at each point. This is done by looking at the
|
| 162 |
+
signs and the relative magnitude of the X-Sobel and Y-Sobel
|
| 163 |
+
to sort the points into 4 categories: horizontal, vertical,
|
| 164 |
+
diagonal and antidiagonal. Then look in the normal and reverse
|
| 165 |
+
directions to see if the values in either of those directions are
|
| 166 |
+
greater than the point in question. Use interpolation to get a mix of
|
| 167 |
+
points instead of picking the one that's the closest to the normal.
|
| 168 |
+
|
| 169 |
+
* Perform a hysteresis thresholding: first label all points above the
|
| 170 |
+
high threshold as edges. Then recursively label any point above the
|
| 171 |
+
low threshold that is 8-connected to a labeled point as an edge.
|
| 172 |
+
|
| 173 |
+
References
|
| 174 |
+
----------
|
| 175 |
+
.. [1] Canny, J., A Computational Approach To Edge Detection, IEEE Trans.
|
| 176 |
+
Pattern Analysis and Machine Intelligence, 8:679-714, 1986
|
| 177 |
+
:DOI:`10.1109/TPAMI.1986.4767851`
|
| 178 |
+
.. [2] William Green's Canny tutorial
|
| 179 |
+
https://en.wikipedia.org/wiki/Canny_edge_detector
|
| 180 |
+
|
| 181 |
+
Examples
|
| 182 |
+
--------
|
| 183 |
+
>>> from skimage import feature
|
| 184 |
+
>>> rng = np.random.default_rng()
|
| 185 |
+
>>> # Generate noisy image of a square
|
| 186 |
+
>>> im = np.zeros((256, 256))
|
| 187 |
+
>>> im[64:-64, 64:-64] = 1
|
| 188 |
+
>>> im += 0.2 * rng.random(im.shape)
|
| 189 |
+
>>> # First trial with the Canny filter, with the default smoothing
|
| 190 |
+
>>> edges1 = feature.canny(im)
|
| 191 |
+
>>> # Increase the smoothing for better results
|
| 192 |
+
>>> edges2 = feature.canny(im, sigma=3)
|
| 193 |
+
|
| 194 |
+
"""
|
| 195 |
+
|
| 196 |
+
# Regarding masks, any point touching a masked point will have a gradient
|
| 197 |
+
# that is "infected" by the masked point, so it's enough to erode the
|
| 198 |
+
# mask by one and then mask the output. We also mask out the border points
|
| 199 |
+
# because who knows what lies beyond the edge of the image?
|
| 200 |
+
|
| 201 |
+
if np.issubdtype(image.dtype, np.int64) or np.issubdtype(image.dtype, np.uint64):
|
| 202 |
+
raise ValueError("64-bit integer images are not supported")
|
| 203 |
+
|
| 204 |
+
check_nD(image, 2)
|
| 205 |
+
dtype_max = dtype_limits(image, clip_negative=False)[1]
|
| 206 |
+
|
| 207 |
+
if low_threshold is None:
|
| 208 |
+
low_threshold = 0.1
|
| 209 |
+
elif use_quantiles:
|
| 210 |
+
if not (0.0 <= low_threshold <= 1.0):
|
| 211 |
+
raise ValueError("Quantile thresholds must be between 0 and 1.")
|
| 212 |
+
else:
|
| 213 |
+
low_threshold /= dtype_max
|
| 214 |
+
|
| 215 |
+
if high_threshold is None:
|
| 216 |
+
high_threshold = 0.2
|
| 217 |
+
elif use_quantiles:
|
| 218 |
+
if not (0.0 <= high_threshold <= 1.0):
|
| 219 |
+
raise ValueError("Quantile thresholds must be between 0 and 1.")
|
| 220 |
+
else:
|
| 221 |
+
high_threshold /= dtype_max
|
| 222 |
+
|
| 223 |
+
if high_threshold < low_threshold:
|
| 224 |
+
raise ValueError("low_threshold should be lower then high_threshold")
|
| 225 |
+
|
| 226 |
+
# Image filtering
|
| 227 |
+
smoothed, eroded_mask = _preprocess(image, mask, sigma, mode, cval)
|
| 228 |
+
|
| 229 |
+
# Gradient magnitude estimation
|
| 230 |
+
jsobel = ndi.sobel(smoothed, axis=1)
|
| 231 |
+
isobel = ndi.sobel(smoothed, axis=0)
|
| 232 |
+
magnitude = isobel * isobel
|
| 233 |
+
magnitude += jsobel * jsobel
|
| 234 |
+
np.sqrt(magnitude, out=magnitude)
|
| 235 |
+
|
| 236 |
+
if use_quantiles:
|
| 237 |
+
low_threshold, high_threshold = np.percentile(
|
| 238 |
+
magnitude, [100.0 * low_threshold, 100.0 * high_threshold]
|
| 239 |
+
)
|
| 240 |
+
|
| 241 |
+
# Non-maximum suppression
|
| 242 |
+
low_masked = _nonmaximum_suppression_bilinear(
|
| 243 |
+
isobel, jsobel, magnitude, eroded_mask, low_threshold
|
| 244 |
+
)
|
| 245 |
+
|
| 246 |
+
# Double thresholding and edge tracking
|
| 247 |
+
#
|
| 248 |
+
# Segment the low-mask, then only keep low-segments that have
|
| 249 |
+
# some high_mask component in them
|
| 250 |
+
#
|
| 251 |
+
low_mask = low_masked > 0
|
| 252 |
+
strel = np.ones((3, 3), bool)
|
| 253 |
+
labels, count = ndi.label(low_mask, strel)
|
| 254 |
+
if count == 0:
|
| 255 |
+
return low_mask
|
| 256 |
+
|
| 257 |
+
high_mask = low_mask & (low_masked >= high_threshold)
|
| 258 |
+
nonzero_sums = np.unique(labels[high_mask])
|
| 259 |
+
good_label = np.zeros((count + 1,), bool)
|
| 260 |
+
good_label[nonzero_sums] = True
|
| 261 |
+
output_mask = good_label[labels]
|
| 262 |
+
return output_mask
|
envs/kitoverlay/skimage/feature/_daisy.py
ADDED
|
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from numpy import arctan2, exp, pi, sqrt
|
| 5 |
+
|
| 6 |
+
from .. import draw
|
| 7 |
+
from ..util.dtype import img_as_float
|
| 8 |
+
from .._shared.filters import gaussian
|
| 9 |
+
from .._shared.utils import check_nD
|
| 10 |
+
from ..color import gray2rgb
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def daisy(
|
| 14 |
+
image,
|
| 15 |
+
step=4,
|
| 16 |
+
radius=15,
|
| 17 |
+
rings=3,
|
| 18 |
+
histograms=8,
|
| 19 |
+
orientations=8,
|
| 20 |
+
normalization='l1',
|
| 21 |
+
sigmas=None,
|
| 22 |
+
ring_radii=None,
|
| 23 |
+
visualize=False,
|
| 24 |
+
):
|
| 25 |
+
'''Extract DAISY feature descriptors densely for the given image.
|
| 26 |
+
|
| 27 |
+
DAISY is a feature descriptor similar to SIFT formulated in a way that
|
| 28 |
+
allows for fast dense extraction. Typically, this is practical for
|
| 29 |
+
bag-of-features image representations.
|
| 30 |
+
|
| 31 |
+
The implementation follows Tola et al. [1]_ but deviate on the following
|
| 32 |
+
points:
|
| 33 |
+
|
| 34 |
+
* Histogram bin contribution are smoothed with a circular Gaussian
|
| 35 |
+
window over the tonal range (the angular range).
|
| 36 |
+
* The sigma values of the spatial Gaussian smoothing in this code do not
|
| 37 |
+
match the sigma values in the original code by Tola et al. [2]_. In
|
| 38 |
+
their code, spatial smoothing is applied to both the input image and
|
| 39 |
+
the center histogram. However, this smoothing is not documented in [1]_
|
| 40 |
+
and, therefore, it is omitted.
|
| 41 |
+
|
| 42 |
+
Parameters
|
| 43 |
+
----------
|
| 44 |
+
image : (M, N) array
|
| 45 |
+
Input image (grayscale).
|
| 46 |
+
step : int, optional
|
| 47 |
+
Distance between descriptor sampling points.
|
| 48 |
+
radius : int, optional
|
| 49 |
+
Radius (in pixels) of the outermost ring.
|
| 50 |
+
rings : int, optional
|
| 51 |
+
Number of rings.
|
| 52 |
+
histograms : int, optional
|
| 53 |
+
Number of histograms sampled per ring.
|
| 54 |
+
orientations : int, optional
|
| 55 |
+
Number of orientations (bins) per histogram.
|
| 56 |
+
normalization : [ 'l1' | 'l2' | 'daisy' | 'off' ], optional
|
| 57 |
+
How to normalize the descriptors
|
| 58 |
+
|
| 59 |
+
* 'l1': L1-normalization of each descriptor.
|
| 60 |
+
* 'l2': L2-normalization of each descriptor.
|
| 61 |
+
* 'daisy': L2-normalization of individual histograms.
|
| 62 |
+
* 'off': Disable normalization.
|
| 63 |
+
|
| 64 |
+
sigmas : 1D array of float, optional
|
| 65 |
+
Standard deviation of spatial Gaussian smoothing for the center
|
| 66 |
+
histogram and for each ring of histograms. The array of sigmas should
|
| 67 |
+
be sorted from the center and out. I.e. the first sigma value defines
|
| 68 |
+
the spatial smoothing of the center histogram and the last sigma value
|
| 69 |
+
defines the spatial smoothing of the outermost ring. Specifying sigmas
|
| 70 |
+
overrides the following parameter.
|
| 71 |
+
|
| 72 |
+
``rings = len(sigmas) - 1``
|
| 73 |
+
|
| 74 |
+
ring_radii : 1D array of int, optional
|
| 75 |
+
Radius (in pixels) for each ring. Specifying ring_radii overrides the
|
| 76 |
+
following two parameters.
|
| 77 |
+
|
| 78 |
+
``rings = len(ring_radii)``
|
| 79 |
+
``radius = ring_radii[-1]``
|
| 80 |
+
|
| 81 |
+
If both sigmas and ring_radii are given, they must satisfy the
|
| 82 |
+
following predicate since no radius is needed for the center
|
| 83 |
+
histogram.
|
| 84 |
+
|
| 85 |
+
``len(ring_radii) == len(sigmas) + 1``
|
| 86 |
+
|
| 87 |
+
visualize : bool, optional
|
| 88 |
+
Generate a visualization of the DAISY descriptors
|
| 89 |
+
|
| 90 |
+
Returns
|
| 91 |
+
-------
|
| 92 |
+
descs : array
|
| 93 |
+
Grid of DAISY descriptors for the given image as an array
|
| 94 |
+
dimensionality (P, Q, R) where
|
| 95 |
+
|
| 96 |
+
``P = ceil((M - radius*2) / step)``
|
| 97 |
+
``Q = ceil((N - radius*2) / step)``
|
| 98 |
+
``R = (rings * histograms + 1) * orientations``
|
| 99 |
+
|
| 100 |
+
descs_img : (M, N, 3) array (only if visualize==True)
|
| 101 |
+
Visualization of the DAISY descriptors.
|
| 102 |
+
|
| 103 |
+
References
|
| 104 |
+
----------
|
| 105 |
+
.. [1] Tola et al. "Daisy: An efficient dense descriptor applied to wide-
|
| 106 |
+
baseline stereo." Pattern Analysis and Machine Intelligence, IEEE
|
| 107 |
+
Transactions on 32.5 (2010): 815-830.
|
| 108 |
+
.. [2] http://cvlab.epfl.ch/software/daisy
|
| 109 |
+
'''
|
| 110 |
+
|
| 111 |
+
check_nD(image, 2, 'img')
|
| 112 |
+
|
| 113 |
+
image = img_as_float(image)
|
| 114 |
+
float_dtype = image.dtype
|
| 115 |
+
|
| 116 |
+
# Validate parameters.
|
| 117 |
+
if (
|
| 118 |
+
sigmas is not None
|
| 119 |
+
and ring_radii is not None
|
| 120 |
+
and len(sigmas) - 1 != len(ring_radii)
|
| 121 |
+
):
|
| 122 |
+
raise ValueError('`len(sigmas)-1 != len(ring_radii)`')
|
| 123 |
+
if ring_radii is not None:
|
| 124 |
+
rings = len(ring_radii)
|
| 125 |
+
radius = ring_radii[-1]
|
| 126 |
+
if sigmas is not None:
|
| 127 |
+
rings = len(sigmas) - 1
|
| 128 |
+
if sigmas is None:
|
| 129 |
+
sigmas = [radius * (i + 1) / float(2 * rings) for i in range(rings)]
|
| 130 |
+
if ring_radii is None:
|
| 131 |
+
ring_radii = [radius * (i + 1) / float(rings) for i in range(rings)]
|
| 132 |
+
if normalization not in ['l1', 'l2', 'daisy', 'off']:
|
| 133 |
+
raise ValueError('Invalid normalization method.')
|
| 134 |
+
|
| 135 |
+
# Compute image derivatives.
|
| 136 |
+
dx = np.zeros(image.shape, dtype=float_dtype)
|
| 137 |
+
dy = np.zeros(image.shape, dtype=float_dtype)
|
| 138 |
+
dx[:, :-1] = np.diff(image, n=1, axis=1)
|
| 139 |
+
dy[:-1, :] = np.diff(image, n=1, axis=0)
|
| 140 |
+
|
| 141 |
+
# Compute gradient orientation and magnitude and their contribution
|
| 142 |
+
# to the histograms.
|
| 143 |
+
grad_mag = sqrt(dx**2 + dy**2)
|
| 144 |
+
grad_ori = arctan2(dy, dx)
|
| 145 |
+
orientation_kappa = orientations / pi
|
| 146 |
+
orientation_angles = [2 * o * pi / orientations - pi for o in range(orientations)]
|
| 147 |
+
hist = np.empty((orientations,) + image.shape, dtype=float_dtype)
|
| 148 |
+
for i, o in enumerate(orientation_angles):
|
| 149 |
+
# Weigh bin contribution by the circular normal distribution
|
| 150 |
+
hist[i, :, :] = exp(orientation_kappa * np.cos(grad_ori - o))
|
| 151 |
+
# Weigh bin contribution by the gradient magnitude
|
| 152 |
+
hist[i, :, :] = np.multiply(hist[i, :, :], grad_mag)
|
| 153 |
+
|
| 154 |
+
# Smooth orientation histograms for the center and all rings.
|
| 155 |
+
sigmas = [sigmas[0]] + sigmas
|
| 156 |
+
hist_smooth = np.empty((rings + 1,) + hist.shape, dtype=float_dtype)
|
| 157 |
+
for i in range(rings + 1):
|
| 158 |
+
for j in range(orientations):
|
| 159 |
+
hist_smooth[i, j, :, :] = gaussian(
|
| 160 |
+
hist[j, :, :], sigma=sigmas[i], mode='reflect'
|
| 161 |
+
)
|
| 162 |
+
|
| 163 |
+
# Assemble descriptor grid.
|
| 164 |
+
theta = [2 * pi * j / histograms for j in range(histograms)]
|
| 165 |
+
desc_dims = (rings * histograms + 1) * orientations
|
| 166 |
+
descs = np.empty(
|
| 167 |
+
(desc_dims, image.shape[0] - 2 * radius, image.shape[1] - 2 * radius),
|
| 168 |
+
dtype=float_dtype,
|
| 169 |
+
)
|
| 170 |
+
descs[:orientations, :, :] = hist_smooth[0, :, radius:-radius, radius:-radius]
|
| 171 |
+
idx = orientations
|
| 172 |
+
for i in range(rings):
|
| 173 |
+
for j in range(histograms):
|
| 174 |
+
y_min = radius + int(round(ring_radii[i] * math.sin(theta[j])))
|
| 175 |
+
y_max = descs.shape[1] + y_min
|
| 176 |
+
x_min = radius + int(round(ring_radii[i] * math.cos(theta[j])))
|
| 177 |
+
x_max = descs.shape[2] + x_min
|
| 178 |
+
descs[idx : idx + orientations, :, :] = hist_smooth[
|
| 179 |
+
i + 1, :, y_min:y_max, x_min:x_max
|
| 180 |
+
]
|
| 181 |
+
idx += orientations
|
| 182 |
+
descs = descs[:, ::step, ::step]
|
| 183 |
+
descs = descs.swapaxes(0, 1).swapaxes(1, 2)
|
| 184 |
+
|
| 185 |
+
# Normalize descriptors.
|
| 186 |
+
if normalization != 'off':
|
| 187 |
+
descs += 1e-10
|
| 188 |
+
if normalization == 'l1':
|
| 189 |
+
descs /= np.sum(descs, axis=2)[:, :, np.newaxis]
|
| 190 |
+
elif normalization == 'l2':
|
| 191 |
+
descs /= sqrt(np.sum(descs**2, axis=2))[:, :, np.newaxis]
|
| 192 |
+
elif normalization == 'daisy':
|
| 193 |
+
for i in range(0, desc_dims, orientations):
|
| 194 |
+
norms = sqrt(np.sum(descs[:, :, i : i + orientations] ** 2, axis=2))
|
| 195 |
+
descs[:, :, i : i + orientations] /= norms[:, :, np.newaxis]
|
| 196 |
+
|
| 197 |
+
if visualize:
|
| 198 |
+
descs_img = gray2rgb(image)
|
| 199 |
+
for i in range(descs.shape[0]):
|
| 200 |
+
for j in range(descs.shape[1]):
|
| 201 |
+
# Draw center histogram sigma
|
| 202 |
+
color = [1, 0, 0]
|
| 203 |
+
desc_y = i * step + radius
|
| 204 |
+
desc_x = j * step + radius
|
| 205 |
+
rows, cols, val = draw.circle_perimeter_aa(
|
| 206 |
+
desc_y, desc_x, int(sigmas[0])
|
| 207 |
+
)
|
| 208 |
+
draw.set_color(descs_img, (rows, cols), color, alpha=val)
|
| 209 |
+
max_bin = np.max(descs[i, j, :])
|
| 210 |
+
for o_num, o in enumerate(orientation_angles):
|
| 211 |
+
# Draw center histogram bins
|
| 212 |
+
bin_size = descs[i, j, o_num] / max_bin
|
| 213 |
+
dy = sigmas[0] * bin_size * math.sin(o)
|
| 214 |
+
dx = sigmas[0] * bin_size * math.cos(o)
|
| 215 |
+
rows, cols, val = draw.line_aa(
|
| 216 |
+
desc_y, desc_x, int(desc_y + dy), int(desc_x + dx)
|
| 217 |
+
)
|
| 218 |
+
draw.set_color(descs_img, (rows, cols), color, alpha=val)
|
| 219 |
+
for r_num, r in enumerate(ring_radii):
|
| 220 |
+
color_offset = float(1 + r_num) / rings
|
| 221 |
+
color = (1 - color_offset, 1, color_offset)
|
| 222 |
+
for t_num, t in enumerate(theta):
|
| 223 |
+
# Draw ring histogram sigmas
|
| 224 |
+
hist_y = desc_y + int(round(r * math.sin(t)))
|
| 225 |
+
hist_x = desc_x + int(round(r * math.cos(t)))
|
| 226 |
+
rows, cols, val = draw.circle_perimeter_aa(
|
| 227 |
+
hist_y, hist_x, int(sigmas[r_num + 1])
|
| 228 |
+
)
|
| 229 |
+
draw.set_color(descs_img, (rows, cols), color, alpha=val)
|
| 230 |
+
for o_num, o in enumerate(orientation_angles):
|
| 231 |
+
# Draw histogram bins
|
| 232 |
+
bin_size = descs[
|
| 233 |
+
i,
|
| 234 |
+
j,
|
| 235 |
+
orientations
|
| 236 |
+
+ r_num * histograms * orientations
|
| 237 |
+
+ t_num * orientations
|
| 238 |
+
+ o_num,
|
| 239 |
+
]
|
| 240 |
+
bin_size /= max_bin
|
| 241 |
+
dy = sigmas[r_num + 1] * bin_size * math.sin(o)
|
| 242 |
+
dx = sigmas[r_num + 1] * bin_size * math.cos(o)
|
| 243 |
+
rows, cols, val = draw.line_aa(
|
| 244 |
+
hist_y, hist_x, int(hist_y + dy), int(hist_x + dx)
|
| 245 |
+
)
|
| 246 |
+
draw.set_color(descs_img, (rows, cols), color, alpha=val)
|
| 247 |
+
return descs, descs_img
|
| 248 |
+
else:
|
| 249 |
+
return descs
|
envs/kitoverlay/skimage/feature/_fisher_vector.py
ADDED
|
@@ -0,0 +1,262 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
fisher_vector.py - Implementation of the Fisher vector encoding algorithm
|
| 3 |
+
|
| 4 |
+
This module contains the source code for Fisher vector computation. The
|
| 5 |
+
computation is separated into two distinct steps, which are called separately
|
| 6 |
+
by the user, namely:
|
| 7 |
+
|
| 8 |
+
learn_gmm: Used to estimate the GMM for all vectors/descriptors computed for
|
| 9 |
+
all examples in the dataset (e.g. estimated using all the SIFT
|
| 10 |
+
vectors computed for all images in the dataset, or at least a subset
|
| 11 |
+
of this).
|
| 12 |
+
|
| 13 |
+
fisher_vector: Used to compute the Fisher vector representation for a
|
| 14 |
+
single set of descriptors/vector (e.g. the SIFT
|
| 15 |
+
descriptors for a single image in your dataset, or
|
| 16 |
+
perhaps a test image).
|
| 17 |
+
|
| 18 |
+
Reference: Perronnin, F. and Dance, C. Fisher kernels on Visual Vocabularies
|
| 19 |
+
for Image Categorization, IEEE Conference on Computer Vision and
|
| 20 |
+
Pattern Recognition, 2007
|
| 21 |
+
|
| 22 |
+
Origin Author: Dan Oneata (Author of the original implementation for the Fisher
|
| 23 |
+
vector computation using scikit-learn and NumPy. Subsequently ported to
|
| 24 |
+
scikit-image (here) by other authors.)
|
| 25 |
+
"""
|
| 26 |
+
|
| 27 |
+
import numpy as np
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
__doctest_requires__ = {("learn_gmm", "fisher_vector"): ["sklearn"]}
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
class FisherVectorException(Exception):
|
| 34 |
+
pass
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class DescriptorException(FisherVectorException):
|
| 38 |
+
pass
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def learn_gmm(descriptors, *, n_modes=32, gm_args=None):
|
| 42 |
+
"""Estimate a Gaussian mixture model (GMM) given a set of descriptors and
|
| 43 |
+
number of modes (i.e. Gaussians). This function is essentially a wrapper
|
| 44 |
+
around the scikit-learn implementation of GMM, namely the
|
| 45 |
+
:class:`sklearn.mixture.GaussianMixture` class.
|
| 46 |
+
|
| 47 |
+
Due to the nature of the Fisher vector, the only enforced parameter of the
|
| 48 |
+
underlying scikit-learn class is the covariance_type, which must be 'diag'.
|
| 49 |
+
|
| 50 |
+
There is no simple way to know what value to use for `n_modes` a-priori.
|
| 51 |
+
Typically, the value is usually one of ``{16, 32, 64, 128}``. One may train
|
| 52 |
+
a few GMMs and choose the one that maximises the log probability of the
|
| 53 |
+
GMM, or choose `n_modes` such that the downstream classifier trained on
|
| 54 |
+
the resultant Fisher vectors has maximal performance.
|
| 55 |
+
|
| 56 |
+
Parameters
|
| 57 |
+
----------
|
| 58 |
+
descriptors : np.ndarray (N, M) or list [(N1, M), (N2, M), ...]
|
| 59 |
+
List of NumPy arrays, or a single NumPy array, of the descriptors
|
| 60 |
+
used to estimate the GMM. The reason a list of NumPy arrays is
|
| 61 |
+
permissible is because often when using a Fisher vector encoding,
|
| 62 |
+
descriptors/vectors are computed separately for each sample/image in
|
| 63 |
+
the dataset, such as SIFT vectors for each image. If a list if passed
|
| 64 |
+
in, then each element must be a NumPy array in which the number of
|
| 65 |
+
rows may differ (e.g. different number of SIFT vector for each image),
|
| 66 |
+
but the number of columns for each must be the same (i.e. the
|
| 67 |
+
dimensionality must be the same).
|
| 68 |
+
n_modes : int
|
| 69 |
+
The number of modes/Gaussians to estimate during the GMM estimate.
|
| 70 |
+
gm_args : dict
|
| 71 |
+
Keyword arguments that can be passed into the underlying scikit-learn
|
| 72 |
+
:class:`sklearn.mixture.GaussianMixture` class.
|
| 73 |
+
|
| 74 |
+
Returns
|
| 75 |
+
-------
|
| 76 |
+
gmm : :class:`sklearn.mixture.GaussianMixture`
|
| 77 |
+
The estimated GMM object, which contains the necessary parameters
|
| 78 |
+
needed to compute the Fisher vector.
|
| 79 |
+
|
| 80 |
+
References
|
| 81 |
+
----------
|
| 82 |
+
.. [1] https://scikit-learn.org/stable/modules/generated/sklearn.mixture.GaussianMixture.html
|
| 83 |
+
|
| 84 |
+
Examples
|
| 85 |
+
--------
|
| 86 |
+
>>> from skimage.feature import fisher_vector
|
| 87 |
+
>>> rng = np.random.Generator(np.random.PCG64())
|
| 88 |
+
>>> sift_for_images = [rng.standard_normal((10, 128)) for _ in range(10)]
|
| 89 |
+
>>> num_modes = 16
|
| 90 |
+
>>> # Estimate 16-mode GMM with these synthetic SIFT vectors
|
| 91 |
+
>>> gmm = learn_gmm(sift_for_images, n_modes=num_modes)
|
| 92 |
+
"""
|
| 93 |
+
|
| 94 |
+
try:
|
| 95 |
+
from sklearn.mixture import GaussianMixture
|
| 96 |
+
except ImportError:
|
| 97 |
+
raise ImportError(
|
| 98 |
+
'scikit-learn is not installed. Please ensure it is installed in '
|
| 99 |
+
'order to use the Fisher vector functionality.'
|
| 100 |
+
)
|
| 101 |
+
|
| 102 |
+
if not isinstance(descriptors, (list, np.ndarray)):
|
| 103 |
+
raise DescriptorException(
|
| 104 |
+
'Please ensure descriptors are either a NumPy array, '
|
| 105 |
+
'or a list of NumPy arrays.'
|
| 106 |
+
)
|
| 107 |
+
|
| 108 |
+
d_mat_1 = descriptors[0]
|
| 109 |
+
if isinstance(descriptors, list) and not isinstance(d_mat_1, np.ndarray):
|
| 110 |
+
raise DescriptorException(
|
| 111 |
+
'Please ensure descriptors are a list of NumPy arrays.'
|
| 112 |
+
)
|
| 113 |
+
|
| 114 |
+
if isinstance(descriptors, list):
|
| 115 |
+
expected_shape = descriptors[0].shape
|
| 116 |
+
ranks = [len(e.shape) == len(expected_shape) for e in descriptors]
|
| 117 |
+
if not all(ranks):
|
| 118 |
+
raise DescriptorException(
|
| 119 |
+
'Please ensure all elements of your descriptor list ' 'are of rank 2.'
|
| 120 |
+
)
|
| 121 |
+
dims = [e.shape[1] == descriptors[0].shape[1] for e in descriptors]
|
| 122 |
+
if not all(dims):
|
| 123 |
+
raise DescriptorException(
|
| 124 |
+
'Please ensure all descriptors are of the same dimensionality.'
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
if not isinstance(n_modes, int) or n_modes <= 0:
|
| 128 |
+
raise FisherVectorException('Please ensure n_modes is a positive integer.')
|
| 129 |
+
|
| 130 |
+
if gm_args:
|
| 131 |
+
has_cov_type = 'covariance_type' in gm_args
|
| 132 |
+
cov_type_not_diag = gm_args['covariance_type'] != 'diag'
|
| 133 |
+
if has_cov_type and cov_type_not_diag:
|
| 134 |
+
raise FisherVectorException('Covariance type must be "diag".')
|
| 135 |
+
|
| 136 |
+
if isinstance(descriptors, list):
|
| 137 |
+
descriptors = np.vstack(descriptors)
|
| 138 |
+
|
| 139 |
+
if gm_args:
|
| 140 |
+
has_cov_type = 'covariance_type' in gm_args
|
| 141 |
+
if has_cov_type:
|
| 142 |
+
gmm = GaussianMixture(n_components=n_modes, **gm_args)
|
| 143 |
+
else:
|
| 144 |
+
gmm = GaussianMixture(
|
| 145 |
+
n_components=n_modes, covariance_type='diag', **gm_args
|
| 146 |
+
)
|
| 147 |
+
else:
|
| 148 |
+
gmm = GaussianMixture(n_components=n_modes, covariance_type='diag')
|
| 149 |
+
|
| 150 |
+
gmm.fit(descriptors)
|
| 151 |
+
|
| 152 |
+
return gmm
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def fisher_vector(descriptors, gmm, *, improved=False, alpha=0.5):
|
| 156 |
+
"""Compute the Fisher vector given some descriptors/vectors,
|
| 157 |
+
and an associated estimated GMM.
|
| 158 |
+
|
| 159 |
+
Parameters
|
| 160 |
+
----------
|
| 161 |
+
descriptors : np.ndarray, shape=(n_descriptors, descriptor_length)
|
| 162 |
+
NumPy array of the descriptors for which the Fisher vector
|
| 163 |
+
representation is to be computed.
|
| 164 |
+
gmm : :class:`sklearn.mixture.GaussianMixture`
|
| 165 |
+
An estimated GMM object, which contains the necessary parameters needed
|
| 166 |
+
to compute the Fisher vector.
|
| 167 |
+
improved : bool, default=False
|
| 168 |
+
Flag denoting whether to compute improved Fisher vectors or not.
|
| 169 |
+
Improved Fisher vectors are L2 and power normalized. Power
|
| 170 |
+
normalization is simply f(z) = sign(z) pow(abs(z), alpha) for some
|
| 171 |
+
0 <= alpha <= 1.
|
| 172 |
+
alpha : float, default=0.5
|
| 173 |
+
The parameter for the power normalization step. Ignored if
|
| 174 |
+
improved=False.
|
| 175 |
+
|
| 176 |
+
Returns
|
| 177 |
+
-------
|
| 178 |
+
fisher_vector : np.ndarray
|
| 179 |
+
The computation Fisher vector, which is given by a concatenation of the
|
| 180 |
+
gradients of a GMM with respect to its parameters (mixture weights,
|
| 181 |
+
means, and covariance matrices). For D-dimensional input descriptors or
|
| 182 |
+
vectors, and a K-mode GMM, the Fisher vector dimensionality will be
|
| 183 |
+
2KD + K. Thus, its dimensionality is invariant to the number of
|
| 184 |
+
descriptors/vectors.
|
| 185 |
+
|
| 186 |
+
References
|
| 187 |
+
----------
|
| 188 |
+
.. [1] Perronnin, F. and Dance, C. Fisher kernels on Visual Vocabularies
|
| 189 |
+
for Image Categorization, IEEE Conference on Computer Vision and
|
| 190 |
+
Pattern Recognition, 2007
|
| 191 |
+
.. [2] Perronnin, F. and Sanchez, J. and Mensink T. Improving the Fisher
|
| 192 |
+
Kernel for Large-Scale Image Classification, ECCV, 2010
|
| 193 |
+
|
| 194 |
+
Examples
|
| 195 |
+
--------
|
| 196 |
+
>>> from skimage.feature import fisher_vector, learn_gmm
|
| 197 |
+
>>> sift_for_images = [np.random.random((10, 128)) for _ in range(10)]
|
| 198 |
+
>>> num_modes = 16
|
| 199 |
+
>>> # Estimate 16-mode GMM with these synthetic SIFT vectors
|
| 200 |
+
>>> gmm = learn_gmm(sift_for_images, n_modes=num_modes)
|
| 201 |
+
>>> test_image_descriptors = np.random.random((25, 128))
|
| 202 |
+
>>> # Compute the Fisher vector
|
| 203 |
+
>>> fv = fisher_vector(test_image_descriptors, gmm)
|
| 204 |
+
"""
|
| 205 |
+
try:
|
| 206 |
+
from sklearn.mixture import GaussianMixture
|
| 207 |
+
except ImportError:
|
| 208 |
+
raise ImportError(
|
| 209 |
+
'scikit-learn is not installed. Please ensure it is installed in '
|
| 210 |
+
'order to use the Fisher vector functionality.'
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
if not isinstance(descriptors, np.ndarray):
|
| 214 |
+
raise DescriptorException('Please ensure descriptors is a NumPy array.')
|
| 215 |
+
|
| 216 |
+
if not isinstance(gmm, GaussianMixture):
|
| 217 |
+
raise FisherVectorException(
|
| 218 |
+
'Please ensure gmm is a sklearn.mixture.GaussianMixture object.'
|
| 219 |
+
)
|
| 220 |
+
|
| 221 |
+
if improved and not isinstance(alpha, float):
|
| 222 |
+
raise FisherVectorException(
|
| 223 |
+
'Please ensure that the alpha parameter is a float.'
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
num_descriptors = len(descriptors)
|
| 227 |
+
|
| 228 |
+
mixture_weights = gmm.weights_
|
| 229 |
+
means = gmm.means_
|
| 230 |
+
covariances = gmm.covariances_
|
| 231 |
+
|
| 232 |
+
posterior_probabilities = gmm.predict_proba(descriptors)
|
| 233 |
+
|
| 234 |
+
# Statistics necessary to compute GMM gradients wrt its parameters
|
| 235 |
+
pp_sum = posterior_probabilities.mean(axis=0, keepdims=True).T
|
| 236 |
+
pp_x = posterior_probabilities.T.dot(descriptors) / num_descriptors
|
| 237 |
+
pp_x_2 = posterior_probabilities.T.dot(np.power(descriptors, 2)) / num_descriptors
|
| 238 |
+
|
| 239 |
+
# Compute GMM gradients wrt its parameters
|
| 240 |
+
d_pi = pp_sum.squeeze() - mixture_weights
|
| 241 |
+
|
| 242 |
+
d_mu = pp_x - pp_sum * means
|
| 243 |
+
|
| 244 |
+
d_sigma_t1 = pp_sum * np.power(means, 2)
|
| 245 |
+
d_sigma_t2 = pp_sum * covariances
|
| 246 |
+
d_sigma_t3 = 2 * pp_x * means
|
| 247 |
+
d_sigma = -pp_x_2 - d_sigma_t1 + d_sigma_t2 + d_sigma_t3
|
| 248 |
+
|
| 249 |
+
# Apply analytical diagonal normalization
|
| 250 |
+
sqrt_mixture_weights = np.sqrt(mixture_weights)
|
| 251 |
+
d_pi /= sqrt_mixture_weights
|
| 252 |
+
d_mu /= sqrt_mixture_weights[:, np.newaxis] * np.sqrt(covariances)
|
| 253 |
+
d_sigma /= np.sqrt(2) * sqrt_mixture_weights[:, np.newaxis] * covariances
|
| 254 |
+
|
| 255 |
+
# Concatenate GMM gradients to form Fisher vector representation
|
| 256 |
+
fisher_vector = np.hstack((d_pi, d_mu.ravel(), d_sigma.ravel()))
|
| 257 |
+
|
| 258 |
+
if improved:
|
| 259 |
+
fisher_vector = np.sign(fisher_vector) * np.power(np.abs(fisher_vector), alpha)
|
| 260 |
+
fisher_vector = fisher_vector / np.linalg.norm(fisher_vector)
|
| 261 |
+
|
| 262 |
+
return fisher_vector
|
envs/kitoverlay/skimage/feature/_hessian_det_appx.cpython-311-x86_64-linux-gnu.so
ADDED
|
Binary file (65.4 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/_hog.py
ADDED
|
@@ -0,0 +1,341 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from . import _hoghistogram
|
| 4 |
+
from .._shared import utils
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def _hog_normalize_block(block, method, eps=1e-5):
|
| 8 |
+
if method == 'L1':
|
| 9 |
+
out = block / (np.sum(np.abs(block)) + eps)
|
| 10 |
+
elif method == 'L1-sqrt':
|
| 11 |
+
out = np.sqrt(block / (np.sum(np.abs(block)) + eps))
|
| 12 |
+
elif method == 'L2':
|
| 13 |
+
out = block / np.sqrt(np.sum(block**2) + eps**2)
|
| 14 |
+
elif method == 'L2-Hys':
|
| 15 |
+
out = block / np.sqrt(np.sum(block**2) + eps**2)
|
| 16 |
+
out = np.minimum(out, 0.2)
|
| 17 |
+
out = out / np.sqrt(np.sum(out**2) + eps**2)
|
| 18 |
+
else:
|
| 19 |
+
raise ValueError('Selected block normalization method is invalid.')
|
| 20 |
+
|
| 21 |
+
return out
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _hog_channel_gradient(channel):
|
| 25 |
+
"""Compute unnormalized gradient image along `row` and `col` axes.
|
| 26 |
+
|
| 27 |
+
Parameters
|
| 28 |
+
----------
|
| 29 |
+
channel : (M, N) ndarray
|
| 30 |
+
Grayscale image or one of image channel.
|
| 31 |
+
|
| 32 |
+
Returns
|
| 33 |
+
-------
|
| 34 |
+
g_row, g_col : channel gradient along `row` and `col` axes correspondingly.
|
| 35 |
+
"""
|
| 36 |
+
g_row = np.empty(channel.shape, dtype=channel.dtype)
|
| 37 |
+
g_row[0, :] = 0
|
| 38 |
+
g_row[-1, :] = 0
|
| 39 |
+
g_row[1:-1, :] = channel[2:, :] - channel[:-2, :]
|
| 40 |
+
g_col = np.empty(channel.shape, dtype=channel.dtype)
|
| 41 |
+
g_col[:, 0] = 0
|
| 42 |
+
g_col[:, -1] = 0
|
| 43 |
+
g_col[:, 1:-1] = channel[:, 2:] - channel[:, :-2]
|
| 44 |
+
|
| 45 |
+
return g_row, g_col
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@utils.channel_as_last_axis(multichannel_output=False)
|
| 49 |
+
def hog(
|
| 50 |
+
image,
|
| 51 |
+
orientations=9,
|
| 52 |
+
pixels_per_cell=(8, 8),
|
| 53 |
+
cells_per_block=(3, 3),
|
| 54 |
+
block_norm='L2-Hys',
|
| 55 |
+
visualize=False,
|
| 56 |
+
transform_sqrt=False,
|
| 57 |
+
feature_vector=True,
|
| 58 |
+
*,
|
| 59 |
+
channel_axis=None,
|
| 60 |
+
):
|
| 61 |
+
"""Extract Histogram of Oriented Gradients (HOG) for a given image.
|
| 62 |
+
|
| 63 |
+
Compute a Histogram of Oriented Gradients (HOG) by
|
| 64 |
+
|
| 65 |
+
1. (optional) global image normalization
|
| 66 |
+
2. computing the gradient image in `row` and `col`
|
| 67 |
+
3. computing gradient histograms
|
| 68 |
+
4. normalizing across blocks
|
| 69 |
+
5. flattening into a feature vector
|
| 70 |
+
|
| 71 |
+
Parameters
|
| 72 |
+
----------
|
| 73 |
+
image : (M, N[, C]) ndarray
|
| 74 |
+
Input image.
|
| 75 |
+
orientations : int, optional
|
| 76 |
+
Number of orientation bins.
|
| 77 |
+
pixels_per_cell : 2-tuple (int, int), optional
|
| 78 |
+
Size (in pixels) of a cell.
|
| 79 |
+
cells_per_block : 2-tuple (int, int), optional
|
| 80 |
+
Number of cells in each block.
|
| 81 |
+
block_norm : str {'L1', 'L1-sqrt', 'L2', 'L2-Hys'}, optional
|
| 82 |
+
Block normalization method:
|
| 83 |
+
|
| 84 |
+
``L1``
|
| 85 |
+
Normalization using L1-norm.
|
| 86 |
+
``L1-sqrt``
|
| 87 |
+
Normalization using L1-norm, followed by square root.
|
| 88 |
+
``L2``
|
| 89 |
+
Normalization using L2-norm.
|
| 90 |
+
``L2-Hys``
|
| 91 |
+
Normalization using L2-norm, followed by limiting the
|
| 92 |
+
maximum values to 0.2 (`Hys` stands for `hysteresis`) and
|
| 93 |
+
renormalization using L2-norm. (default)
|
| 94 |
+
For details, see [3]_, [4]_.
|
| 95 |
+
|
| 96 |
+
visualize : bool, optional
|
| 97 |
+
Also return an image of the HOG. For each cell and orientation bin,
|
| 98 |
+
the image contains a line segment that is centered at the cell center,
|
| 99 |
+
is perpendicular to the midpoint of the range of angles spanned by the
|
| 100 |
+
orientation bin, and has intensity proportional to the corresponding
|
| 101 |
+
histogram value.
|
| 102 |
+
transform_sqrt : bool, optional
|
| 103 |
+
Apply power law compression to normalize the image before
|
| 104 |
+
processing. DO NOT use this if the image contains negative
|
| 105 |
+
values. Also see `notes` section below.
|
| 106 |
+
feature_vector : bool, optional
|
| 107 |
+
Return the data as a feature vector by calling .ravel() on the result
|
| 108 |
+
just before returning.
|
| 109 |
+
channel_axis : int or None, optional
|
| 110 |
+
If None, the image is assumed to be a grayscale (single channel) image.
|
| 111 |
+
Otherwise, this parameter indicates which axis of the array corresponds
|
| 112 |
+
to channels.
|
| 113 |
+
|
| 114 |
+
.. versionadded:: 0.19
|
| 115 |
+
`channel_axis` was added in 0.19.
|
| 116 |
+
|
| 117 |
+
Returns
|
| 118 |
+
-------
|
| 119 |
+
out : (n_blocks_row, n_blocks_col, n_cells_row, n_cells_col, n_orient) ndarray
|
| 120 |
+
HOG descriptor for the image. If `feature_vector` is True, a 1D
|
| 121 |
+
(flattened) array is returned.
|
| 122 |
+
hog_image : (M, N) ndarray, optional
|
| 123 |
+
A visualisation of the HOG image. Only provided if `visualize` is True.
|
| 124 |
+
|
| 125 |
+
Raises
|
| 126 |
+
------
|
| 127 |
+
ValueError
|
| 128 |
+
If the image is too small given the values of pixels_per_cell and
|
| 129 |
+
cells_per_block.
|
| 130 |
+
|
| 131 |
+
References
|
| 132 |
+
----------
|
| 133 |
+
.. [1] https://en.wikipedia.org/wiki/Histogram_of_oriented_gradients
|
| 134 |
+
|
| 135 |
+
.. [2] Dalal, N and Triggs, B, Histograms of Oriented Gradients for
|
| 136 |
+
Human Detection, IEEE Computer Society Conference on Computer
|
| 137 |
+
Vision and Pattern Recognition 2005 San Diego, CA, USA,
|
| 138 |
+
https://lear.inrialpes.fr/people/triggs/pubs/Dalal-cvpr05.pdf,
|
| 139 |
+
:DOI:`10.1109/CVPR.2005.177`
|
| 140 |
+
|
| 141 |
+
.. [3] Lowe, D.G., Distinctive image features from scale-invatiant
|
| 142 |
+
keypoints, International Journal of Computer Vision (2004) 60: 91,
|
| 143 |
+
http://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf,
|
| 144 |
+
:DOI:`10.1023/B:VISI.0000029664.99615.94`
|
| 145 |
+
|
| 146 |
+
.. [4] Dalal, N, Finding People in Images and Videos,
|
| 147 |
+
Human-Computer Interaction [cs.HC], Institut National Polytechnique
|
| 148 |
+
de Grenoble - INPG, 2006,
|
| 149 |
+
https://tel.archives-ouvertes.fr/tel-00390303/file/NavneetDalalThesis.pdf
|
| 150 |
+
|
| 151 |
+
Notes
|
| 152 |
+
-----
|
| 153 |
+
The presented code implements the HOG extraction method from [2]_ with
|
| 154 |
+
the following changes: (I) blocks of (3, 3) cells are used ((2, 2) in the
|
| 155 |
+
paper); (II) no smoothing within cells (Gaussian spatial window with sigma=8pix
|
| 156 |
+
in the paper); (III) L1 block normalization is used (L2-Hys in the paper).
|
| 157 |
+
|
| 158 |
+
Power law compression, also known as Gamma correction, is used to reduce
|
| 159 |
+
the effects of shadowing and illumination variations. The compression makes
|
| 160 |
+
the dark regions lighter. When the kwarg `transform_sqrt` is set to
|
| 161 |
+
``True``, the function computes the square root of each color channel
|
| 162 |
+
and then applies the hog algorithm to the image.
|
| 163 |
+
"""
|
| 164 |
+
image = np.atleast_2d(image)
|
| 165 |
+
float_dtype = utils._supported_float_type(image.dtype)
|
| 166 |
+
image = image.astype(float_dtype, copy=False)
|
| 167 |
+
|
| 168 |
+
multichannel = channel_axis is not None
|
| 169 |
+
ndim_spatial = image.ndim - 1 if multichannel else image.ndim
|
| 170 |
+
if ndim_spatial != 2:
|
| 171 |
+
raise ValueError(
|
| 172 |
+
'Only images with two spatial dimensions are '
|
| 173 |
+
'supported. If using with color/multichannel '
|
| 174 |
+
'images, specify `channel_axis`.'
|
| 175 |
+
)
|
| 176 |
+
|
| 177 |
+
"""
|
| 178 |
+
The first stage applies an optional global image normalization
|
| 179 |
+
equalisation that is designed to reduce the influence of illumination
|
| 180 |
+
effects. In practice we use gamma (power law) compression, either
|
| 181 |
+
computing the square root or the log of each color channel.
|
| 182 |
+
Image texture strength is typically proportional to the local surface
|
| 183 |
+
illumination so this compression helps to reduce the effects of local
|
| 184 |
+
shadowing and illumination variations.
|
| 185 |
+
"""
|
| 186 |
+
|
| 187 |
+
if transform_sqrt:
|
| 188 |
+
image = np.sqrt(image)
|
| 189 |
+
|
| 190 |
+
"""
|
| 191 |
+
The second stage computes first order image gradients. These capture
|
| 192 |
+
contour, silhouette and some texture information, while providing
|
| 193 |
+
further resistance to illumination variations. The locally dominant
|
| 194 |
+
color channel is used, which provides color invariance to a large
|
| 195 |
+
extent. Variant methods may also include second order image derivatives,
|
| 196 |
+
which act as primitive bar detectors - a useful feature for capturing,
|
| 197 |
+
e.g. bar like structures in bicycles and limbs in humans.
|
| 198 |
+
"""
|
| 199 |
+
|
| 200 |
+
if multichannel:
|
| 201 |
+
g_row_by_ch = np.empty_like(image, dtype=float_dtype)
|
| 202 |
+
g_col_by_ch = np.empty_like(image, dtype=float_dtype)
|
| 203 |
+
g_magn = np.empty_like(image, dtype=float_dtype)
|
| 204 |
+
|
| 205 |
+
for idx_ch in range(image.shape[2]):
|
| 206 |
+
(
|
| 207 |
+
g_row_by_ch[:, :, idx_ch],
|
| 208 |
+
g_col_by_ch[:, :, idx_ch],
|
| 209 |
+
) = _hog_channel_gradient(image[:, :, idx_ch])
|
| 210 |
+
g_magn[:, :, idx_ch] = np.hypot(
|
| 211 |
+
g_row_by_ch[:, :, idx_ch], g_col_by_ch[:, :, idx_ch]
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
# For each pixel select the channel with the highest gradient magnitude
|
| 215 |
+
idcs_max = g_magn.argmax(axis=2)
|
| 216 |
+
rr, cc = np.meshgrid(
|
| 217 |
+
np.arange(image.shape[0]),
|
| 218 |
+
np.arange(image.shape[1]),
|
| 219 |
+
indexing='ij',
|
| 220 |
+
sparse=True,
|
| 221 |
+
)
|
| 222 |
+
g_row = g_row_by_ch[rr, cc, idcs_max]
|
| 223 |
+
g_col = g_col_by_ch[rr, cc, idcs_max]
|
| 224 |
+
else:
|
| 225 |
+
g_row, g_col = _hog_channel_gradient(image)
|
| 226 |
+
|
| 227 |
+
"""
|
| 228 |
+
The third stage aims to produce an encoding that is sensitive to
|
| 229 |
+
local image content while remaining resistant to small changes in
|
| 230 |
+
pose or appearance. The adopted method pools gradient orientation
|
| 231 |
+
information locally in the same way as the SIFT [Lowe 2004]
|
| 232 |
+
feature. The image window is divided into small spatial regions,
|
| 233 |
+
called "cells". For each cell we accumulate a local 1-D histogram
|
| 234 |
+
of gradient or edge orientations over all the pixels in the
|
| 235 |
+
cell. This combined cell-level 1-D histogram forms the basic
|
| 236 |
+
"orientation histogram" representation. Each orientation histogram
|
| 237 |
+
divides the gradient angle range into a fixed number of
|
| 238 |
+
predetermined bins. The gradient magnitudes of the pixels in the
|
| 239 |
+
cell are used to vote into the orientation histogram.
|
| 240 |
+
"""
|
| 241 |
+
|
| 242 |
+
s_row, s_col = image.shape[:2]
|
| 243 |
+
c_row, c_col = pixels_per_cell
|
| 244 |
+
b_row, b_col = cells_per_block
|
| 245 |
+
|
| 246 |
+
n_cells_row = int(s_row // c_row) # number of cells along row-axis
|
| 247 |
+
n_cells_col = int(s_col // c_col) # number of cells along col-axis
|
| 248 |
+
|
| 249 |
+
# compute orientations integral images
|
| 250 |
+
orientation_histogram = np.zeros(
|
| 251 |
+
(n_cells_row, n_cells_col, orientations), dtype=float
|
| 252 |
+
)
|
| 253 |
+
g_row = g_row.astype(float, copy=False)
|
| 254 |
+
g_col = g_col.astype(float, copy=False)
|
| 255 |
+
|
| 256 |
+
_hoghistogram.hog_histograms(
|
| 257 |
+
g_col,
|
| 258 |
+
g_row,
|
| 259 |
+
c_col,
|
| 260 |
+
c_row,
|
| 261 |
+
s_col,
|
| 262 |
+
s_row,
|
| 263 |
+
n_cells_col,
|
| 264 |
+
n_cells_row,
|
| 265 |
+
orientations,
|
| 266 |
+
orientation_histogram,
|
| 267 |
+
)
|
| 268 |
+
|
| 269 |
+
# now compute the histogram for each cell
|
| 270 |
+
hog_image = None
|
| 271 |
+
|
| 272 |
+
if visualize:
|
| 273 |
+
from .. import draw
|
| 274 |
+
|
| 275 |
+
radius = min(c_row, c_col) // 2 - 1
|
| 276 |
+
orientations_arr = np.arange(orientations)
|
| 277 |
+
# set dr_arr, dc_arr to correspond to midpoints of orientation bins
|
| 278 |
+
orientation_bin_midpoints = np.pi * (orientations_arr + 0.5) / orientations
|
| 279 |
+
dr_arr = radius * np.sin(orientation_bin_midpoints)
|
| 280 |
+
dc_arr = radius * np.cos(orientation_bin_midpoints)
|
| 281 |
+
hog_image = np.zeros((s_row, s_col), dtype=float_dtype)
|
| 282 |
+
for r in range(n_cells_row):
|
| 283 |
+
for c in range(n_cells_col):
|
| 284 |
+
for o, dr, dc in zip(orientations_arr, dr_arr, dc_arr):
|
| 285 |
+
centre = tuple([r * c_row + c_row // 2, c * c_col + c_col // 2])
|
| 286 |
+
rr, cc = draw.line(
|
| 287 |
+
int(centre[0] - dc),
|
| 288 |
+
int(centre[1] + dr),
|
| 289 |
+
int(centre[0] + dc),
|
| 290 |
+
int(centre[1] - dr),
|
| 291 |
+
)
|
| 292 |
+
hog_image[rr, cc] += orientation_histogram[r, c, o]
|
| 293 |
+
|
| 294 |
+
"""
|
| 295 |
+
The fourth stage computes normalization, which takes local groups of
|
| 296 |
+
cells and contrast normalizes their overall responses before passing
|
| 297 |
+
to next stage. Normalization introduces better invariance to illumination,
|
| 298 |
+
shadowing, and edge contrast. It is performed by accumulating a measure
|
| 299 |
+
of local histogram "energy" over local groups of cells that we call
|
| 300 |
+
"blocks". The result is used to normalize each cell in the block.
|
| 301 |
+
Typically each individual cell is shared between several blocks, but
|
| 302 |
+
its normalizations are block dependent and thus different. The cell
|
| 303 |
+
thus appears several times in the final output vector with different
|
| 304 |
+
normalizations. This may seem redundant but it improves the performance.
|
| 305 |
+
We refer to the normalized block descriptors as Histogram of Oriented
|
| 306 |
+
Gradient (HOG) descriptors.
|
| 307 |
+
"""
|
| 308 |
+
|
| 309 |
+
n_blocks_row = (n_cells_row - b_row) + 1
|
| 310 |
+
n_blocks_col = (n_cells_col - b_col) + 1
|
| 311 |
+
if n_blocks_col <= 0 or n_blocks_row <= 0:
|
| 312 |
+
min_row = b_row * c_row
|
| 313 |
+
min_col = b_col * c_col
|
| 314 |
+
raise ValueError(
|
| 315 |
+
'The input image is too small given the values of '
|
| 316 |
+
'pixels_per_cell and cells_per_block. '
|
| 317 |
+
'It should have at least: '
|
| 318 |
+
f'{min_row} rows and {min_col} cols.'
|
| 319 |
+
)
|
| 320 |
+
normalized_blocks = np.zeros(
|
| 321 |
+
(n_blocks_row, n_blocks_col, b_row, b_col, orientations), dtype=float_dtype
|
| 322 |
+
)
|
| 323 |
+
|
| 324 |
+
for r in range(n_blocks_row):
|
| 325 |
+
for c in range(n_blocks_col):
|
| 326 |
+
block = orientation_histogram[r : r + b_row, c : c + b_col, :]
|
| 327 |
+
normalized_blocks[r, c, :] = _hog_normalize_block(block, method=block_norm)
|
| 328 |
+
|
| 329 |
+
"""
|
| 330 |
+
The final step collects the HOG descriptors from all blocks of a dense
|
| 331 |
+
overlapping grid of blocks covering the detection window into a combined
|
| 332 |
+
feature vector for use in the window classifier.
|
| 333 |
+
"""
|
| 334 |
+
|
| 335 |
+
if feature_vector:
|
| 336 |
+
normalized_blocks = normalized_blocks.ravel()
|
| 337 |
+
|
| 338 |
+
if visualize:
|
| 339 |
+
return normalized_blocks, hog_image
|
| 340 |
+
else:
|
| 341 |
+
return normalized_blocks
|
envs/kitoverlay/skimage/feature/_orb_descriptor_positions.py
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
# Putting this in cython was giving strange bugs for different versions
|
| 5 |
+
# of cython which seemed to indicate troubles with the __file__ variable
|
| 6 |
+
# not being defined. Keeping it in pure python makes it more reliable
|
| 7 |
+
this_dir = os.path.dirname(__file__)
|
| 8 |
+
POS = np.loadtxt(os.path.join(this_dir, "orb_descriptor_positions.txt"), dtype=np.int8)
|
| 9 |
+
POS0 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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import scipy.ndimage as ndi
|
| 5 |
+
from scipy import spatial
|
| 6 |
+
|
| 7 |
+
from .._shared.filters import gaussian
|
| 8 |
+
from .._shared.utils import _supported_float_type, check_nD
|
| 9 |
+
from ..transform import integral_image
|
| 10 |
+
from ..util import img_as_float
|
| 11 |
+
from ._hessian_det_appx import _hessian_matrix_det
|
| 12 |
+
from .peak import peak_local_max
|
| 13 |
+
|
| 14 |
+
# This basic blob detection algorithm is based on:
|
| 15 |
+
# http://www.cs.utah.edu/~jfishbau/advimproc/project1/ (04.04.2013)
|
| 16 |
+
# Theory behind: https://en.wikipedia.org/wiki/Blob_detection (04.04.2013)
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _compute_disk_overlap(d, r1, r2):
|
| 20 |
+
"""
|
| 21 |
+
Compute fraction of surface overlap between two disks of radii
|
| 22 |
+
``r1`` and ``r2``, with centers separated by a distance ``d``.
|
| 23 |
+
|
| 24 |
+
Parameters
|
| 25 |
+
----------
|
| 26 |
+
d : float
|
| 27 |
+
Distance between centers.
|
| 28 |
+
r1 : float
|
| 29 |
+
Radius of the first disk.
|
| 30 |
+
r2 : float
|
| 31 |
+
Radius of the second disk.
|
| 32 |
+
|
| 33 |
+
Returns
|
| 34 |
+
-------
|
| 35 |
+
fraction: float
|
| 36 |
+
Fraction of area of the overlap between the two disks.
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
ratio1 = (d**2 + r1**2 - r2**2) / (2 * d * r1)
|
| 40 |
+
ratio1 = np.clip(ratio1, -1, 1)
|
| 41 |
+
acos1 = math.acos(ratio1)
|
| 42 |
+
|
| 43 |
+
ratio2 = (d**2 + r2**2 - r1**2) / (2 * d * r2)
|
| 44 |
+
ratio2 = np.clip(ratio2, -1, 1)
|
| 45 |
+
acos2 = math.acos(ratio2)
|
| 46 |
+
|
| 47 |
+
a = -d + r2 + r1
|
| 48 |
+
b = d - r2 + r1
|
| 49 |
+
c = d + r2 - r1
|
| 50 |
+
d = d + r2 + r1
|
| 51 |
+
area = r1**2 * acos1 + r2**2 * acos2 - 0.5 * math.sqrt(abs(a * b * c * d))
|
| 52 |
+
return area / (math.pi * (min(r1, r2) ** 2))
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def _compute_sphere_overlap(d, r1, r2):
|
| 56 |
+
"""
|
| 57 |
+
Compute volume overlap fraction between two spheres of radii
|
| 58 |
+
``r1`` and ``r2``, with centers separated by a distance ``d``.
|
| 59 |
+
|
| 60 |
+
Parameters
|
| 61 |
+
----------
|
| 62 |
+
d : float
|
| 63 |
+
Distance between centers.
|
| 64 |
+
r1 : float
|
| 65 |
+
Radius of the first sphere.
|
| 66 |
+
r2 : float
|
| 67 |
+
Radius of the second sphere.
|
| 68 |
+
|
| 69 |
+
Returns
|
| 70 |
+
-------
|
| 71 |
+
fraction: float
|
| 72 |
+
Fraction of volume of the overlap between the two spheres.
|
| 73 |
+
|
| 74 |
+
Notes
|
| 75 |
+
-----
|
| 76 |
+
See for example http://mathworld.wolfram.com/Sphere-SphereIntersection.html
|
| 77 |
+
for more details.
|
| 78 |
+
"""
|
| 79 |
+
vol = (
|
| 80 |
+
math.pi
|
| 81 |
+
/ (12 * d)
|
| 82 |
+
* (r1 + r2 - d) ** 2
|
| 83 |
+
* (d**2 + 2 * d * (r1 + r2) - 3 * (r1**2 + r2**2) + 6 * r1 * r2)
|
| 84 |
+
)
|
| 85 |
+
return vol / (4.0 / 3 * math.pi * min(r1, r2) ** 3)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def _blob_overlap(blob1, blob2, *, sigma_dim=1):
|
| 89 |
+
"""Finds the overlapping area fraction between two blobs.
|
| 90 |
+
|
| 91 |
+
Returns a float representing fraction of overlapped area. Note that 0.0
|
| 92 |
+
is *always* returned for dimension greater than 3.
|
| 93 |
+
|
| 94 |
+
Parameters
|
| 95 |
+
----------
|
| 96 |
+
blob1 : sequence of arrays
|
| 97 |
+
A sequence of ``(row, col, sigma)`` or ``(pln, row, col, sigma)``,
|
| 98 |
+
where ``row, col`` (or ``(pln, row, col)``) are coordinates
|
| 99 |
+
of blob and ``sigma`` is the standard deviation of the Gaussian kernel
|
| 100 |
+
which detected the blob.
|
| 101 |
+
blob2 : sequence of arrays
|
| 102 |
+
A sequence of ``(row, col, sigma)`` or ``(pln, row, col, sigma)``,
|
| 103 |
+
where ``row, col`` (or ``(pln, row, col)``) are coordinates
|
| 104 |
+
of blob and ``sigma`` is the standard deviation of the Gaussian kernel
|
| 105 |
+
which detected the blob.
|
| 106 |
+
sigma_dim : int, optional
|
| 107 |
+
The dimensionality of the sigma value. Can be 1 or the same as the
|
| 108 |
+
dimensionality of the blob space (2 or 3).
|
| 109 |
+
|
| 110 |
+
Returns
|
| 111 |
+
-------
|
| 112 |
+
f : float
|
| 113 |
+
Fraction of overlapped area (or volume in 3D).
|
| 114 |
+
"""
|
| 115 |
+
ndim = len(blob1) - sigma_dim
|
| 116 |
+
if ndim > 3:
|
| 117 |
+
return 0.0
|
| 118 |
+
root_ndim = math.sqrt(ndim)
|
| 119 |
+
|
| 120 |
+
# we divide coordinates by sigma * sqrt(ndim) to rescale space to isotropy,
|
| 121 |
+
# giving spheres of radius = 1 or < 1.
|
| 122 |
+
if blob1[-1] == blob2[-1] == 0:
|
| 123 |
+
return 0.0
|
| 124 |
+
elif blob1[-1] > blob2[-1]:
|
| 125 |
+
max_sigma = blob1[-sigma_dim:]
|
| 126 |
+
r1 = 1
|
| 127 |
+
r2 = blob2[-1] / blob1[-1]
|
| 128 |
+
else:
|
| 129 |
+
max_sigma = blob2[-sigma_dim:]
|
| 130 |
+
r2 = 1
|
| 131 |
+
r1 = blob1[-1] / blob2[-1]
|
| 132 |
+
pos1 = blob1[:ndim] / (max_sigma * root_ndim)
|
| 133 |
+
pos2 = blob2[:ndim] / (max_sigma * root_ndim)
|
| 134 |
+
|
| 135 |
+
d = np.sqrt(np.sum((pos2 - pos1) ** 2))
|
| 136 |
+
if d > r1 + r2: # centers farther than sum of radii, so no overlap
|
| 137 |
+
return 0.0
|
| 138 |
+
|
| 139 |
+
# one blob is inside the other
|
| 140 |
+
if d <= abs(r1 - r2):
|
| 141 |
+
return 1.0
|
| 142 |
+
|
| 143 |
+
if ndim == 2:
|
| 144 |
+
return _compute_disk_overlap(d, r1, r2)
|
| 145 |
+
|
| 146 |
+
else: # ndim=3 http://mathworld.wolfram.com/Sphere-SphereIntersection.html
|
| 147 |
+
return _compute_sphere_overlap(d, r1, r2)
|
| 148 |
+
|
| 149 |
+
|
| 150 |
+
def _prune_blobs(blobs_array, overlap, *, sigma_dim=1):
|
| 151 |
+
"""Eliminated blobs with area overlap.
|
| 152 |
+
|
| 153 |
+
Parameters
|
| 154 |
+
----------
|
| 155 |
+
blobs_array : ndarray
|
| 156 |
+
A 2d array with each row representing 3 (or 4) values,
|
| 157 |
+
``(row, col, sigma)`` or ``(pln, row, col, sigma)`` in 3D,
|
| 158 |
+
where ``(row, col)`` (``(pln, row, col)``) are coordinates of the blob
|
| 159 |
+
and ``sigma`` is the standard deviation of the Gaussian kernel which
|
| 160 |
+
detected the blob.
|
| 161 |
+
This array must not have a dimension of size 0.
|
| 162 |
+
overlap : float
|
| 163 |
+
A value between 0 and 1. If the fraction of area overlapping for 2
|
| 164 |
+
blobs is greater than `overlap` the smaller blob is eliminated.
|
| 165 |
+
sigma_dim : int, optional
|
| 166 |
+
The number of columns in ``blobs_array`` corresponding to sigmas rather
|
| 167 |
+
than positions.
|
| 168 |
+
|
| 169 |
+
Returns
|
| 170 |
+
-------
|
| 171 |
+
A : ndarray
|
| 172 |
+
`array` with overlapping blobs removed.
|
| 173 |
+
"""
|
| 174 |
+
sigma = blobs_array[:, -sigma_dim:].max()
|
| 175 |
+
distance = 2 * sigma * math.sqrt(blobs_array.shape[1] - sigma_dim)
|
| 176 |
+
tree = spatial.cKDTree(blobs_array[:, :-sigma_dim])
|
| 177 |
+
pairs = np.array(list(tree.query_pairs(distance)))
|
| 178 |
+
if len(pairs) == 0:
|
| 179 |
+
return blobs_array
|
| 180 |
+
else:
|
| 181 |
+
for i, j in pairs:
|
| 182 |
+
blob1, blob2 = blobs_array[i], blobs_array[j]
|
| 183 |
+
if _blob_overlap(blob1, blob2, sigma_dim=sigma_dim) > overlap:
|
| 184 |
+
# note: this test works even in the anisotropic case because
|
| 185 |
+
# all sigmas increase together.
|
| 186 |
+
if blob1[-1] > blob2[-1]:
|
| 187 |
+
blob2[-1] = 0
|
| 188 |
+
else:
|
| 189 |
+
blob1[-1] = 0
|
| 190 |
+
|
| 191 |
+
return np.stack([b for b in blobs_array if b[-1] > 0])
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _format_exclude_border(img_ndim, exclude_border):
|
| 195 |
+
"""Format an ``exclude_border`` argument as a tuple of ints for calling
|
| 196 |
+
``peak_local_max``.
|
| 197 |
+
"""
|
| 198 |
+
if isinstance(exclude_border, tuple):
|
| 199 |
+
if len(exclude_border) != img_ndim:
|
| 200 |
+
raise ValueError(
|
| 201 |
+
"`exclude_border` should have the same length as the "
|
| 202 |
+
"dimensionality of the image."
|
| 203 |
+
)
|
| 204 |
+
for exclude in exclude_border:
|
| 205 |
+
if not isinstance(exclude, int):
|
| 206 |
+
raise ValueError(
|
| 207 |
+
"exclude border, when expressed as a tuple, must only "
|
| 208 |
+
"contain ints."
|
| 209 |
+
)
|
| 210 |
+
return exclude_border + (0,)
|
| 211 |
+
elif isinstance(exclude_border, int):
|
| 212 |
+
return (exclude_border,) * img_ndim + (0,)
|
| 213 |
+
elif exclude_border is True:
|
| 214 |
+
raise ValueError("exclude_border cannot be True")
|
| 215 |
+
elif exclude_border is False:
|
| 216 |
+
return (0,) * (img_ndim + 1)
|
| 217 |
+
else:
|
| 218 |
+
raise ValueError(f'Unsupported value ({exclude_border}) for exclude_border')
|
| 219 |
+
|
| 220 |
+
|
| 221 |
+
def blob_dog(
|
| 222 |
+
image,
|
| 223 |
+
min_sigma=1,
|
| 224 |
+
max_sigma=50,
|
| 225 |
+
sigma_ratio=1.6,
|
| 226 |
+
threshold=0.5,
|
| 227 |
+
overlap=0.5,
|
| 228 |
+
*,
|
| 229 |
+
threshold_rel=None,
|
| 230 |
+
exclude_border=False,
|
| 231 |
+
):
|
| 232 |
+
r"""Finds blobs in the given grayscale image.
|
| 233 |
+
|
| 234 |
+
Blobs are found using the Difference of Gaussian (DoG) method [1]_, [2]_.
|
| 235 |
+
For each blob found, the method returns its coordinates and the standard
|
| 236 |
+
deviation of the Gaussian kernel that detected the blob.
|
| 237 |
+
|
| 238 |
+
Parameters
|
| 239 |
+
----------
|
| 240 |
+
image : ndarray
|
| 241 |
+
Input grayscale image, blobs are assumed to be light on dark
|
| 242 |
+
background (white on black).
|
| 243 |
+
min_sigma : scalar or sequence of scalars, optional
|
| 244 |
+
Minimum standard deviation for Gaussian kernel. Keep this value low to
|
| 245 |
+
detect smaller blobs. The standard deviation of the Gaussian kernel
|
| 246 |
+
is given either as a sequence for each axis, or as a single number, in
|
| 247 |
+
which case it is equal for all axes.
|
| 248 |
+
max_sigma : scalar or sequence of scalars, optional
|
| 249 |
+
The maximum standard deviation for Gaussian kernel. Keep this high to
|
| 250 |
+
detect larger blobs. The standard deviation of the Gaussian kernel
|
| 251 |
+
is given either as a sequence for each axis, or as a single number, in
|
| 252 |
+
which case it is equal for all axes.
|
| 253 |
+
sigma_ratio : float, optional
|
| 254 |
+
The ratio between the standard deviation of Gaussian Kernels used for
|
| 255 |
+
computing the Difference of Gaussians
|
| 256 |
+
threshold : float or None, optional
|
| 257 |
+
The absolute lower bound for scale space maxima. Local maxima smaller
|
| 258 |
+
than `threshold` are ignored. Reduce this to detect blobs with lower
|
| 259 |
+
intensities. If `threshold_rel` is also specified, whichever threshold
|
| 260 |
+
is larger will be used. If None, `threshold_rel` is used instead.
|
| 261 |
+
overlap : float, optional
|
| 262 |
+
A value between 0 and 1. If the area of two blobs overlaps by a
|
| 263 |
+
fraction greater than `threshold`, the smaller blob is eliminated.
|
| 264 |
+
threshold_rel : float or None, optional
|
| 265 |
+
Minimum intensity of peaks, calculated as
|
| 266 |
+
``max(dog_space) * threshold_rel``, where ``dog_space`` refers to the
|
| 267 |
+
stack of Difference-of-Gaussian (DoG) images computed internally. This
|
| 268 |
+
should have a value between 0 and 1. If None, `threshold` is used
|
| 269 |
+
instead.
|
| 270 |
+
exclude_border : tuple of ints, int, or False, optional
|
| 271 |
+
If tuple of ints, the length of the tuple must match the input array's
|
| 272 |
+
dimensionality. Each element of the tuple will exclude peaks from
|
| 273 |
+
within `exclude_border`-pixels of the border of the image along that
|
| 274 |
+
dimension.
|
| 275 |
+
If nonzero int, `exclude_border` excludes peaks from within
|
| 276 |
+
`exclude_border`-pixels of the border of the image.
|
| 277 |
+
If zero or False, peaks are identified regardless of their
|
| 278 |
+
distance from the border.
|
| 279 |
+
|
| 280 |
+
Returns
|
| 281 |
+
-------
|
| 282 |
+
A : (n, image.ndim + sigma) ndarray
|
| 283 |
+
A 2d array with each row representing 2 coordinate values for a 2D
|
| 284 |
+
image, or 3 coordinate values for a 3D image, plus the sigma(s) used.
|
| 285 |
+
When a single sigma is passed, outputs are:
|
| 286 |
+
``(r, c, sigma)`` or ``(p, r, c, sigma)`` where ``(r, c)`` or
|
| 287 |
+
``(p, r, c)`` are coordinates of the blob and ``sigma`` is the standard
|
| 288 |
+
deviation of the Gaussian kernel which detected the blob. When an
|
| 289 |
+
anisotropic gaussian is used (sigmas per dimension), the detected sigma
|
| 290 |
+
is returned for each dimension.
|
| 291 |
+
|
| 292 |
+
See also
|
| 293 |
+
--------
|
| 294 |
+
skimage.filters.difference_of_gaussians
|
| 295 |
+
|
| 296 |
+
References
|
| 297 |
+
----------
|
| 298 |
+
.. [1] https://en.wikipedia.org/wiki/Blob_detection#The_difference_of_Gaussians_approach
|
| 299 |
+
.. [2] Lowe, D. G. "Distinctive Image Features from Scale-Invariant
|
| 300 |
+
Keypoints." International Journal of Computer Vision 60, 91–110 (2004).
|
| 301 |
+
https://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf
|
| 302 |
+
:DOI:`10.1023/B:VISI.0000029664.99615.94`
|
| 303 |
+
|
| 304 |
+
Examples
|
| 305 |
+
--------
|
| 306 |
+
>>> from skimage import data, feature
|
| 307 |
+
>>> coins = data.coins()
|
| 308 |
+
>>> feature.blob_dog(coins, threshold=.05, min_sigma=10, max_sigma=40)
|
| 309 |
+
array([[128., 155., 10.],
|
| 310 |
+
[198., 155., 10.],
|
| 311 |
+
[124., 338., 10.],
|
| 312 |
+
[127., 102., 10.],
|
| 313 |
+
[193., 281., 10.],
|
| 314 |
+
[126., 208., 10.],
|
| 315 |
+
[267., 115., 10.],
|
| 316 |
+
[197., 102., 10.],
|
| 317 |
+
[198., 215., 10.],
|
| 318 |
+
[123., 279., 10.],
|
| 319 |
+
[126., 46., 10.],
|
| 320 |
+
[259., 247., 10.],
|
| 321 |
+
[196., 43., 10.],
|
| 322 |
+
[ 54., 276., 10.],
|
| 323 |
+
[267., 358., 10.],
|
| 324 |
+
[ 58., 100., 10.],
|
| 325 |
+
[259., 305., 10.],
|
| 326 |
+
[185., 347., 16.],
|
| 327 |
+
[261., 174., 16.],
|
| 328 |
+
[ 46., 336., 16.],
|
| 329 |
+
[ 54., 217., 10.],
|
| 330 |
+
[ 55., 157., 10.],
|
| 331 |
+
[ 57., 41., 10.],
|
| 332 |
+
[260., 47., 16.]])
|
| 333 |
+
|
| 334 |
+
Notes
|
| 335 |
+
-----
|
| 336 |
+
The radius of each blob is approximately :math:`\sqrt{2}\sigma` for
|
| 337 |
+
a 2-D image and :math:`\sqrt{3}\sigma` for a 3-D image.
|
| 338 |
+
"""
|
| 339 |
+
image = img_as_float(image)
|
| 340 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 341 |
+
image = image.astype(float_dtype, copy=False)
|
| 342 |
+
|
| 343 |
+
# if both min and max sigma are scalar, function returns only one sigma
|
| 344 |
+
scalar_sigma = np.isscalar(max_sigma) and np.isscalar(min_sigma)
|
| 345 |
+
|
| 346 |
+
# Gaussian filter requires that sequence-type sigmas have same
|
| 347 |
+
# dimensionality as image. This broadcasts scalar kernels
|
| 348 |
+
if np.isscalar(max_sigma):
|
| 349 |
+
max_sigma = np.full(image.ndim, max_sigma, dtype=float_dtype)
|
| 350 |
+
if np.isscalar(min_sigma):
|
| 351 |
+
min_sigma = np.full(image.ndim, min_sigma, dtype=float_dtype)
|
| 352 |
+
|
| 353 |
+
# Convert sequence types to array
|
| 354 |
+
min_sigma = np.asarray(min_sigma, dtype=float_dtype)
|
| 355 |
+
max_sigma = np.asarray(max_sigma, dtype=float_dtype)
|
| 356 |
+
|
| 357 |
+
if sigma_ratio <= 1.0:
|
| 358 |
+
raise ValueError('sigma_ratio must be > 1.0')
|
| 359 |
+
|
| 360 |
+
# k such that min_sigma*(sigma_ratio**k) > max_sigma
|
| 361 |
+
k = int(np.mean(np.log(max_sigma / min_sigma) / np.log(sigma_ratio) + 1))
|
| 362 |
+
|
| 363 |
+
# a geometric progression of standard deviations for gaussian kernels
|
| 364 |
+
sigma_list = np.array([min_sigma * (sigma_ratio**i) for i in range(k + 1)])
|
| 365 |
+
|
| 366 |
+
# computing difference between two successive Gaussian blurred images
|
| 367 |
+
# to obtain an approximation of the scale invariant Laplacian of the
|
| 368 |
+
# Gaussian operator
|
| 369 |
+
dog_image_cube = np.empty(image.shape + (k,), dtype=float_dtype)
|
| 370 |
+
gaussian_previous = gaussian(image, sigma=sigma_list[0], mode='reflect')
|
| 371 |
+
for i, s in enumerate(sigma_list[1:]):
|
| 372 |
+
gaussian_current = gaussian(image, sigma=s, mode='reflect')
|
| 373 |
+
dog_image_cube[..., i] = gaussian_previous - gaussian_current
|
| 374 |
+
gaussian_previous = gaussian_current
|
| 375 |
+
|
| 376 |
+
# normalization factor for consistency in DoG magnitude
|
| 377 |
+
sf = 1 / (sigma_ratio - 1)
|
| 378 |
+
dog_image_cube *= sf
|
| 379 |
+
|
| 380 |
+
exclude_border = _format_exclude_border(image.ndim, exclude_border)
|
| 381 |
+
local_maxima = peak_local_max(
|
| 382 |
+
dog_image_cube,
|
| 383 |
+
threshold_abs=threshold,
|
| 384 |
+
threshold_rel=threshold_rel,
|
| 385 |
+
exclude_border=exclude_border,
|
| 386 |
+
footprint=np.ones((3,) * (image.ndim + 1)),
|
| 387 |
+
)
|
| 388 |
+
|
| 389 |
+
# Catch no peaks
|
| 390 |
+
if local_maxima.size == 0:
|
| 391 |
+
return np.empty((0, image.ndim + (1 if scalar_sigma else image.ndim)))
|
| 392 |
+
|
| 393 |
+
# Convert local_maxima to float64
|
| 394 |
+
lm = local_maxima.astype(float_dtype)
|
| 395 |
+
|
| 396 |
+
# translate final column of lm, which contains the index of the
|
| 397 |
+
# sigma that produced the maximum intensity value, into the sigma
|
| 398 |
+
sigmas_of_peaks = sigma_list[local_maxima[:, -1]]
|
| 399 |
+
|
| 400 |
+
if scalar_sigma:
|
| 401 |
+
# select one sigma column, keeping dimension
|
| 402 |
+
sigmas_of_peaks = sigmas_of_peaks[:, 0:1]
|
| 403 |
+
|
| 404 |
+
# Remove sigma index and replace with sigmas
|
| 405 |
+
lm = np.hstack([lm[:, :-1], sigmas_of_peaks])
|
| 406 |
+
|
| 407 |
+
sigma_dim = sigmas_of_peaks.shape[1]
|
| 408 |
+
|
| 409 |
+
return _prune_blobs(lm, overlap, sigma_dim=sigma_dim)
|
| 410 |
+
|
| 411 |
+
|
| 412 |
+
def blob_log(
|
| 413 |
+
image,
|
| 414 |
+
min_sigma=1,
|
| 415 |
+
max_sigma=50,
|
| 416 |
+
num_sigma=10,
|
| 417 |
+
threshold=0.2,
|
| 418 |
+
overlap=0.5,
|
| 419 |
+
log_scale=False,
|
| 420 |
+
*,
|
| 421 |
+
threshold_rel=None,
|
| 422 |
+
exclude_border=False,
|
| 423 |
+
):
|
| 424 |
+
r"""Finds blobs in the given grayscale image.
|
| 425 |
+
|
| 426 |
+
Blobs are found using the Laplacian of Gaussian (LoG) method [1]_.
|
| 427 |
+
For each blob found, the method returns its coordinates and the standard
|
| 428 |
+
deviation of the Gaussian kernel that detected the blob.
|
| 429 |
+
|
| 430 |
+
Parameters
|
| 431 |
+
----------
|
| 432 |
+
image : ndarray
|
| 433 |
+
Input grayscale image, blobs are assumed to be light on dark
|
| 434 |
+
background (white on black).
|
| 435 |
+
min_sigma : scalar or sequence of scalars, optional
|
| 436 |
+
Minimum standard deviation for Gaussian kernel. Keep this value low to
|
| 437 |
+
detect smaller blobs. The standard deviation of the Gaussian kernel
|
| 438 |
+
is given either as a sequence for each axis, or as a single number, in
|
| 439 |
+
which case it is equal for all axes.
|
| 440 |
+
max_sigma : scalar or sequence of scalars, optional
|
| 441 |
+
The maximum standard deviation for Gaussian kernel. Keep this high to
|
| 442 |
+
detect larger blobs. The standard deviation of the Gaussian kernel
|
| 443 |
+
is given either as a sequence for each axis, or as a single number, in
|
| 444 |
+
which case it is equal for all axes.
|
| 445 |
+
num_sigma : int, optional
|
| 446 |
+
The number of evenly spaced values for standard deviation of the
|
| 447 |
+
Gaussian kernel to consider on the closed interval
|
| 448 |
+
``[min_sigma, max_sigma]``.
|
| 449 |
+
threshold : float or None, optional
|
| 450 |
+
The absolute lower bound for scale space maxima. Local maxima smaller
|
| 451 |
+
than `threshold` are ignored. Reduce this to detect blobs with lower
|
| 452 |
+
intensities. If `threshold_rel` is also specified, whichever threshold
|
| 453 |
+
is larger will be used. If None, `threshold_rel` is used instead.
|
| 454 |
+
overlap : float, optional
|
| 455 |
+
A value between 0 and 1. If the area of two blobs overlaps by a
|
| 456 |
+
fraction greater than `threshold`, the smaller blob is eliminated.
|
| 457 |
+
log_scale : bool, optional
|
| 458 |
+
If set intermediate values of standard deviations are interpolated
|
| 459 |
+
using a logarithmic scale to the base `10`. If not, linear
|
| 460 |
+
interpolation is used.
|
| 461 |
+
threshold_rel : float or None, optional
|
| 462 |
+
Minimum intensity of peaks, calculated as
|
| 463 |
+
``max(log_space) * threshold_rel``, where ``log_space`` refers to the
|
| 464 |
+
stack of Laplacian-of-Gaussian (LoG) images computed internally. This
|
| 465 |
+
should have a value between 0 and 1. If None, `threshold` is used
|
| 466 |
+
instead.
|
| 467 |
+
exclude_border : tuple of ints, int, or False, optional
|
| 468 |
+
If tuple of ints, the length of the tuple must match the input array's
|
| 469 |
+
dimensionality. Each element of the tuple will exclude peaks from
|
| 470 |
+
within `exclude_border`-pixels of the border of the image along that
|
| 471 |
+
dimension.
|
| 472 |
+
If nonzero int, `exclude_border` excludes peaks from within
|
| 473 |
+
`exclude_border`-pixels of the border of the image.
|
| 474 |
+
If zero or False, peaks are identified regardless of their
|
| 475 |
+
distance from the border.
|
| 476 |
+
|
| 477 |
+
Returns
|
| 478 |
+
-------
|
| 479 |
+
A : (n, image.ndim + sigma) ndarray
|
| 480 |
+
A 2d array with each row representing 2 coordinate values for a 2D
|
| 481 |
+
image, or 3 coordinate values for a 3D image, plus the sigma(s) used.
|
| 482 |
+
When a single sigma is passed, outputs are:
|
| 483 |
+
``(r, c, sigma)`` or ``(p, r, c, sigma)`` where ``(r, c)`` or
|
| 484 |
+
``(p, r, c)`` are coordinates of the blob and ``sigma`` is the standard
|
| 485 |
+
deviation of the Gaussian kernel which detected the blob. When an
|
| 486 |
+
anisotropic gaussian is used (sigmas per dimension), the detected sigma
|
| 487 |
+
is returned for each dimension.
|
| 488 |
+
|
| 489 |
+
References
|
| 490 |
+
----------
|
| 491 |
+
.. [1] https://en.wikipedia.org/wiki/Blob_detection#The_Laplacian_of_Gaussian
|
| 492 |
+
|
| 493 |
+
Examples
|
| 494 |
+
--------
|
| 495 |
+
>>> from skimage import data, feature, exposure
|
| 496 |
+
>>> img = data.coins()
|
| 497 |
+
>>> img = exposure.equalize_hist(img) # improves detection
|
| 498 |
+
>>> feature.blob_log(img, threshold = .3)
|
| 499 |
+
array([[124. , 336. , 11.88888889],
|
| 500 |
+
[198. , 155. , 11.88888889],
|
| 501 |
+
[194. , 213. , 17.33333333],
|
| 502 |
+
[121. , 272. , 17.33333333],
|
| 503 |
+
[263. , 244. , 17.33333333],
|
| 504 |
+
[194. , 276. , 17.33333333],
|
| 505 |
+
[266. , 115. , 11.88888889],
|
| 506 |
+
[128. , 154. , 11.88888889],
|
| 507 |
+
[260. , 174. , 17.33333333],
|
| 508 |
+
[198. , 103. , 11.88888889],
|
| 509 |
+
[126. , 208. , 11.88888889],
|
| 510 |
+
[127. , 102. , 11.88888889],
|
| 511 |
+
[263. , 302. , 17.33333333],
|
| 512 |
+
[197. , 44. , 11.88888889],
|
| 513 |
+
[185. , 344. , 17.33333333],
|
| 514 |
+
[126. , 46. , 11.88888889],
|
| 515 |
+
[113. , 323. , 1. ]])
|
| 516 |
+
|
| 517 |
+
Notes
|
| 518 |
+
-----
|
| 519 |
+
The radius of each blob is approximately :math:`\sqrt{2}\sigma` for
|
| 520 |
+
a 2-D image and :math:`\sqrt{3}\sigma` for a 3-D image.
|
| 521 |
+
"""
|
| 522 |
+
image = img_as_float(image)
|
| 523 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 524 |
+
image = image.astype(float_dtype, copy=False)
|
| 525 |
+
|
| 526 |
+
# if both min and max sigma are scalar, function returns only one sigma
|
| 527 |
+
scalar_sigma = True if np.isscalar(max_sigma) and np.isscalar(min_sigma) else False
|
| 528 |
+
|
| 529 |
+
# Gaussian filter requires that sequence-type sigmas have same
|
| 530 |
+
# dimensionality as image. This broadcasts scalar kernels
|
| 531 |
+
if np.isscalar(max_sigma):
|
| 532 |
+
max_sigma = np.full(image.ndim, max_sigma, dtype=float_dtype)
|
| 533 |
+
if np.isscalar(min_sigma):
|
| 534 |
+
min_sigma = np.full(image.ndim, min_sigma, dtype=float_dtype)
|
| 535 |
+
|
| 536 |
+
# Convert sequence types to array
|
| 537 |
+
min_sigma = np.asarray(min_sigma, dtype=float_dtype)
|
| 538 |
+
max_sigma = np.asarray(max_sigma, dtype=float_dtype)
|
| 539 |
+
|
| 540 |
+
if log_scale:
|
| 541 |
+
start = np.log10(min_sigma)
|
| 542 |
+
stop = np.log10(max_sigma)
|
| 543 |
+
sigma_list = np.logspace(start, stop, num_sigma)
|
| 544 |
+
else:
|
| 545 |
+
sigma_list = np.linspace(min_sigma, max_sigma, num_sigma)
|
| 546 |
+
|
| 547 |
+
# computing gaussian laplace
|
| 548 |
+
image_cube = np.empty(image.shape + (len(sigma_list),), dtype=float_dtype)
|
| 549 |
+
for i, s in enumerate(sigma_list):
|
| 550 |
+
# average s**2 provides scale invariance
|
| 551 |
+
image_cube[..., i] = -ndi.gaussian_laplace(image, s) * np.mean(s) ** 2
|
| 552 |
+
|
| 553 |
+
exclude_border = _format_exclude_border(image.ndim, exclude_border)
|
| 554 |
+
local_maxima = peak_local_max(
|
| 555 |
+
image_cube,
|
| 556 |
+
threshold_abs=threshold,
|
| 557 |
+
threshold_rel=threshold_rel,
|
| 558 |
+
exclude_border=exclude_border,
|
| 559 |
+
footprint=np.ones((3,) * (image.ndim + 1)),
|
| 560 |
+
)
|
| 561 |
+
|
| 562 |
+
# Catch no peaks
|
| 563 |
+
if local_maxima.size == 0:
|
| 564 |
+
return np.empty((0, image.ndim + (1 if scalar_sigma else image.ndim)))
|
| 565 |
+
|
| 566 |
+
# Convert local_maxima to float64
|
| 567 |
+
lm = local_maxima.astype(float_dtype)
|
| 568 |
+
|
| 569 |
+
# translate final column of lm, which contains the index of the
|
| 570 |
+
# sigma that produced the maximum intensity value, into the sigma
|
| 571 |
+
sigmas_of_peaks = sigma_list[local_maxima[:, -1]]
|
| 572 |
+
|
| 573 |
+
if scalar_sigma:
|
| 574 |
+
# select one sigma column, keeping dimension
|
| 575 |
+
sigmas_of_peaks = sigmas_of_peaks[:, 0:1]
|
| 576 |
+
|
| 577 |
+
# Remove sigma index and replace with sigmas
|
| 578 |
+
lm = np.hstack([lm[:, :-1], sigmas_of_peaks])
|
| 579 |
+
|
| 580 |
+
sigma_dim = sigmas_of_peaks.shape[1]
|
| 581 |
+
|
| 582 |
+
return _prune_blobs(lm, overlap, sigma_dim=sigma_dim)
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
def blob_doh(
|
| 586 |
+
image,
|
| 587 |
+
min_sigma=1,
|
| 588 |
+
max_sigma=30,
|
| 589 |
+
num_sigma=10,
|
| 590 |
+
threshold=0.01,
|
| 591 |
+
overlap=0.5,
|
| 592 |
+
log_scale=False,
|
| 593 |
+
*,
|
| 594 |
+
threshold_rel=None,
|
| 595 |
+
):
|
| 596 |
+
"""Finds blobs in the given grayscale image.
|
| 597 |
+
|
| 598 |
+
Blobs are found using the Determinant of Hessian method [1]_. For each blob
|
| 599 |
+
found, the method returns its coordinates and the standard deviation
|
| 600 |
+
of the Gaussian Kernel used for the Hessian matrix whose determinant
|
| 601 |
+
detected the blob. Determinant of Hessians is approximated using [2]_.
|
| 602 |
+
|
| 603 |
+
Parameters
|
| 604 |
+
----------
|
| 605 |
+
image : 2D ndarray
|
| 606 |
+
Input grayscale image. Blobs can either be light on dark or vice versa.
|
| 607 |
+
min_sigma : float, optional
|
| 608 |
+
The minimum standard deviation for Gaussian Kernel used to compute
|
| 609 |
+
Hessian matrix. Keep this value low to detect smaller blobs.
|
| 610 |
+
The standard deviation of the Gaussian kernel is given either as a
|
| 611 |
+
sequence for each axis, or as a single number, in which case it is
|
| 612 |
+
equal for all axes.
|
| 613 |
+
max_sigma : float, optional
|
| 614 |
+
The maximum standard deviation for Gaussian Kernel used to compute
|
| 615 |
+
Hessian matrix. Keep this value high to detect larger blobs.
|
| 616 |
+
The standard deviation of the Gaussian kernel is given either as a
|
| 617 |
+
sequence for each axis, or as a single number, in which case it is
|
| 618 |
+
equal for all axes.
|
| 619 |
+
num_sigma : int, optional
|
| 620 |
+
The number of evenly spaced values for standard deviation of the
|
| 621 |
+
Gaussian kernel to consider on the closed interval
|
| 622 |
+
``[min_sigma, max_sigma]``.
|
| 623 |
+
threshold : float or None, optional
|
| 624 |
+
The absolute lower bound for scale space maxima. Local maxima smaller
|
| 625 |
+
than `threshold` are ignored. Reduce this to detect blobs with lower
|
| 626 |
+
intensities. If `threshold_rel` is also specified, whichever threshold
|
| 627 |
+
is larger will be used. If None, `threshold_rel` is used instead.
|
| 628 |
+
overlap : float, optional
|
| 629 |
+
A value between 0 and 1. If the area of two blobs overlaps by a
|
| 630 |
+
fraction greater than `threshold`, the smaller blob is eliminated.
|
| 631 |
+
log_scale : bool, optional
|
| 632 |
+
If set intermediate values of standard deviations are interpolated
|
| 633 |
+
using a logarithmic scale to the base `10`. If not, linear
|
| 634 |
+
interpolation is used.
|
| 635 |
+
threshold_rel : float or None, optional
|
| 636 |
+
Minimum intensity of peaks, calculated as
|
| 637 |
+
``max(doh_space) * threshold_rel``, where ``doh_space`` refers to the
|
| 638 |
+
stack of Determinant-of-Hessian (DoH) images computed internally. This
|
| 639 |
+
should have a value between 0 and 1. If None, `threshold` is used
|
| 640 |
+
instead.
|
| 641 |
+
|
| 642 |
+
Returns
|
| 643 |
+
-------
|
| 644 |
+
A : (n, 3) ndarray
|
| 645 |
+
A 2d array with each row representing 3 values, ``(y,x,sigma)``
|
| 646 |
+
where ``(y,x)`` are coordinates of the blob and ``sigma`` is the
|
| 647 |
+
standard deviation of the Gaussian kernel of the Hessian Matrix whose
|
| 648 |
+
determinant detected the blob.
|
| 649 |
+
|
| 650 |
+
References
|
| 651 |
+
----------
|
| 652 |
+
.. [1] https://en.wikipedia.org/wiki/Blob_detection#The_determinant_of_the_Hessian
|
| 653 |
+
.. [2] Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool,
|
| 654 |
+
"SURF: Speeded Up Robust Features"
|
| 655 |
+
ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf
|
| 656 |
+
|
| 657 |
+
Examples
|
| 658 |
+
--------
|
| 659 |
+
>>> from skimage import data, feature
|
| 660 |
+
>>> img = data.coins()
|
| 661 |
+
>>> feature.blob_doh(img)
|
| 662 |
+
array([[197. , 153. , 20.33333333],
|
| 663 |
+
[124. , 336. , 20.33333333],
|
| 664 |
+
[126. , 153. , 20.33333333],
|
| 665 |
+
[195. , 100. , 23.55555556],
|
| 666 |
+
[192. , 212. , 23.55555556],
|
| 667 |
+
[121. , 271. , 30. ],
|
| 668 |
+
[126. , 101. , 20.33333333],
|
| 669 |
+
[193. , 275. , 23.55555556],
|
| 670 |
+
[123. , 205. , 20.33333333],
|
| 671 |
+
[270. , 363. , 30. ],
|
| 672 |
+
[265. , 113. , 23.55555556],
|
| 673 |
+
[262. , 243. , 23.55555556],
|
| 674 |
+
[185. , 348. , 30. ],
|
| 675 |
+
[156. , 302. , 30. ],
|
| 676 |
+
[123. , 44. , 23.55555556],
|
| 677 |
+
[260. , 173. , 30. ],
|
| 678 |
+
[197. , 44. , 20.33333333]])
|
| 679 |
+
|
| 680 |
+
Notes
|
| 681 |
+
-----
|
| 682 |
+
The radius of each blob is approximately `sigma`.
|
| 683 |
+
Computation of Determinant of Hessians is independent of the standard
|
| 684 |
+
deviation. Therefore detecting larger blobs won't take more time. In
|
| 685 |
+
methods line :py:meth:`blob_dog` and :py:meth:`blob_log` the computation
|
| 686 |
+
of Gaussians for larger `sigma` takes more time. The downside is that
|
| 687 |
+
this method can't be used for detecting blobs of radius less than `3px`
|
| 688 |
+
due to the box filters used in the approximation of Hessian Determinant.
|
| 689 |
+
"""
|
| 690 |
+
check_nD(image, 2)
|
| 691 |
+
|
| 692 |
+
image = img_as_float(image)
|
| 693 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 694 |
+
image = image.astype(float_dtype, copy=False)
|
| 695 |
+
|
| 696 |
+
image = integral_image(image)
|
| 697 |
+
|
| 698 |
+
if log_scale:
|
| 699 |
+
start, stop = math.log(min_sigma, 10), math.log(max_sigma, 10)
|
| 700 |
+
sigma_list = np.logspace(start, stop, num_sigma)
|
| 701 |
+
else:
|
| 702 |
+
sigma_list = np.linspace(min_sigma, max_sigma, num_sigma)
|
| 703 |
+
|
| 704 |
+
image_cube = np.empty(shape=image.shape + (len(sigma_list),), dtype=float_dtype)
|
| 705 |
+
for j, s in enumerate(sigma_list):
|
| 706 |
+
image_cube[..., j] = _hessian_matrix_det(image, s)
|
| 707 |
+
|
| 708 |
+
local_maxima = peak_local_max(
|
| 709 |
+
image_cube,
|
| 710 |
+
threshold_abs=threshold,
|
| 711 |
+
threshold_rel=threshold_rel,
|
| 712 |
+
exclude_border=False,
|
| 713 |
+
footprint=np.ones((3,) * image_cube.ndim),
|
| 714 |
+
)
|
| 715 |
+
|
| 716 |
+
# Catch no peaks
|
| 717 |
+
if local_maxima.size == 0:
|
| 718 |
+
return np.empty((0, 3))
|
| 719 |
+
# Convert local_maxima to float64
|
| 720 |
+
lm = local_maxima.astype(np.float64)
|
| 721 |
+
# Convert the last index to its corresponding scale value
|
| 722 |
+
lm[:, -1] = sigma_list[local_maxima[:, -1]]
|
| 723 |
+
return _prune_blobs(lm, overlap)
|
envs/kitoverlay/skimage/feature/brief.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import copy
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from packaging.version import Version
|
| 5 |
+
|
| 6 |
+
from .._shared.filters import gaussian
|
| 7 |
+
from .._shared.utils import check_nD
|
| 8 |
+
from .brief_cy import _brief_loop
|
| 9 |
+
from .util import (
|
| 10 |
+
DescriptorExtractor,
|
| 11 |
+
_mask_border_keypoints,
|
| 12 |
+
_prepare_grayscale_input_2D,
|
| 13 |
+
)
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
np2 = Version(np.__version__) >= Version('2')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class BRIEF(DescriptorExtractor):
|
| 20 |
+
"""BRIEF binary descriptor extractor.
|
| 21 |
+
|
| 22 |
+
BRIEF (Binary Robust Independent Elementary Features) is an efficient
|
| 23 |
+
feature point descriptor. It is highly discriminative even when using
|
| 24 |
+
relatively few bits and is computed using simple intensity difference
|
| 25 |
+
tests.
|
| 26 |
+
|
| 27 |
+
For each keypoint, intensity comparisons are carried out for a specifically
|
| 28 |
+
distributed number N of pixel-pairs resulting in a binary descriptor of
|
| 29 |
+
length N. For binary descriptors the Hamming distance can be used for
|
| 30 |
+
feature matching, which leads to lower computational cost in comparison to
|
| 31 |
+
the L2 norm.
|
| 32 |
+
|
| 33 |
+
Parameters
|
| 34 |
+
----------
|
| 35 |
+
descriptor_size : int, optional
|
| 36 |
+
Size of BRIEF descriptor for each keypoint. Sizes 128, 256 and 512
|
| 37 |
+
recommended by the authors. Default is 256.
|
| 38 |
+
patch_size : int, optional
|
| 39 |
+
Length of the two dimensional square patch sampling region around
|
| 40 |
+
the keypoints. Default is 49.
|
| 41 |
+
mode : {'normal', 'uniform'}, optional
|
| 42 |
+
Probability distribution for sampling location of decision pixel-pairs
|
| 43 |
+
around keypoints.
|
| 44 |
+
rng : {`numpy.random.Generator`, int}, optional
|
| 45 |
+
Pseudo-random number generator (RNG).
|
| 46 |
+
By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
|
| 47 |
+
If `rng` is an int, it is used to seed the generator.
|
| 48 |
+
|
| 49 |
+
The PRNG is used for the random sampling of the decision
|
| 50 |
+
pixel-pairs. From a square window with length `patch_size`,
|
| 51 |
+
pixel pairs are sampled using the `mode` parameter to build
|
| 52 |
+
the descriptors using intensity comparison.
|
| 53 |
+
|
| 54 |
+
For matching across images, the same `rng` should be used to construct
|
| 55 |
+
descriptors. To facilitate this:
|
| 56 |
+
|
| 57 |
+
(a) `rng` defaults to 1
|
| 58 |
+
(b) Subsequent calls of the ``extract`` method will use the same rng/seed.
|
| 59 |
+
sigma : float, optional
|
| 60 |
+
Standard deviation of the Gaussian low-pass filter applied to the image
|
| 61 |
+
to alleviate noise sensitivity, which is strongly recommended to obtain
|
| 62 |
+
discriminative and good descriptors.
|
| 63 |
+
|
| 64 |
+
Attributes
|
| 65 |
+
----------
|
| 66 |
+
descriptors : (Q, `descriptor_size`) array of dtype bool
|
| 67 |
+
2D ndarray of binary descriptors of size `descriptor_size` for Q
|
| 68 |
+
keypoints after filtering out border keypoints with value at an
|
| 69 |
+
index ``(i, j)`` either being ``True`` or ``False`` representing
|
| 70 |
+
the outcome of the intensity comparison for i-th keypoint on j-th
|
| 71 |
+
decision pixel-pair. It is ``Q == np.sum(mask)``.
|
| 72 |
+
mask : (N,) array of dtype bool
|
| 73 |
+
Mask indicating whether a keypoint has been filtered out
|
| 74 |
+
(``False``) or is described in the `descriptors` array (``True``).
|
| 75 |
+
|
| 76 |
+
Examples
|
| 77 |
+
--------
|
| 78 |
+
>>> from skimage.feature import (corner_harris, corner_peaks, BRIEF,
|
| 79 |
+
... match_descriptors)
|
| 80 |
+
>>> import numpy as np
|
| 81 |
+
>>> square1 = np.zeros((8, 8), dtype=np.int32)
|
| 82 |
+
>>> square1[2:6, 2:6] = 1
|
| 83 |
+
>>> square1
|
| 84 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0],
|
| 85 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 86 |
+
[0, 0, 1, 1, 1, 1, 0, 0],
|
| 87 |
+
[0, 0, 1, 1, 1, 1, 0, 0],
|
| 88 |
+
[0, 0, 1, 1, 1, 1, 0, 0],
|
| 89 |
+
[0, 0, 1, 1, 1, 1, 0, 0],
|
| 90 |
+
[0, 0, 0, 0, 0, 0, 0, 0],
|
| 91 |
+
[0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
|
| 92 |
+
>>> square2 = np.zeros((9, 9), dtype=np.int32)
|
| 93 |
+
>>> square2[2:7, 2:7] = 1
|
| 94 |
+
>>> square2
|
| 95 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 96 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 97 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 98 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 99 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 100 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 101 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 102 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 103 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=int32)
|
| 104 |
+
>>> keypoints1 = corner_peaks(corner_harris(square1), min_distance=1)
|
| 105 |
+
>>> keypoints2 = corner_peaks(corner_harris(square2), min_distance=1)
|
| 106 |
+
>>> extractor = BRIEF(patch_size=5)
|
| 107 |
+
>>> extractor.extract(square1, keypoints1)
|
| 108 |
+
>>> descriptors1 = extractor.descriptors
|
| 109 |
+
>>> extractor.extract(square2, keypoints2)
|
| 110 |
+
>>> descriptors2 = extractor.descriptors
|
| 111 |
+
>>> matches = match_descriptors(descriptors1, descriptors2)
|
| 112 |
+
>>> matches
|
| 113 |
+
array([[0, 0],
|
| 114 |
+
[1, 1],
|
| 115 |
+
[2, 2],
|
| 116 |
+
[3, 3]])
|
| 117 |
+
>>> keypoints1[matches[:, 0]]
|
| 118 |
+
array([[2, 2],
|
| 119 |
+
[2, 5],
|
| 120 |
+
[5, 2],
|
| 121 |
+
[5, 5]])
|
| 122 |
+
>>> keypoints2[matches[:, 1]]
|
| 123 |
+
array([[2, 2],
|
| 124 |
+
[2, 6],
|
| 125 |
+
[6, 2],
|
| 126 |
+
[6, 6]])
|
| 127 |
+
|
| 128 |
+
"""
|
| 129 |
+
|
| 130 |
+
def __init__(
|
| 131 |
+
self, descriptor_size=256, patch_size=49, mode='normal', sigma=1, rng=1
|
| 132 |
+
):
|
| 133 |
+
mode = mode.lower()
|
| 134 |
+
if mode not in ('normal', 'uniform'):
|
| 135 |
+
raise ValueError("`mode` must be 'normal' or 'uniform'.")
|
| 136 |
+
|
| 137 |
+
self.descriptor_size = descriptor_size
|
| 138 |
+
self.patch_size = patch_size
|
| 139 |
+
self.mode = mode
|
| 140 |
+
self.sigma = sigma
|
| 141 |
+
|
| 142 |
+
if isinstance(rng, np.random.Generator):
|
| 143 |
+
# Spawn an independent RNG from parent RNG provided by the user.
|
| 144 |
+
# This is necessary so that we can safely deepcopy the RNG.
|
| 145 |
+
# See https://github.com/scikit-learn/scikit-learn/issues/16988#issuecomment-1518037853
|
| 146 |
+
bg = rng._bit_generator
|
| 147 |
+
ss = bg._seed_seq
|
| 148 |
+
(child_ss,) = ss.spawn(1)
|
| 149 |
+
self.rng = np.random.Generator(type(bg)(child_ss))
|
| 150 |
+
elif rng is None:
|
| 151 |
+
self.rng = np.random.default_rng(np.random.SeedSequence())
|
| 152 |
+
else:
|
| 153 |
+
self.rng = np.random.default_rng(rng)
|
| 154 |
+
|
| 155 |
+
self.descriptors = None
|
| 156 |
+
self.mask = None
|
| 157 |
+
|
| 158 |
+
def extract(self, image, keypoints):
|
| 159 |
+
"""Extract BRIEF binary descriptors for given keypoints in image.
|
| 160 |
+
|
| 161 |
+
Parameters
|
| 162 |
+
----------
|
| 163 |
+
image : 2D array
|
| 164 |
+
Input image.
|
| 165 |
+
keypoints : (N, 2) array
|
| 166 |
+
Keypoint coordinates as ``(row, col)``.
|
| 167 |
+
|
| 168 |
+
"""
|
| 169 |
+
check_nD(image, 2)
|
| 170 |
+
|
| 171 |
+
# Copy RNG so we can repeatedly call extract with the same random values
|
| 172 |
+
rng = copy.deepcopy(self.rng)
|
| 173 |
+
|
| 174 |
+
image = _prepare_grayscale_input_2D(image)
|
| 175 |
+
|
| 176 |
+
# Gaussian low-pass filtering to alleviate noise sensitivity
|
| 177 |
+
image = np.ascontiguousarray(gaussian(image, sigma=self.sigma, mode='reflect'))
|
| 178 |
+
|
| 179 |
+
# Sampling pairs of decision pixels in patch_size x patch_size window
|
| 180 |
+
desc_size = self.descriptor_size
|
| 181 |
+
patch_size = self.patch_size
|
| 182 |
+
if self.mode == 'normal':
|
| 183 |
+
samples = (patch_size / 5.0) * rng.standard_normal(desc_size * 8)
|
| 184 |
+
samples = np.array(samples, dtype=np.int32)
|
| 185 |
+
samples = samples[
|
| 186 |
+
(samples < (patch_size // 2)) & (samples > -(patch_size - 2) // 2)
|
| 187 |
+
]
|
| 188 |
+
|
| 189 |
+
pos1 = samples[: desc_size * 2].reshape(desc_size, 2)
|
| 190 |
+
pos2 = samples[desc_size * 2 : desc_size * 4].reshape(desc_size, 2)
|
| 191 |
+
elif self.mode == 'uniform':
|
| 192 |
+
samples = rng.integers(
|
| 193 |
+
-(patch_size - 2) // 2, (patch_size // 2) + 1, (desc_size * 2, 2)
|
| 194 |
+
)
|
| 195 |
+
samples = np.array(samples, dtype=np.int32)
|
| 196 |
+
pos1, pos2 = np.split(samples, 2)
|
| 197 |
+
|
| 198 |
+
pos1 = np.ascontiguousarray(pos1)
|
| 199 |
+
pos2 = np.ascontiguousarray(pos2)
|
| 200 |
+
|
| 201 |
+
# Removing keypoints that are within (patch_size / 2) distance from the
|
| 202 |
+
# image border
|
| 203 |
+
self.mask = _mask_border_keypoints(image.shape, keypoints, patch_size // 2)
|
| 204 |
+
|
| 205 |
+
keypoints = np.array(
|
| 206 |
+
keypoints[self.mask, :],
|
| 207 |
+
dtype=np.int64,
|
| 208 |
+
order='C',
|
| 209 |
+
copy=None if np2 else False,
|
| 210 |
+
)
|
| 211 |
+
|
| 212 |
+
self.descriptors = np.zeros(
|
| 213 |
+
(keypoints.shape[0], desc_size), dtype=bool, order='C'
|
| 214 |
+
)
|
| 215 |
+
|
| 216 |
+
_brief_loop(image, self.descriptors.view(np.uint8), keypoints, pos1, pos2)
|
envs/kitoverlay/skimage/feature/censure.py
ADDED
|
@@ -0,0 +1,346 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.ndimage import maximum_filter, minimum_filter, convolve
|
| 3 |
+
|
| 4 |
+
from ..transform import integral_image
|
| 5 |
+
from .corner import structure_tensor
|
| 6 |
+
from ..morphology import octagon, star
|
| 7 |
+
from .censure_cy import _censure_dob_loop
|
| 8 |
+
from ..feature.util import (
|
| 9 |
+
FeatureDetector,
|
| 10 |
+
_prepare_grayscale_input_2D,
|
| 11 |
+
_mask_border_keypoints,
|
| 12 |
+
)
|
| 13 |
+
from .._shared.utils import check_nD
|
| 14 |
+
|
| 15 |
+
# The paper(Reference [1]) mentions the sizes of the Octagon shaped filter
|
| 16 |
+
# kernel for the first seven scales only. The sizes of the later scales
|
| 17 |
+
# have been extrapolated based on the following statement in the paper.
|
| 18 |
+
# "These octagons scale linearly and were experimentally chosen to correspond
|
| 19 |
+
# to the seven DOBs described in the previous section."
|
| 20 |
+
OCTAGON_OUTER_SHAPE = [
|
| 21 |
+
(5, 2),
|
| 22 |
+
(5, 3),
|
| 23 |
+
(7, 3),
|
| 24 |
+
(9, 4),
|
| 25 |
+
(9, 7),
|
| 26 |
+
(13, 7),
|
| 27 |
+
(15, 10),
|
| 28 |
+
(15, 11),
|
| 29 |
+
(15, 12),
|
| 30 |
+
(17, 13),
|
| 31 |
+
(17, 14),
|
| 32 |
+
]
|
| 33 |
+
OCTAGON_INNER_SHAPE = [
|
| 34 |
+
(3, 0),
|
| 35 |
+
(3, 1),
|
| 36 |
+
(3, 2),
|
| 37 |
+
(5, 2),
|
| 38 |
+
(5, 3),
|
| 39 |
+
(5, 4),
|
| 40 |
+
(5, 5),
|
| 41 |
+
(7, 5),
|
| 42 |
+
(7, 6),
|
| 43 |
+
(9, 6),
|
| 44 |
+
(9, 7),
|
| 45 |
+
]
|
| 46 |
+
|
| 47 |
+
# The sizes for the STAR shaped filter kernel for different scales have been
|
| 48 |
+
# taken from the OpenCV implementation.
|
| 49 |
+
STAR_SHAPE = [1, 2, 3, 4, 6, 8, 11, 12, 16, 22, 23, 32, 45, 46, 64, 90, 128]
|
| 50 |
+
STAR_FILTER_SHAPE = [
|
| 51 |
+
(1, 0),
|
| 52 |
+
(3, 1),
|
| 53 |
+
(4, 2),
|
| 54 |
+
(5, 3),
|
| 55 |
+
(7, 4),
|
| 56 |
+
(8, 5),
|
| 57 |
+
(9, 6),
|
| 58 |
+
(11, 8),
|
| 59 |
+
(13, 10),
|
| 60 |
+
(14, 11),
|
| 61 |
+
(15, 12),
|
| 62 |
+
(16, 14),
|
| 63 |
+
]
|
| 64 |
+
|
| 65 |
+
|
| 66 |
+
def _filter_image(image, min_scale, max_scale, mode):
|
| 67 |
+
response = np.zeros(
|
| 68 |
+
(image.shape[0], image.shape[1], max_scale - min_scale + 1), dtype=np.float64
|
| 69 |
+
)
|
| 70 |
+
|
| 71 |
+
if mode == 'dob':
|
| 72 |
+
# make response[:, :, i] contiguous memory block
|
| 73 |
+
item_size = response.itemsize
|
| 74 |
+
response = np.lib.stride_tricks.as_strided(
|
| 75 |
+
response,
|
| 76 |
+
strides=(
|
| 77 |
+
item_size * response.shape[1],
|
| 78 |
+
item_size,
|
| 79 |
+
item_size * response.shape[0] * response.shape[1],
|
| 80 |
+
),
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
integral_img = integral_image(image)
|
| 84 |
+
|
| 85 |
+
for i in range(max_scale - min_scale + 1):
|
| 86 |
+
n = min_scale + i
|
| 87 |
+
|
| 88 |
+
# Constant multipliers for the outer region and the inner region
|
| 89 |
+
# of the bi-level filters with the constraint of keeping the
|
| 90 |
+
# DC bias 0.
|
| 91 |
+
inner_weight = 1.0 / (2 * n + 1) ** 2
|
| 92 |
+
outer_weight = 1.0 / (12 * n**2 + 4 * n)
|
| 93 |
+
|
| 94 |
+
_censure_dob_loop(
|
| 95 |
+
n, integral_img, response[:, :, i], inner_weight, outer_weight
|
| 96 |
+
)
|
| 97 |
+
|
| 98 |
+
# NOTE : For the Octagon shaped filter, we implemented and evaluated the
|
| 99 |
+
# slanted integral image based image filtering but the performance was
|
| 100 |
+
# more or less equal to image filtering using
|
| 101 |
+
# scipy.ndimage.filters.convolve(). Hence we have decided to use the
|
| 102 |
+
# later for a much cleaner implementation.
|
| 103 |
+
elif mode == 'octagon':
|
| 104 |
+
# TODO : Decide the shapes of Octagon filters for scales > 7
|
| 105 |
+
|
| 106 |
+
for i in range(max_scale - min_scale + 1):
|
| 107 |
+
mo, no = OCTAGON_OUTER_SHAPE[min_scale + i - 1]
|
| 108 |
+
mi, ni = OCTAGON_INNER_SHAPE[min_scale + i - 1]
|
| 109 |
+
response[:, :, i] = convolve(image, _octagon_kernel(mo, no, mi, ni))
|
| 110 |
+
|
| 111 |
+
elif mode == 'star':
|
| 112 |
+
for i in range(max_scale - min_scale + 1):
|
| 113 |
+
m = STAR_SHAPE[STAR_FILTER_SHAPE[min_scale + i - 1][0]]
|
| 114 |
+
n = STAR_SHAPE[STAR_FILTER_SHAPE[min_scale + i - 1][1]]
|
| 115 |
+
response[:, :, i] = convolve(image, _star_kernel(m, n))
|
| 116 |
+
|
| 117 |
+
return response
|
| 118 |
+
|
| 119 |
+
|
| 120 |
+
def _octagon_kernel(mo, no, mi, ni):
|
| 121 |
+
outer = (mo + 2 * no) ** 2 - 2 * no * (no + 1)
|
| 122 |
+
inner = (mi + 2 * ni) ** 2 - 2 * ni * (ni + 1)
|
| 123 |
+
outer_weight = 1.0 / (outer - inner)
|
| 124 |
+
inner_weight = 1.0 / inner
|
| 125 |
+
c = ((mo + 2 * no) - (mi + 2 * ni)) // 2
|
| 126 |
+
outer_oct = octagon(mo, no)
|
| 127 |
+
inner_oct = np.zeros((mo + 2 * no, mo + 2 * no))
|
| 128 |
+
inner_oct[c:-c, c:-c] = octagon(mi, ni)
|
| 129 |
+
bfilter = outer_weight * outer_oct - (outer_weight + inner_weight) * inner_oct
|
| 130 |
+
return bfilter
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
def _star_kernel(m, n):
|
| 134 |
+
c = m + m // 2 - n - n // 2
|
| 135 |
+
outer_star = star(m)
|
| 136 |
+
inner_star = np.zeros_like(outer_star)
|
| 137 |
+
inner_star[c:-c, c:-c] = star(n)
|
| 138 |
+
outer_weight = 1.0 / (np.sum(outer_star - inner_star))
|
| 139 |
+
inner_weight = 1.0 / np.sum(inner_star)
|
| 140 |
+
bfilter = outer_weight * outer_star - (outer_weight + inner_weight) * inner_star
|
| 141 |
+
return bfilter
|
| 142 |
+
|
| 143 |
+
|
| 144 |
+
def _suppress_lines(feature_mask, image, sigma, line_threshold):
|
| 145 |
+
Arr, Arc, Acc = structure_tensor(image, sigma, order='rc')
|
| 146 |
+
feature_mask[(Arr + Acc) ** 2 > line_threshold * (Arr * Acc - Arc**2)] = False
|
| 147 |
+
|
| 148 |
+
|
| 149 |
+
class CENSURE(FeatureDetector):
|
| 150 |
+
"""CENSURE keypoint detector.
|
| 151 |
+
|
| 152 |
+
min_scale : int, optional
|
| 153 |
+
Minimum scale to extract keypoints from.
|
| 154 |
+
max_scale : int, optional
|
| 155 |
+
Maximum scale to extract keypoints from. The keypoints will be
|
| 156 |
+
extracted from all the scales except the first and the last i.e.
|
| 157 |
+
from the scales in the range [min_scale + 1, max_scale - 1]. The filter
|
| 158 |
+
sizes for different scales is such that the two adjacent scales
|
| 159 |
+
comprise of an octave.
|
| 160 |
+
mode : {'DoB', 'Octagon', 'STAR'}, optional
|
| 161 |
+
Type of bi-level filter used to get the scales of the input image.
|
| 162 |
+
Possible values are 'DoB', 'Octagon' and 'STAR'. The three modes
|
| 163 |
+
represent the shape of the bi-level filters i.e. box(square), octagon
|
| 164 |
+
and star respectively. For instance, a bi-level octagon filter consists
|
| 165 |
+
of a smaller inner octagon and a larger outer octagon with the filter
|
| 166 |
+
weights being uniformly negative in both the inner octagon while
|
| 167 |
+
uniformly positive in the difference region. Use STAR and Octagon for
|
| 168 |
+
better features and DoB for better performance.
|
| 169 |
+
non_max_threshold : float, optional
|
| 170 |
+
Threshold value used to suppress maximas and minimas with a weak
|
| 171 |
+
magnitude response obtained after Non-Maximal Suppression.
|
| 172 |
+
line_threshold : float, optional
|
| 173 |
+
Threshold for rejecting interest points which have ratio of principal
|
| 174 |
+
curvatures greater than this value.
|
| 175 |
+
|
| 176 |
+
Attributes
|
| 177 |
+
----------
|
| 178 |
+
keypoints : (N, 2) array
|
| 179 |
+
Keypoint coordinates as ``(row, col)``.
|
| 180 |
+
scales : (N,) array
|
| 181 |
+
Corresponding scales.
|
| 182 |
+
|
| 183 |
+
References
|
| 184 |
+
----------
|
| 185 |
+
.. [1] Motilal Agrawal, Kurt Konolige and Morten Rufus Blas
|
| 186 |
+
"CENSURE: Center Surround Extremas for Realtime Feature
|
| 187 |
+
Detection and Matching",
|
| 188 |
+
https://link.springer.com/chapter/10.1007/978-3-540-88693-8_8
|
| 189 |
+
:DOI:`10.1007/978-3-540-88693-8_8`
|
| 190 |
+
|
| 191 |
+
.. [2] Adam Schmidt, Marek Kraft, Michal Fularz and Zuzanna Domagala
|
| 192 |
+
"Comparative Assessment of Point Feature Detectors and
|
| 193 |
+
Descriptors in the Context of Robot Navigation"
|
| 194 |
+
http://yadda.icm.edu.pl/yadda/element/bwmeta1.element.baztech-268aaf28-0faf-4872-a4df-7e2e61cb364c/c/Schmidt_comparative.pdf
|
| 195 |
+
:DOI:`10.1.1.465.1117`
|
| 196 |
+
|
| 197 |
+
Examples
|
| 198 |
+
--------
|
| 199 |
+
>>> from skimage.data import astronaut
|
| 200 |
+
>>> from skimage.color import rgb2gray
|
| 201 |
+
>>> from skimage.feature import CENSURE
|
| 202 |
+
>>> img = rgb2gray(astronaut()[100:300, 100:300])
|
| 203 |
+
>>> censure = CENSURE()
|
| 204 |
+
>>> censure.detect(img)
|
| 205 |
+
>>> censure.keypoints
|
| 206 |
+
array([[ 4, 148],
|
| 207 |
+
[ 12, 73],
|
| 208 |
+
[ 21, 176],
|
| 209 |
+
[ 91, 22],
|
| 210 |
+
[ 93, 56],
|
| 211 |
+
[ 94, 22],
|
| 212 |
+
[ 95, 54],
|
| 213 |
+
[100, 51],
|
| 214 |
+
[103, 51],
|
| 215 |
+
[106, 67],
|
| 216 |
+
[108, 15],
|
| 217 |
+
[117, 20],
|
| 218 |
+
[122, 60],
|
| 219 |
+
[125, 37],
|
| 220 |
+
[129, 37],
|
| 221 |
+
[133, 76],
|
| 222 |
+
[145, 44],
|
| 223 |
+
[146, 94],
|
| 224 |
+
[150, 114],
|
| 225 |
+
[153, 33],
|
| 226 |
+
[154, 156],
|
| 227 |
+
[155, 151],
|
| 228 |
+
[184, 63]])
|
| 229 |
+
>>> censure.scales
|
| 230 |
+
array([2, 6, 6, 2, 4, 3, 2, 3, 2, 6, 3, 2, 2, 3, 2, 2, 2, 3, 2, 2, 4, 2,
|
| 231 |
+
2])
|
| 232 |
+
|
| 233 |
+
"""
|
| 234 |
+
|
| 235 |
+
def __init__(
|
| 236 |
+
self,
|
| 237 |
+
min_scale=1,
|
| 238 |
+
max_scale=7,
|
| 239 |
+
mode='DoB',
|
| 240 |
+
non_max_threshold=0.15,
|
| 241 |
+
line_threshold=10,
|
| 242 |
+
):
|
| 243 |
+
mode = mode.lower()
|
| 244 |
+
if mode not in ('dob', 'octagon', 'star'):
|
| 245 |
+
raise ValueError("`mode` must be one of 'DoB', 'Octagon', 'STAR'.")
|
| 246 |
+
|
| 247 |
+
if min_scale < 1 or max_scale < 1 or max_scale - min_scale < 2:
|
| 248 |
+
raise ValueError(
|
| 249 |
+
'The scales must be >= 1 and the number of ' 'scales should be >= 3.'
|
| 250 |
+
)
|
| 251 |
+
|
| 252 |
+
self.min_scale = min_scale
|
| 253 |
+
self.max_scale = max_scale
|
| 254 |
+
self.mode = mode
|
| 255 |
+
self.non_max_threshold = non_max_threshold
|
| 256 |
+
self.line_threshold = line_threshold
|
| 257 |
+
|
| 258 |
+
self.keypoints = None
|
| 259 |
+
self.scales = None
|
| 260 |
+
|
| 261 |
+
def detect(self, image):
|
| 262 |
+
"""Detect CENSURE keypoints along with the corresponding scale.
|
| 263 |
+
|
| 264 |
+
Parameters
|
| 265 |
+
----------
|
| 266 |
+
image : 2D ndarray
|
| 267 |
+
Input image.
|
| 268 |
+
|
| 269 |
+
"""
|
| 270 |
+
|
| 271 |
+
# (1) First we generate the required scales on the input grayscale
|
| 272 |
+
# image using a bi-level filter and stack them up in `filter_response`.
|
| 273 |
+
|
| 274 |
+
# (2) We then perform Non-Maximal suppression in 3 x 3 x 3 window on
|
| 275 |
+
# the filter_response to suppress points that are neither minima or
|
| 276 |
+
# maxima in 3 x 3 x 3 neighborhood. We obtain a boolean ndarray
|
| 277 |
+
# `feature_mask` containing all the minimas and maximas in
|
| 278 |
+
# `filter_response` as True.
|
| 279 |
+
# (3) Then we suppress all the points in the `feature_mask` for which
|
| 280 |
+
# the corresponding point in the image at a particular scale has the
|
| 281 |
+
# ratio of principal curvatures greater than `line_threshold`.
|
| 282 |
+
# (4) Finally, we remove the border keypoints and return the keypoints
|
| 283 |
+
# along with its corresponding scale.
|
| 284 |
+
|
| 285 |
+
check_nD(image, 2)
|
| 286 |
+
|
| 287 |
+
num_scales = self.max_scale - self.min_scale
|
| 288 |
+
|
| 289 |
+
image = np.ascontiguousarray(_prepare_grayscale_input_2D(image))
|
| 290 |
+
|
| 291 |
+
# Generating all the scales
|
| 292 |
+
filter_response = _filter_image(
|
| 293 |
+
image, self.min_scale, self.max_scale, self.mode
|
| 294 |
+
)
|
| 295 |
+
|
| 296 |
+
# Suppressing points that are neither minima or maxima in their
|
| 297 |
+
# 3 x 3 x 3 neighborhood to zero
|
| 298 |
+
minimas = minimum_filter(filter_response, (3, 3, 3)) == filter_response
|
| 299 |
+
maximas = maximum_filter(filter_response, (3, 3, 3)) == filter_response
|
| 300 |
+
|
| 301 |
+
feature_mask = minimas | maximas
|
| 302 |
+
feature_mask[filter_response < self.non_max_threshold] = False
|
| 303 |
+
|
| 304 |
+
for i in range(1, num_scales):
|
| 305 |
+
# sigma = (window_size - 1) / 6.0, so the window covers > 99% of
|
| 306 |
+
# the kernel's distribution
|
| 307 |
+
# window_size = 7 + 2 * (min_scale - 1 + i)
|
| 308 |
+
# Hence sigma = 1 + (min_scale - 1 + i)/ 3.0
|
| 309 |
+
_suppress_lines(
|
| 310 |
+
feature_mask[:, :, i],
|
| 311 |
+
image,
|
| 312 |
+
(1 + (self.min_scale + i - 1) / 3.0),
|
| 313 |
+
self.line_threshold,
|
| 314 |
+
)
|
| 315 |
+
|
| 316 |
+
rows, cols, scales = np.nonzero(feature_mask[..., 1:num_scales])
|
| 317 |
+
keypoints = np.column_stack([rows, cols])
|
| 318 |
+
scales = scales + self.min_scale + 1
|
| 319 |
+
|
| 320 |
+
if self.mode == 'dob':
|
| 321 |
+
self.keypoints = keypoints
|
| 322 |
+
self.scales = scales
|
| 323 |
+
return
|
| 324 |
+
|
| 325 |
+
cumulative_mask = np.zeros(keypoints.shape[0], dtype=bool)
|
| 326 |
+
|
| 327 |
+
if self.mode == 'octagon':
|
| 328 |
+
for i in range(self.min_scale + 1, self.max_scale):
|
| 329 |
+
c = (OCTAGON_OUTER_SHAPE[i - 1][0] - 1) // 2 + OCTAGON_OUTER_SHAPE[
|
| 330 |
+
i - 1
|
| 331 |
+
][1]
|
| 332 |
+
cumulative_mask |= _mask_border_keypoints(image.shape, keypoints, c) & (
|
| 333 |
+
scales == i
|
| 334 |
+
)
|
| 335 |
+
elif self.mode == 'star':
|
| 336 |
+
for i in range(self.min_scale + 1, self.max_scale):
|
| 337 |
+
c = (
|
| 338 |
+
STAR_SHAPE[STAR_FILTER_SHAPE[i - 1][0]]
|
| 339 |
+
+ STAR_SHAPE[STAR_FILTER_SHAPE[i - 1][0]] // 2
|
| 340 |
+
)
|
| 341 |
+
cumulative_mask |= _mask_border_keypoints(image.shape, keypoints, c) & (
|
| 342 |
+
scales == i
|
| 343 |
+
)
|
| 344 |
+
|
| 345 |
+
self.keypoints = keypoints[cumulative_mask]
|
| 346 |
+
self.scales = scales[cumulative_mask]
|
envs/kitoverlay/skimage/feature/corner.py
ADDED
|
@@ -0,0 +1,1355 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import functools
|
| 2 |
+
import math
|
| 3 |
+
from itertools import combinations_with_replacement
|
| 4 |
+
|
| 5 |
+
import numpy as np
|
| 6 |
+
from scipy import ndimage as ndi
|
| 7 |
+
from scipy import spatial, stats
|
| 8 |
+
|
| 9 |
+
from .._shared.filters import gaussian
|
| 10 |
+
from .._shared.utils import _supported_float_type, safe_as_int, warn
|
| 11 |
+
from ..transform import integral_image
|
| 12 |
+
from ..util import img_as_float
|
| 13 |
+
from ._hessian_det_appx import _hessian_matrix_det
|
| 14 |
+
from .corner_cy import _corner_fast, _corner_moravec, _corner_orientations
|
| 15 |
+
from .peak import peak_local_max
|
| 16 |
+
from .util import _prepare_grayscale_input_2D, _prepare_grayscale_input_nD
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
def _compute_derivatives(image, mode='constant', cval=0):
|
| 20 |
+
"""Compute derivatives in axis directions using the Sobel operator.
|
| 21 |
+
|
| 22 |
+
Parameters
|
| 23 |
+
----------
|
| 24 |
+
image : ndarray
|
| 25 |
+
Input image.
|
| 26 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 27 |
+
How to handle values outside the image borders.
|
| 28 |
+
cval : float, optional
|
| 29 |
+
Used in conjunction with mode 'constant', the value outside
|
| 30 |
+
the image boundaries.
|
| 31 |
+
|
| 32 |
+
Returns
|
| 33 |
+
-------
|
| 34 |
+
derivatives : list of ndarray
|
| 35 |
+
Derivatives in each axis direction.
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
+
|
| 39 |
+
derivatives = [
|
| 40 |
+
ndi.sobel(image, axis=i, mode=mode, cval=cval) for i in range(image.ndim)
|
| 41 |
+
]
|
| 42 |
+
|
| 43 |
+
return derivatives
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def structure_tensor(image, sigma=1, mode='constant', cval=0, order='rc'):
|
| 47 |
+
"""Compute structure tensor using sum of squared differences.
|
| 48 |
+
|
| 49 |
+
The (2-dimensional) structure tensor A is defined as::
|
| 50 |
+
|
| 51 |
+
A = [Arr Arc]
|
| 52 |
+
[Arc Acc]
|
| 53 |
+
|
| 54 |
+
which is approximated by the weighted sum of squared differences in a local
|
| 55 |
+
window around each pixel in the image. This formula can be extended to a
|
| 56 |
+
larger number of dimensions (see [1]_).
|
| 57 |
+
|
| 58 |
+
Parameters
|
| 59 |
+
----------
|
| 60 |
+
image : ndarray
|
| 61 |
+
Input image.
|
| 62 |
+
sigma : float or array-like of float, optional
|
| 63 |
+
Standard deviation used for the Gaussian kernel, which is used as a
|
| 64 |
+
weighting function for the local summation of squared differences.
|
| 65 |
+
If sigma is an iterable, its length must be equal to `image.ndim` and
|
| 66 |
+
each element is used for the Gaussian kernel applied along its
|
| 67 |
+
respective axis.
|
| 68 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 69 |
+
How to handle values outside the image borders.
|
| 70 |
+
cval : float, optional
|
| 71 |
+
Used in conjunction with mode 'constant', the value outside
|
| 72 |
+
the image boundaries.
|
| 73 |
+
order : {'rc', 'xy'}, optional
|
| 74 |
+
NOTE: 'xy' is only an option for 2D images, higher dimensions must
|
| 75 |
+
always use 'rc' order. This parameter allows for the use of reverse or
|
| 76 |
+
forward order of the image axes in gradient computation. 'rc' indicates
|
| 77 |
+
the use of the first axis initially (Arr, Arc, Acc), whilst 'xy'
|
| 78 |
+
indicates the usage of the last axis initially (Axx, Axy, Ayy).
|
| 79 |
+
|
| 80 |
+
Returns
|
| 81 |
+
-------
|
| 82 |
+
A_elems : list of ndarray
|
| 83 |
+
Upper-diagonal elements of the structure tensor for each pixel in the
|
| 84 |
+
input image.
|
| 85 |
+
|
| 86 |
+
Examples
|
| 87 |
+
--------
|
| 88 |
+
>>> from skimage.feature import structure_tensor
|
| 89 |
+
>>> square = np.zeros((5, 5))
|
| 90 |
+
>>> square[2, 2] = 1
|
| 91 |
+
>>> Arr, Arc, Acc = structure_tensor(square, sigma=0.1, order='rc')
|
| 92 |
+
>>> Acc
|
| 93 |
+
array([[0., 0., 0., 0., 0.],
|
| 94 |
+
[0., 1., 0., 1., 0.],
|
| 95 |
+
[0., 4., 0., 4., 0.],
|
| 96 |
+
[0., 1., 0., 1., 0.],
|
| 97 |
+
[0., 0., 0., 0., 0.]])
|
| 98 |
+
|
| 99 |
+
See also
|
| 100 |
+
--------
|
| 101 |
+
structure_tensor_eigenvalues
|
| 102 |
+
|
| 103 |
+
References
|
| 104 |
+
----------
|
| 105 |
+
.. [1] https://en.wikipedia.org/wiki/Structure_tensor
|
| 106 |
+
"""
|
| 107 |
+
if order == 'xy' and image.ndim > 2:
|
| 108 |
+
raise ValueError('Only "rc" order is supported for dim > 2.')
|
| 109 |
+
|
| 110 |
+
if order not in ['rc', 'xy']:
|
| 111 |
+
raise ValueError(f'order {order} is invalid. Must be either "rc" or "xy"')
|
| 112 |
+
|
| 113 |
+
if not np.isscalar(sigma):
|
| 114 |
+
sigma = tuple(sigma)
|
| 115 |
+
if len(sigma) != image.ndim:
|
| 116 |
+
raise ValueError('sigma must have as many elements as image ' 'has axes')
|
| 117 |
+
|
| 118 |
+
image = _prepare_grayscale_input_nD(image)
|
| 119 |
+
|
| 120 |
+
derivatives = _compute_derivatives(image, mode=mode, cval=cval)
|
| 121 |
+
|
| 122 |
+
if order == 'xy':
|
| 123 |
+
derivatives = reversed(derivatives)
|
| 124 |
+
|
| 125 |
+
# structure tensor
|
| 126 |
+
A_elems = [
|
| 127 |
+
gaussian(der0 * der1, sigma=sigma, mode=mode, cval=cval)
|
| 128 |
+
for der0, der1 in combinations_with_replacement(derivatives, 2)
|
| 129 |
+
]
|
| 130 |
+
|
| 131 |
+
return A_elems
|
| 132 |
+
|
| 133 |
+
|
| 134 |
+
def _hessian_matrix_with_gaussian(image, sigma=1, mode='reflect', cval=0, order='rc'):
|
| 135 |
+
"""Compute the Hessian via convolutions with Gaussian derivatives.
|
| 136 |
+
|
| 137 |
+
In 2D, the Hessian matrix is defined as:
|
| 138 |
+
H = [Hrr Hrc]
|
| 139 |
+
[Hrc Hcc]
|
| 140 |
+
|
| 141 |
+
which is computed by convolving the image with the second derivatives
|
| 142 |
+
of the Gaussian kernel in the respective r- and c-directions.
|
| 143 |
+
|
| 144 |
+
The implementation here also supports n-dimensional data.
|
| 145 |
+
|
| 146 |
+
Parameters
|
| 147 |
+
----------
|
| 148 |
+
image : ndarray
|
| 149 |
+
Input image.
|
| 150 |
+
sigma : float or sequence of float, optional
|
| 151 |
+
Standard deviation used for the Gaussian kernel, which sets the
|
| 152 |
+
amount of smoothing in terms of pixel-distances. It is
|
| 153 |
+
advised to not choose a sigma much less than 1.0, otherwise
|
| 154 |
+
aliasing artifacts may occur.
|
| 155 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 156 |
+
How to handle values outside the image borders.
|
| 157 |
+
cval : float, optional
|
| 158 |
+
Used in conjunction with mode 'constant', the value outside
|
| 159 |
+
the image boundaries.
|
| 160 |
+
order : {'rc', 'xy'}, optional
|
| 161 |
+
This parameter allows for the use of reverse or forward order of
|
| 162 |
+
the image axes in gradient computation. 'rc' indicates the use of
|
| 163 |
+
the first axis initially (Hrr, Hrc, Hcc), whilst 'xy' indicates the
|
| 164 |
+
usage of the last axis initially (Hxx, Hxy, Hyy)
|
| 165 |
+
|
| 166 |
+
Returns
|
| 167 |
+
-------
|
| 168 |
+
H_elems : list of ndarray
|
| 169 |
+
Upper-diagonal elements of the hessian matrix for each pixel in the
|
| 170 |
+
input image. In 2D, this will be a three element list containing [Hrr,
|
| 171 |
+
Hrc, Hcc]. In nD, the list will contain ``(n**2 + n) / 2`` arrays.
|
| 172 |
+
|
| 173 |
+
"""
|
| 174 |
+
image = img_as_float(image)
|
| 175 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 176 |
+
image = image.astype(float_dtype, copy=False)
|
| 177 |
+
if image.ndim > 2 and order == "xy":
|
| 178 |
+
raise ValueError("order='xy' is only supported for 2D images.")
|
| 179 |
+
if order not in ["rc", "xy"]:
|
| 180 |
+
raise ValueError(f"unrecognized order: {order}")
|
| 181 |
+
|
| 182 |
+
if np.isscalar(sigma):
|
| 183 |
+
sigma = (sigma,) * image.ndim
|
| 184 |
+
|
| 185 |
+
# This function uses `scipy.ndimage.gaussian_filter` with the order
|
| 186 |
+
# argument to compute convolutions. For example, specifying
|
| 187 |
+
# ``order=[1, 0]`` would apply convolution with a first-order derivative of
|
| 188 |
+
# the Gaussian along the first axis and simple Gaussian smoothing along the
|
| 189 |
+
# second.
|
| 190 |
+
|
| 191 |
+
# For small sigma, the SciPy Gaussian filter suffers from aliasing and edge
|
| 192 |
+
# artifacts, given that the filter will approximate a sinc or sinc
|
| 193 |
+
# derivative which only goes to 0 very slowly (order 1/n**2). Thus, we use
|
| 194 |
+
# a much larger truncate value to reduce any edge artifacts.
|
| 195 |
+
truncate = 8 if all(s > 1 for s in sigma) else 100
|
| 196 |
+
sq1_2 = 1 / math.sqrt(2)
|
| 197 |
+
sigma_scaled = tuple(sq1_2 * s for s in sigma)
|
| 198 |
+
common_kwargs = dict(sigma=sigma_scaled, mode=mode, cval=cval, truncate=truncate)
|
| 199 |
+
gaussian_ = functools.partial(ndi.gaussian_filter, **common_kwargs)
|
| 200 |
+
|
| 201 |
+
# Apply two successive first order Gaussian derivative operations, as
|
| 202 |
+
# detailed in:
|
| 203 |
+
# https://dsp.stackexchange.com/questions/78280/are-scipy-second-order-gaussian-derivatives-correct
|
| 204 |
+
|
| 205 |
+
# 1.) First order along one axis while smoothing (order=0) along the other
|
| 206 |
+
ndim = image.ndim
|
| 207 |
+
|
| 208 |
+
# orders in 2D = ([1, 0], [0, 1])
|
| 209 |
+
# in 3D = ([1, 0, 0], [0, 1, 0], [0, 0, 1])
|
| 210 |
+
# etc.
|
| 211 |
+
orders = tuple([0] * d + [1] + [0] * (ndim - d - 1) for d in range(ndim))
|
| 212 |
+
gradients = [gaussian_(image, order=orders[d]) for d in range(ndim)]
|
| 213 |
+
|
| 214 |
+
# 2.) apply the derivative along another axis as well
|
| 215 |
+
axes = range(ndim)
|
| 216 |
+
if order == 'xy':
|
| 217 |
+
axes = reversed(axes)
|
| 218 |
+
H_elems = [
|
| 219 |
+
gaussian_(gradients[ax0], order=orders[ax1])
|
| 220 |
+
for ax0, ax1 in combinations_with_replacement(axes, 2)
|
| 221 |
+
]
|
| 222 |
+
return H_elems
|
| 223 |
+
|
| 224 |
+
|
| 225 |
+
def hessian_matrix(
|
| 226 |
+
image, sigma=1, mode='constant', cval=0, order='rc', use_gaussian_derivatives=None
|
| 227 |
+
):
|
| 228 |
+
r"""Compute the Hessian matrix.
|
| 229 |
+
|
| 230 |
+
In 2D, the Hessian matrix is defined as::
|
| 231 |
+
|
| 232 |
+
H = [Hrr Hrc]
|
| 233 |
+
[Hrc Hcc]
|
| 234 |
+
|
| 235 |
+
which is computed by convolving the image with the second derivatives
|
| 236 |
+
of the Gaussian kernel in the respective r- and c-directions.
|
| 237 |
+
|
| 238 |
+
The implementation here also supports n-dimensional data.
|
| 239 |
+
|
| 240 |
+
Parameters
|
| 241 |
+
----------
|
| 242 |
+
image : ndarray
|
| 243 |
+
Input image.
|
| 244 |
+
sigma : float
|
| 245 |
+
Standard deviation used for the Gaussian kernel, which is used as
|
| 246 |
+
weighting function for the auto-correlation matrix.
|
| 247 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 248 |
+
How to handle values outside the image borders.
|
| 249 |
+
cval : float, optional
|
| 250 |
+
Used in conjunction with mode 'constant', the value outside
|
| 251 |
+
the image boundaries.
|
| 252 |
+
order : {'rc', 'xy'}, optional
|
| 253 |
+
For 2D images, this parameter allows for the use of reverse or forward
|
| 254 |
+
order of the image axes in gradient computation. 'rc' indicates the use
|
| 255 |
+
of the first axis initially (Hrr, Hrc, Hcc), whilst 'xy' indicates the
|
| 256 |
+
usage of the last axis initially (Hxx, Hxy, Hyy). Images with higher
|
| 257 |
+
dimension must always use 'rc' order.
|
| 258 |
+
use_gaussian_derivatives : bool, optional
|
| 259 |
+
Indicates whether the Hessian is computed by convolving with Gaussian
|
| 260 |
+
derivatives, or by a simple finite-difference operation.
|
| 261 |
+
|
| 262 |
+
Returns
|
| 263 |
+
-------
|
| 264 |
+
H_elems : list of ndarray
|
| 265 |
+
Upper-diagonal elements of the hessian matrix for each pixel in the
|
| 266 |
+
input image. In 2D, this will be a three element list containing [Hrr,
|
| 267 |
+
Hrc, Hcc]. In nD, the list will contain ``(n**2 + n) / 2`` arrays.
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
Notes
|
| 271 |
+
-----
|
| 272 |
+
The distributive property of derivatives and convolutions allows us to
|
| 273 |
+
restate the derivative of an image, I, smoothed with a Gaussian kernel, G,
|
| 274 |
+
as the convolution of the image with the derivative of G.
|
| 275 |
+
|
| 276 |
+
.. math::
|
| 277 |
+
|
| 278 |
+
\frac{\partial }{\partial x_i}(I * G) =
|
| 279 |
+
I * \left( \frac{\partial }{\partial x_i} G \right)
|
| 280 |
+
|
| 281 |
+
When ``use_gaussian_derivatives`` is ``True``, this property is used to
|
| 282 |
+
compute the second order derivatives that make up the Hessian matrix.
|
| 283 |
+
|
| 284 |
+
When ``use_gaussian_derivatives`` is ``False``, simple finite differences
|
| 285 |
+
on a Gaussian-smoothed image are used instead.
|
| 286 |
+
|
| 287 |
+
Examples
|
| 288 |
+
--------
|
| 289 |
+
>>> from skimage.feature import hessian_matrix
|
| 290 |
+
>>> square = np.zeros((5, 5))
|
| 291 |
+
>>> square[2, 2] = 4
|
| 292 |
+
>>> Hrr, Hrc, Hcc = hessian_matrix(square, sigma=0.1, order='rc',
|
| 293 |
+
... use_gaussian_derivatives=False)
|
| 294 |
+
>>> Hrc
|
| 295 |
+
array([[ 0., 0., 0., 0., 0.],
|
| 296 |
+
[ 0., 1., 0., -1., 0.],
|
| 297 |
+
[ 0., 0., 0., 0., 0.],
|
| 298 |
+
[ 0., -1., 0., 1., 0.],
|
| 299 |
+
[ 0., 0., 0., 0., 0.]])
|
| 300 |
+
|
| 301 |
+
"""
|
| 302 |
+
|
| 303 |
+
image = img_as_float(image)
|
| 304 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 305 |
+
image = image.astype(float_dtype, copy=False)
|
| 306 |
+
if image.ndim > 2 and order == "xy":
|
| 307 |
+
raise ValueError("order='xy' is only supported for 2D images.")
|
| 308 |
+
if order not in ["rc", "xy"]:
|
| 309 |
+
raise ValueError(f"unrecognized order: {order}")
|
| 310 |
+
|
| 311 |
+
if use_gaussian_derivatives is None:
|
| 312 |
+
use_gaussian_derivatives = False
|
| 313 |
+
warn(
|
| 314 |
+
"use_gaussian_derivatives currently defaults to False, but will "
|
| 315 |
+
"change to True in a future version. Please specify this "
|
| 316 |
+
"argument explicitly to maintain the current behavior",
|
| 317 |
+
category=FutureWarning,
|
| 318 |
+
stacklevel=2,
|
| 319 |
+
)
|
| 320 |
+
|
| 321 |
+
if use_gaussian_derivatives:
|
| 322 |
+
return _hessian_matrix_with_gaussian(
|
| 323 |
+
image, sigma=sigma, mode=mode, cval=cval, order=order
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
gaussian_filtered = gaussian(image, sigma=sigma, mode=mode, cval=cval)
|
| 327 |
+
|
| 328 |
+
gradients = np.gradient(gaussian_filtered)
|
| 329 |
+
axes = range(image.ndim)
|
| 330 |
+
|
| 331 |
+
if order == 'xy':
|
| 332 |
+
axes = reversed(axes)
|
| 333 |
+
|
| 334 |
+
H_elems = [
|
| 335 |
+
np.gradient(gradients[ax0], axis=ax1)
|
| 336 |
+
for ax0, ax1 in combinations_with_replacement(axes, 2)
|
| 337 |
+
]
|
| 338 |
+
return H_elems
|
| 339 |
+
|
| 340 |
+
|
| 341 |
+
def hessian_matrix_det(image, sigma=1, approximate=True):
|
| 342 |
+
"""Compute the approximate Hessian Determinant over an image.
|
| 343 |
+
|
| 344 |
+
The 2D approximate method uses box filters over integral images to
|
| 345 |
+
compute the approximate Hessian Determinant.
|
| 346 |
+
|
| 347 |
+
Parameters
|
| 348 |
+
----------
|
| 349 |
+
image : ndarray
|
| 350 |
+
The image over which to compute the Hessian Determinant.
|
| 351 |
+
sigma : float, optional
|
| 352 |
+
Standard deviation of the Gaussian kernel used for the Hessian
|
| 353 |
+
matrix.
|
| 354 |
+
approximate : bool, optional
|
| 355 |
+
If ``True`` and the image is 2D, use a much faster approximate
|
| 356 |
+
computation. This argument has no effect on 3D and higher images.
|
| 357 |
+
|
| 358 |
+
Returns
|
| 359 |
+
-------
|
| 360 |
+
out : array
|
| 361 |
+
The array of the Determinant of Hessians.
|
| 362 |
+
|
| 363 |
+
References
|
| 364 |
+
----------
|
| 365 |
+
.. [1] Herbert Bay, Andreas Ess, Tinne Tuytelaars, Luc Van Gool,
|
| 366 |
+
"SURF: Speeded Up Robust Features"
|
| 367 |
+
ftp://ftp.vision.ee.ethz.ch/publications/articles/eth_biwi_00517.pdf
|
| 368 |
+
|
| 369 |
+
Notes
|
| 370 |
+
-----
|
| 371 |
+
For 2D images when ``approximate=True``, the running time of this method
|
| 372 |
+
only depends on size of the image. It is independent of `sigma` as one
|
| 373 |
+
would expect. The downside is that the result for `sigma` less than `3`
|
| 374 |
+
is not accurate, i.e., not similar to the result obtained if someone
|
| 375 |
+
computed the Hessian and took its determinant.
|
| 376 |
+
"""
|
| 377 |
+
image = img_as_float(image)
|
| 378 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 379 |
+
image = image.astype(float_dtype, copy=False)
|
| 380 |
+
if image.ndim == 2 and approximate:
|
| 381 |
+
integral = integral_image(image)
|
| 382 |
+
return np.array(_hessian_matrix_det(integral, sigma))
|
| 383 |
+
else: # slower brute-force implementation for nD images
|
| 384 |
+
hessian_mat_array = _symmetric_image(
|
| 385 |
+
hessian_matrix(image, sigma, use_gaussian_derivatives=False)
|
| 386 |
+
)
|
| 387 |
+
return np.linalg.det(hessian_mat_array)
|
| 388 |
+
|
| 389 |
+
|
| 390 |
+
def _symmetric_compute_eigenvalues(S_elems):
|
| 391 |
+
"""Compute eigenvalues from the upper-diagonal entries of a symmetric
|
| 392 |
+
matrix.
|
| 393 |
+
|
| 394 |
+
Parameters
|
| 395 |
+
----------
|
| 396 |
+
S_elems : list of ndarray
|
| 397 |
+
The upper-diagonal elements of the matrix, as returned by
|
| 398 |
+
`hessian_matrix` or `structure_tensor`.
|
| 399 |
+
|
| 400 |
+
Returns
|
| 401 |
+
-------
|
| 402 |
+
eigs : ndarray
|
| 403 |
+
The eigenvalues of the matrix, in decreasing order. The eigenvalues are
|
| 404 |
+
the leading dimension. That is, ``eigs[i, j, k]`` contains the
|
| 405 |
+
ith-largest eigenvalue at position (j, k).
|
| 406 |
+
"""
|
| 407 |
+
|
| 408 |
+
if len(S_elems) == 3: # Fast explicit formulas for 2D.
|
| 409 |
+
M00, M01, M11 = S_elems
|
| 410 |
+
eigs = np.empty((2, *M00.shape), M00.dtype)
|
| 411 |
+
eigs[:] = (M00 + M11) / 2
|
| 412 |
+
hsqrtdet = np.sqrt(M01**2 + ((M00 - M11) / 2) ** 2)
|
| 413 |
+
eigs[0] += hsqrtdet
|
| 414 |
+
eigs[1] -= hsqrtdet
|
| 415 |
+
return eigs
|
| 416 |
+
else:
|
| 417 |
+
matrices = _symmetric_image(S_elems)
|
| 418 |
+
# eigvalsh returns eigenvalues in increasing order. We want decreasing
|
| 419 |
+
eigs = np.linalg.eigvalsh(matrices)[..., ::-1]
|
| 420 |
+
leading_axes = tuple(range(eigs.ndim - 1))
|
| 421 |
+
return np.transpose(eigs, (eigs.ndim - 1,) + leading_axes)
|
| 422 |
+
|
| 423 |
+
|
| 424 |
+
def _symmetric_image(S_elems):
|
| 425 |
+
"""Convert the upper-diagonal elements of a matrix to the full
|
| 426 |
+
symmetric matrix.
|
| 427 |
+
|
| 428 |
+
Parameters
|
| 429 |
+
----------
|
| 430 |
+
S_elems : list of array
|
| 431 |
+
The upper-diagonal elements of the matrix, as returned by
|
| 432 |
+
`hessian_matrix` or `structure_tensor`.
|
| 433 |
+
|
| 434 |
+
Returns
|
| 435 |
+
-------
|
| 436 |
+
image : array
|
| 437 |
+
An array of shape ``(M, N[, ...], image.ndim, image.ndim)``,
|
| 438 |
+
containing the matrix corresponding to each coordinate.
|
| 439 |
+
"""
|
| 440 |
+
image = S_elems[0]
|
| 441 |
+
symmetric_image = np.zeros(
|
| 442 |
+
image.shape + (image.ndim, image.ndim), dtype=S_elems[0].dtype
|
| 443 |
+
)
|
| 444 |
+
for idx, (row, col) in enumerate(
|
| 445 |
+
combinations_with_replacement(range(image.ndim), 2)
|
| 446 |
+
):
|
| 447 |
+
symmetric_image[..., row, col] = S_elems[idx]
|
| 448 |
+
symmetric_image[..., col, row] = S_elems[idx]
|
| 449 |
+
return symmetric_image
|
| 450 |
+
|
| 451 |
+
|
| 452 |
+
def structure_tensor_eigenvalues(A_elems):
|
| 453 |
+
"""Compute eigenvalues of structure tensor.
|
| 454 |
+
|
| 455 |
+
Parameters
|
| 456 |
+
----------
|
| 457 |
+
A_elems : list of ndarray
|
| 458 |
+
The upper-diagonal elements of the structure tensor, as returned
|
| 459 |
+
by `structure_tensor`.
|
| 460 |
+
|
| 461 |
+
Returns
|
| 462 |
+
-------
|
| 463 |
+
ndarray
|
| 464 |
+
The eigenvalues of the structure tensor, in decreasing order. The
|
| 465 |
+
eigenvalues are the leading dimension. That is, the coordinate
|
| 466 |
+
[i, j, k] corresponds to the ith-largest eigenvalue at position (j, k).
|
| 467 |
+
|
| 468 |
+
Examples
|
| 469 |
+
--------
|
| 470 |
+
>>> from skimage.feature import structure_tensor
|
| 471 |
+
>>> from skimage.feature import structure_tensor_eigenvalues
|
| 472 |
+
>>> square = np.zeros((5, 5))
|
| 473 |
+
>>> square[2, 2] = 1
|
| 474 |
+
>>> A_elems = structure_tensor(square, sigma=0.1, order='rc')
|
| 475 |
+
>>> structure_tensor_eigenvalues(A_elems)[0]
|
| 476 |
+
array([[0., 0., 0., 0., 0.],
|
| 477 |
+
[0., 2., 4., 2., 0.],
|
| 478 |
+
[0., 4., 0., 4., 0.],
|
| 479 |
+
[0., 2., 4., 2., 0.],
|
| 480 |
+
[0., 0., 0., 0., 0.]])
|
| 481 |
+
|
| 482 |
+
See also
|
| 483 |
+
--------
|
| 484 |
+
structure_tensor
|
| 485 |
+
"""
|
| 486 |
+
return _symmetric_compute_eigenvalues(A_elems)
|
| 487 |
+
|
| 488 |
+
|
| 489 |
+
def hessian_matrix_eigvals(H_elems):
|
| 490 |
+
"""Compute eigenvalues of Hessian matrix.
|
| 491 |
+
|
| 492 |
+
Parameters
|
| 493 |
+
----------
|
| 494 |
+
H_elems : list of ndarray
|
| 495 |
+
The upper-diagonal elements of the Hessian matrix, as returned
|
| 496 |
+
by `hessian_matrix`.
|
| 497 |
+
|
| 498 |
+
Returns
|
| 499 |
+
-------
|
| 500 |
+
eigs : ndarray
|
| 501 |
+
The eigenvalues of the Hessian matrix, in decreasing order. The
|
| 502 |
+
eigenvalues are the leading dimension. That is, ``eigs[i, j, k]``
|
| 503 |
+
contains the ith-largest eigenvalue at position (j, k).
|
| 504 |
+
|
| 505 |
+
Examples
|
| 506 |
+
--------
|
| 507 |
+
>>> from skimage.feature import hessian_matrix, hessian_matrix_eigvals
|
| 508 |
+
>>> square = np.zeros((5, 5))
|
| 509 |
+
>>> square[2, 2] = 4
|
| 510 |
+
>>> H_elems = hessian_matrix(square, sigma=0.1, order='rc',
|
| 511 |
+
... use_gaussian_derivatives=False)
|
| 512 |
+
>>> hessian_matrix_eigvals(H_elems)[0]
|
| 513 |
+
array([[ 0., 0., 2., 0., 0.],
|
| 514 |
+
[ 0., 1., 0., 1., 0.],
|
| 515 |
+
[ 2., 0., -2., 0., 2.],
|
| 516 |
+
[ 0., 1., 0., 1., 0.],
|
| 517 |
+
[ 0., 0., 2., 0., 0.]])
|
| 518 |
+
"""
|
| 519 |
+
return _symmetric_compute_eigenvalues(H_elems)
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def shape_index(image, sigma=1, mode='constant', cval=0):
|
| 523 |
+
"""Compute the shape index.
|
| 524 |
+
|
| 525 |
+
The shape index, as defined by Koenderink & van Doorn [1]_, is a
|
| 526 |
+
single valued measure of local curvature, assuming the image as a 3D plane
|
| 527 |
+
with intensities representing heights.
|
| 528 |
+
|
| 529 |
+
It is derived from the eigenvalues of the Hessian, and its
|
| 530 |
+
value ranges from -1 to 1 (and is undefined (=NaN) in *flat* regions),
|
| 531 |
+
with following ranges representing following shapes:
|
| 532 |
+
|
| 533 |
+
.. table:: Ranges of the shape index and corresponding shapes.
|
| 534 |
+
|
| 535 |
+
=================== =============
|
| 536 |
+
Interval (s in ...) Shape
|
| 537 |
+
=================== =============
|
| 538 |
+
[ -1, -7/8) Spherical cup
|
| 539 |
+
[-7/8, -5/8) Through
|
| 540 |
+
[-5/8, -3/8) Rut
|
| 541 |
+
[-3/8, -1/8) Saddle rut
|
| 542 |
+
[-1/8, +1/8) Saddle
|
| 543 |
+
[+1/8, +3/8) Saddle ridge
|
| 544 |
+
[+3/8, +5/8) Ridge
|
| 545 |
+
[+5/8, +7/8) Dome
|
| 546 |
+
[+7/8, +1] Spherical cap
|
| 547 |
+
=================== =============
|
| 548 |
+
|
| 549 |
+
Parameters
|
| 550 |
+
----------
|
| 551 |
+
image : (M, N) ndarray
|
| 552 |
+
Input image.
|
| 553 |
+
sigma : float, optional
|
| 554 |
+
Standard deviation used for the Gaussian kernel, which is used for
|
| 555 |
+
smoothing the input data before Hessian eigen value calculation.
|
| 556 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 557 |
+
How to handle values outside the image borders
|
| 558 |
+
cval : float, optional
|
| 559 |
+
Used in conjunction with mode 'constant', the value outside
|
| 560 |
+
the image boundaries.
|
| 561 |
+
|
| 562 |
+
Returns
|
| 563 |
+
-------
|
| 564 |
+
s : ndarray
|
| 565 |
+
Shape index
|
| 566 |
+
|
| 567 |
+
References
|
| 568 |
+
----------
|
| 569 |
+
.. [1] Koenderink, J. J. & van Doorn, A. J.,
|
| 570 |
+
"Surface shape and curvature scales",
|
| 571 |
+
Image and Vision Computing, 1992, 10, 557-564.
|
| 572 |
+
:DOI:`10.1016/0262-8856(92)90076-F`
|
| 573 |
+
|
| 574 |
+
Examples
|
| 575 |
+
--------
|
| 576 |
+
>>> from skimage.feature import shape_index
|
| 577 |
+
>>> square = np.zeros((5, 5))
|
| 578 |
+
>>> square[2, 2] = 4
|
| 579 |
+
>>> s = shape_index(square, sigma=0.1)
|
| 580 |
+
>>> s
|
| 581 |
+
array([[ nan, nan, -0.5, nan, nan],
|
| 582 |
+
[ nan, -0. , nan, -0. , nan],
|
| 583 |
+
[-0.5, nan, -1. , nan, -0.5],
|
| 584 |
+
[ nan, -0. , nan, -0. , nan],
|
| 585 |
+
[ nan, nan, -0.5, nan, nan]])
|
| 586 |
+
"""
|
| 587 |
+
|
| 588 |
+
H = hessian_matrix(
|
| 589 |
+
image,
|
| 590 |
+
sigma=sigma,
|
| 591 |
+
mode=mode,
|
| 592 |
+
cval=cval,
|
| 593 |
+
order='rc',
|
| 594 |
+
use_gaussian_derivatives=False,
|
| 595 |
+
)
|
| 596 |
+
l1, l2 = hessian_matrix_eigvals(H)
|
| 597 |
+
|
| 598 |
+
# don't warn on divide by 0 as occurs in the docstring example
|
| 599 |
+
with np.errstate(divide='ignore', invalid='ignore'):
|
| 600 |
+
return (2.0 / np.pi) * np.arctan((l2 + l1) / (l2 - l1))
|
| 601 |
+
|
| 602 |
+
|
| 603 |
+
def corner_kitchen_rosenfeld(image, mode='constant', cval=0):
|
| 604 |
+
"""Compute Kitchen and Rosenfeld corner measure response image.
|
| 605 |
+
|
| 606 |
+
The corner measure is calculated as follows::
|
| 607 |
+
|
| 608 |
+
(imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy)
|
| 609 |
+
/ (imx**2 + imy**2)
|
| 610 |
+
|
| 611 |
+
Where imx and imy are the first and imxx, imxy, imyy the second
|
| 612 |
+
derivatives.
|
| 613 |
+
|
| 614 |
+
Parameters
|
| 615 |
+
----------
|
| 616 |
+
image : (M, N) ndarray
|
| 617 |
+
Input image.
|
| 618 |
+
mode : {'constant', 'reflect', 'wrap', 'nearest', 'mirror'}, optional
|
| 619 |
+
How to handle values outside the image borders.
|
| 620 |
+
cval : float, optional
|
| 621 |
+
Used in conjunction with mode 'constant', the value outside
|
| 622 |
+
the image boundaries.
|
| 623 |
+
|
| 624 |
+
Returns
|
| 625 |
+
-------
|
| 626 |
+
response : ndarray
|
| 627 |
+
Kitchen and Rosenfeld response image.
|
| 628 |
+
|
| 629 |
+
References
|
| 630 |
+
----------
|
| 631 |
+
.. [1] Kitchen, L., & Rosenfeld, A. (1982). Gray-level corner detection.
|
| 632 |
+
Pattern recognition letters, 1(2), 95-102.
|
| 633 |
+
:DOI:`10.1016/0167-8655(82)90020-4`
|
| 634 |
+
"""
|
| 635 |
+
|
| 636 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 637 |
+
image = image.astype(float_dtype, copy=False)
|
| 638 |
+
|
| 639 |
+
imy, imx = _compute_derivatives(image, mode=mode, cval=cval)
|
| 640 |
+
imxy, imxx = _compute_derivatives(imx, mode=mode, cval=cval)
|
| 641 |
+
imyy, imyx = _compute_derivatives(imy, mode=mode, cval=cval)
|
| 642 |
+
|
| 643 |
+
numerator = imxx * imy**2 + imyy * imx**2 - 2 * imxy * imx * imy
|
| 644 |
+
denominator = imx**2 + imy**2
|
| 645 |
+
|
| 646 |
+
response = np.zeros_like(image, dtype=float_dtype)
|
| 647 |
+
|
| 648 |
+
mask = denominator != 0
|
| 649 |
+
response[mask] = numerator[mask] / denominator[mask]
|
| 650 |
+
|
| 651 |
+
return response
|
| 652 |
+
|
| 653 |
+
|
| 654 |
+
def corner_harris(image, method='k', k=0.05, eps=1e-6, sigma=1):
|
| 655 |
+
"""Compute Harris corner measure response image.
|
| 656 |
+
|
| 657 |
+
This corner detector uses information from the auto-correlation matrix A::
|
| 658 |
+
|
| 659 |
+
A = [(imx**2) (imx*imy)] = [Axx Axy]
|
| 660 |
+
[(imx*imy) (imy**2)] [Axy Ayy]
|
| 661 |
+
|
| 662 |
+
Where imx and imy are first derivatives, averaged with a gaussian filter.
|
| 663 |
+
The corner measure is then defined as::
|
| 664 |
+
|
| 665 |
+
det(A) - k * trace(A)**2
|
| 666 |
+
|
| 667 |
+
or::
|
| 668 |
+
|
| 669 |
+
2 * det(A) / (trace(A) + eps)
|
| 670 |
+
|
| 671 |
+
Parameters
|
| 672 |
+
----------
|
| 673 |
+
image : (M, N) ndarray
|
| 674 |
+
Input image.
|
| 675 |
+
method : {'k', 'eps'}, optional
|
| 676 |
+
Method to compute the response image from the auto-correlation matrix.
|
| 677 |
+
k : float, optional
|
| 678 |
+
Sensitivity factor to separate corners from edges, typically in range
|
| 679 |
+
`[0, 0.2]`. Small values of k result in detection of sharp corners.
|
| 680 |
+
eps : float, optional
|
| 681 |
+
Normalisation factor (Noble's corner measure).
|
| 682 |
+
sigma : float, optional
|
| 683 |
+
Standard deviation used for the Gaussian kernel, which is used as
|
| 684 |
+
weighting function for the auto-correlation matrix.
|
| 685 |
+
|
| 686 |
+
Returns
|
| 687 |
+
-------
|
| 688 |
+
response : ndarray
|
| 689 |
+
Harris response image.
|
| 690 |
+
|
| 691 |
+
References
|
| 692 |
+
----------
|
| 693 |
+
.. [1] https://en.wikipedia.org/wiki/Corner_detection
|
| 694 |
+
|
| 695 |
+
Examples
|
| 696 |
+
--------
|
| 697 |
+
>>> from skimage.feature import corner_harris, corner_peaks
|
| 698 |
+
>>> square = np.zeros([10, 10])
|
| 699 |
+
>>> square[2:8, 2:8] = 1
|
| 700 |
+
>>> square.astype(int)
|
| 701 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 702 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 703 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 704 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 705 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 706 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 707 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 708 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 709 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 710 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 711 |
+
>>> corner_peaks(corner_harris(square), min_distance=1)
|
| 712 |
+
array([[2, 2],
|
| 713 |
+
[2, 7],
|
| 714 |
+
[7, 2],
|
| 715 |
+
[7, 7]])
|
| 716 |
+
|
| 717 |
+
"""
|
| 718 |
+
|
| 719 |
+
Arr, Arc, Acc = structure_tensor(image, sigma, order='rc')
|
| 720 |
+
|
| 721 |
+
# determinant
|
| 722 |
+
detA = Arr * Acc - Arc**2
|
| 723 |
+
# trace
|
| 724 |
+
traceA = Arr + Acc
|
| 725 |
+
|
| 726 |
+
if method == 'k':
|
| 727 |
+
response = detA - k * traceA**2
|
| 728 |
+
else:
|
| 729 |
+
response = 2 * detA / (traceA + eps)
|
| 730 |
+
|
| 731 |
+
return response
|
| 732 |
+
|
| 733 |
+
|
| 734 |
+
def corner_shi_tomasi(image, sigma=1):
|
| 735 |
+
"""Compute Shi-Tomasi (Kanade-Tomasi) corner measure response image.
|
| 736 |
+
|
| 737 |
+
This corner detector uses information from the auto-correlation matrix A::
|
| 738 |
+
|
| 739 |
+
A = [(imx**2) (imx*imy)] = [Axx Axy]
|
| 740 |
+
[(imx*imy) (imy**2)] [Axy Ayy]
|
| 741 |
+
|
| 742 |
+
Where imx and imy are first derivatives, averaged with a gaussian filter.
|
| 743 |
+
The corner measure is then defined as the smaller eigenvalue of A::
|
| 744 |
+
|
| 745 |
+
((Axx + Ayy) - sqrt((Axx - Ayy)**2 + 4 * Axy**2)) / 2
|
| 746 |
+
|
| 747 |
+
Parameters
|
| 748 |
+
----------
|
| 749 |
+
image : (M, N) ndarray
|
| 750 |
+
Input image.
|
| 751 |
+
sigma : float, optional
|
| 752 |
+
Standard deviation used for the Gaussian kernel, which is used as
|
| 753 |
+
weighting function for the auto-correlation matrix.
|
| 754 |
+
|
| 755 |
+
Returns
|
| 756 |
+
-------
|
| 757 |
+
response : ndarray
|
| 758 |
+
Shi-Tomasi response image.
|
| 759 |
+
|
| 760 |
+
References
|
| 761 |
+
----------
|
| 762 |
+
.. [1] https://en.wikipedia.org/wiki/Corner_detection
|
| 763 |
+
|
| 764 |
+
Examples
|
| 765 |
+
--------
|
| 766 |
+
>>> from skimage.feature import corner_shi_tomasi, corner_peaks
|
| 767 |
+
>>> square = np.zeros([10, 10])
|
| 768 |
+
>>> square[2:8, 2:8] = 1
|
| 769 |
+
>>> square.astype(int)
|
| 770 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 771 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 772 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 773 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 774 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 775 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 776 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 777 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 778 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 779 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 780 |
+
>>> corner_peaks(corner_shi_tomasi(square), min_distance=1)
|
| 781 |
+
array([[2, 2],
|
| 782 |
+
[2, 7],
|
| 783 |
+
[7, 2],
|
| 784 |
+
[7, 7]])
|
| 785 |
+
|
| 786 |
+
"""
|
| 787 |
+
|
| 788 |
+
Arr, Arc, Acc = structure_tensor(image, sigma, order='rc')
|
| 789 |
+
|
| 790 |
+
# minimum eigenvalue of A
|
| 791 |
+
response = ((Arr + Acc) - np.sqrt((Arr - Acc) ** 2 + 4 * Arc**2)) / 2
|
| 792 |
+
|
| 793 |
+
return response
|
| 794 |
+
|
| 795 |
+
|
| 796 |
+
def corner_foerstner(image, sigma=1):
|
| 797 |
+
"""Compute Foerstner corner measure response image.
|
| 798 |
+
|
| 799 |
+
This corner detector uses information from the auto-correlation matrix A::
|
| 800 |
+
|
| 801 |
+
A = [(imx**2) (imx*imy)] = [Axx Axy]
|
| 802 |
+
[(imx*imy) (imy**2)] [Axy Ayy]
|
| 803 |
+
|
| 804 |
+
Where imx and imy are first derivatives, averaged with a gaussian filter.
|
| 805 |
+
The corner measure is then defined as::
|
| 806 |
+
|
| 807 |
+
w = det(A) / trace(A) (size of error ellipse)
|
| 808 |
+
q = 4 * det(A) / trace(A)**2 (roundness of error ellipse)
|
| 809 |
+
|
| 810 |
+
Parameters
|
| 811 |
+
----------
|
| 812 |
+
image : (M, N) ndarray
|
| 813 |
+
Input image.
|
| 814 |
+
sigma : float, optional
|
| 815 |
+
Standard deviation used for the Gaussian kernel, which is used as
|
| 816 |
+
weighting function for the auto-correlation matrix.
|
| 817 |
+
|
| 818 |
+
Returns
|
| 819 |
+
-------
|
| 820 |
+
w : ndarray
|
| 821 |
+
Error ellipse sizes.
|
| 822 |
+
q : ndarray
|
| 823 |
+
Roundness of error ellipse.
|
| 824 |
+
|
| 825 |
+
References
|
| 826 |
+
----------
|
| 827 |
+
.. [1] Förstner, W., & Gülch, E. (1987, June). A fast operator for
|
| 828 |
+
detection and precise location of distinct points, corners and
|
| 829 |
+
centres of circular features. In Proc. ISPRS intercommission
|
| 830 |
+
conference on fast processing of photogrammetric data (pp. 281-305).
|
| 831 |
+
https://cseweb.ucsd.edu/classes/sp02/cse252/foerstner/foerstner.pdf
|
| 832 |
+
.. [2] https://en.wikipedia.org/wiki/Corner_detection
|
| 833 |
+
|
| 834 |
+
Examples
|
| 835 |
+
--------
|
| 836 |
+
>>> from skimage.feature import corner_foerstner, corner_peaks
|
| 837 |
+
>>> square = np.zeros([10, 10])
|
| 838 |
+
>>> square[2:8, 2:8] = 1
|
| 839 |
+
>>> square.astype(int)
|
| 840 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 841 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 842 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 843 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 844 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 845 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 846 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 847 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 848 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 849 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 850 |
+
>>> w, q = corner_foerstner(square)
|
| 851 |
+
>>> accuracy_thresh = 0.5
|
| 852 |
+
>>> roundness_thresh = 0.3
|
| 853 |
+
>>> foerstner = (q > roundness_thresh) * (w > accuracy_thresh) * w
|
| 854 |
+
>>> corner_peaks(foerstner, min_distance=1)
|
| 855 |
+
array([[2, 2],
|
| 856 |
+
[2, 7],
|
| 857 |
+
[7, 2],
|
| 858 |
+
[7, 7]])
|
| 859 |
+
|
| 860 |
+
"""
|
| 861 |
+
|
| 862 |
+
Arr, Arc, Acc = structure_tensor(image, sigma, order='rc')
|
| 863 |
+
|
| 864 |
+
# determinant
|
| 865 |
+
detA = Arr * Acc - Arc**2
|
| 866 |
+
# trace
|
| 867 |
+
traceA = Arr + Acc
|
| 868 |
+
|
| 869 |
+
w = np.zeros_like(image, dtype=detA.dtype)
|
| 870 |
+
q = np.zeros_like(w)
|
| 871 |
+
|
| 872 |
+
mask = traceA != 0
|
| 873 |
+
|
| 874 |
+
w[mask] = detA[mask] / traceA[mask]
|
| 875 |
+
q[mask] = 4 * detA[mask] / traceA[mask] ** 2
|
| 876 |
+
|
| 877 |
+
return w, q
|
| 878 |
+
|
| 879 |
+
|
| 880 |
+
def corner_fast(image, n=12, threshold=0.15):
|
| 881 |
+
"""Extract FAST corners for a given image.
|
| 882 |
+
|
| 883 |
+
Parameters
|
| 884 |
+
----------
|
| 885 |
+
image : (M, N) ndarray
|
| 886 |
+
Input image.
|
| 887 |
+
n : int, optional
|
| 888 |
+
Minimum number of consecutive pixels out of 16 pixels on the circle
|
| 889 |
+
that should all be either brighter or darker w.r.t testpixel.
|
| 890 |
+
A point c on the circle is darker w.r.t test pixel p if
|
| 891 |
+
`Ic < Ip - threshold` and brighter if `Ic > Ip + threshold`. Also
|
| 892 |
+
stands for the n in `FAST-n` corner detector.
|
| 893 |
+
threshold : float, optional
|
| 894 |
+
Threshold used in deciding whether the pixels on the circle are
|
| 895 |
+
brighter, darker or similar w.r.t. the test pixel. Decrease the
|
| 896 |
+
threshold when more corners are desired and vice-versa.
|
| 897 |
+
|
| 898 |
+
Returns
|
| 899 |
+
-------
|
| 900 |
+
response : ndarray
|
| 901 |
+
FAST corner response image.
|
| 902 |
+
|
| 903 |
+
References
|
| 904 |
+
----------
|
| 905 |
+
.. [1] Rosten, E., & Drummond, T. (2006, May). Machine learning for
|
| 906 |
+
high-speed corner detection. In European conference on computer
|
| 907 |
+
vision (pp. 430-443). Springer, Berlin, Heidelberg.
|
| 908 |
+
:DOI:`10.1007/11744023_34`
|
| 909 |
+
http://www.edwardrosten.com/work/rosten_2006_machine.pdf
|
| 910 |
+
.. [2] Wikipedia, "Features from accelerated segment test",
|
| 911 |
+
https://en.wikipedia.org/wiki/Features_from_accelerated_segment_test
|
| 912 |
+
|
| 913 |
+
Examples
|
| 914 |
+
--------
|
| 915 |
+
>>> from skimage.feature import corner_fast, corner_peaks
|
| 916 |
+
>>> square = np.zeros((12, 12))
|
| 917 |
+
>>> square[3:9, 3:9] = 1
|
| 918 |
+
>>> square.astype(int)
|
| 919 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 920 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 921 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 922 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 923 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 924 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 925 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 926 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 927 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 928 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 929 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 930 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 931 |
+
>>> corner_peaks(corner_fast(square, 9), min_distance=1)
|
| 932 |
+
array([[3, 3],
|
| 933 |
+
[3, 8],
|
| 934 |
+
[8, 3],
|
| 935 |
+
[8, 8]])
|
| 936 |
+
|
| 937 |
+
"""
|
| 938 |
+
image = _prepare_grayscale_input_2D(image)
|
| 939 |
+
|
| 940 |
+
image = np.ascontiguousarray(image)
|
| 941 |
+
response = _corner_fast(image, n, threshold)
|
| 942 |
+
return response
|
| 943 |
+
|
| 944 |
+
|
| 945 |
+
def corner_subpix(image, corners, window_size=11, alpha=0.99):
|
| 946 |
+
"""Determine subpixel position of corners.
|
| 947 |
+
|
| 948 |
+
A statistical test decides whether the corner is defined as the
|
| 949 |
+
intersection of two edges or a single peak. Depending on the classification
|
| 950 |
+
result, the subpixel corner location is determined based on the local
|
| 951 |
+
covariance of the grey-values. If the significance level for either
|
| 952 |
+
statistical test is not sufficient, the corner cannot be classified, and
|
| 953 |
+
the output subpixel position is set to NaN.
|
| 954 |
+
|
| 955 |
+
Parameters
|
| 956 |
+
----------
|
| 957 |
+
image : (M, N) ndarray
|
| 958 |
+
Input image.
|
| 959 |
+
corners : (K, 2) ndarray
|
| 960 |
+
Corner coordinates `(row, col)`.
|
| 961 |
+
window_size : int, optional
|
| 962 |
+
Search window size for subpixel estimation.
|
| 963 |
+
alpha : float, optional
|
| 964 |
+
Significance level for corner classification.
|
| 965 |
+
|
| 966 |
+
Returns
|
| 967 |
+
-------
|
| 968 |
+
positions : (K, 2) ndarray
|
| 969 |
+
Subpixel corner positions. NaN for "not classified" corners.
|
| 970 |
+
|
| 971 |
+
References
|
| 972 |
+
----------
|
| 973 |
+
.. [1] Förstner, W., & Gülch, E. (1987, June). A fast operator for
|
| 974 |
+
detection and precise location of distinct points, corners and
|
| 975 |
+
centres of circular features. In Proc. ISPRS intercommission
|
| 976 |
+
conference on fast processing of photogrammetric data (pp. 281-305).
|
| 977 |
+
https://cseweb.ucsd.edu/classes/sp02/cse252/foerstner/foerstner.pdf
|
| 978 |
+
.. [2] https://en.wikipedia.org/wiki/Corner_detection
|
| 979 |
+
|
| 980 |
+
Examples
|
| 981 |
+
--------
|
| 982 |
+
>>> from skimage.feature import corner_harris, corner_peaks, corner_subpix
|
| 983 |
+
>>> img = np.zeros((10, 10))
|
| 984 |
+
>>> img[:5, :5] = 1
|
| 985 |
+
>>> img[5:, 5:] = 1
|
| 986 |
+
>>> img.astype(int)
|
| 987 |
+
array([[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 988 |
+
[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 989 |
+
[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 990 |
+
[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 991 |
+
[1, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 992 |
+
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
|
| 993 |
+
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
|
| 994 |
+
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
|
| 995 |
+
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1],
|
| 996 |
+
[0, 0, 0, 0, 0, 1, 1, 1, 1, 1]])
|
| 997 |
+
>>> coords = corner_peaks(corner_harris(img), min_distance=2)
|
| 998 |
+
>>> coords_subpix = corner_subpix(img, coords, window_size=7)
|
| 999 |
+
>>> coords_subpix
|
| 1000 |
+
array([[4.5, 4.5]])
|
| 1001 |
+
|
| 1002 |
+
"""
|
| 1003 |
+
|
| 1004 |
+
# window extent in one direction
|
| 1005 |
+
wext = (window_size - 1) // 2
|
| 1006 |
+
|
| 1007 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 1008 |
+
image = image.astype(float_dtype, copy=False)
|
| 1009 |
+
image = np.pad(image, pad_width=wext, mode='constant', constant_values=0)
|
| 1010 |
+
|
| 1011 |
+
# add pad width, make sure to not modify the input values in-place
|
| 1012 |
+
corners = safe_as_int(corners + wext)
|
| 1013 |
+
|
| 1014 |
+
# normal equation arrays
|
| 1015 |
+
N_dot = np.zeros((2, 2), dtype=float_dtype)
|
| 1016 |
+
N_edge = np.zeros((2, 2), dtype=float_dtype)
|
| 1017 |
+
b_dot = np.zeros((2,), dtype=float_dtype)
|
| 1018 |
+
b_edge = np.zeros((2,), dtype=float_dtype)
|
| 1019 |
+
|
| 1020 |
+
# critical statistical test values
|
| 1021 |
+
redundancy = window_size**2 - 2
|
| 1022 |
+
t_crit_dot = stats.f.isf(1 - alpha, redundancy, redundancy)
|
| 1023 |
+
t_crit_edge = stats.f.isf(alpha, redundancy, redundancy)
|
| 1024 |
+
|
| 1025 |
+
# coordinates of pixels within window
|
| 1026 |
+
y, x = np.mgrid[-wext : wext + 1, -wext : wext + 1]
|
| 1027 |
+
|
| 1028 |
+
corners_subpix = np.zeros_like(corners, dtype=float_dtype)
|
| 1029 |
+
|
| 1030 |
+
for i, (y0, x0) in enumerate(corners):
|
| 1031 |
+
# crop window around corner + border for sobel operator
|
| 1032 |
+
miny = y0 - wext - 1
|
| 1033 |
+
maxy = y0 + wext + 2
|
| 1034 |
+
minx = x0 - wext - 1
|
| 1035 |
+
maxx = x0 + wext + 2
|
| 1036 |
+
window = image[miny:maxy, minx:maxx]
|
| 1037 |
+
|
| 1038 |
+
winy, winx = _compute_derivatives(window, mode='constant', cval=0)
|
| 1039 |
+
|
| 1040 |
+
# compute gradient squares and remove border
|
| 1041 |
+
winx_winx = (winx * winx)[1:-1, 1:-1]
|
| 1042 |
+
winx_winy = (winx * winy)[1:-1, 1:-1]
|
| 1043 |
+
winy_winy = (winy * winy)[1:-1, 1:-1]
|
| 1044 |
+
|
| 1045 |
+
# sum of squared differences (mean instead of gaussian filter)
|
| 1046 |
+
Axx = np.sum(winx_winx)
|
| 1047 |
+
Axy = np.sum(winx_winy)
|
| 1048 |
+
Ayy = np.sum(winy_winy)
|
| 1049 |
+
|
| 1050 |
+
# sum of squared differences weighted with coordinates
|
| 1051 |
+
# (mean instead of gaussian filter)
|
| 1052 |
+
bxx_x = np.sum(winx_winx * x)
|
| 1053 |
+
bxx_y = np.sum(winx_winx * y)
|
| 1054 |
+
bxy_x = np.sum(winx_winy * x)
|
| 1055 |
+
bxy_y = np.sum(winx_winy * y)
|
| 1056 |
+
byy_x = np.sum(winy_winy * x)
|
| 1057 |
+
byy_y = np.sum(winy_winy * y)
|
| 1058 |
+
|
| 1059 |
+
# normal equations for subpixel position
|
| 1060 |
+
N_dot[0, 0] = Axx
|
| 1061 |
+
N_dot[0, 1] = N_dot[1, 0] = -Axy
|
| 1062 |
+
N_dot[1, 1] = Ayy
|
| 1063 |
+
|
| 1064 |
+
N_edge[0, 0] = Ayy
|
| 1065 |
+
N_edge[0, 1] = N_edge[1, 0] = Axy
|
| 1066 |
+
N_edge[1, 1] = Axx
|
| 1067 |
+
|
| 1068 |
+
b_dot[:] = bxx_y - bxy_x, byy_x - bxy_y
|
| 1069 |
+
b_edge[:] = byy_y + bxy_x, bxx_x + bxy_y
|
| 1070 |
+
|
| 1071 |
+
# estimated positions
|
| 1072 |
+
try:
|
| 1073 |
+
est_dot = np.linalg.solve(N_dot, b_dot)
|
| 1074 |
+
est_edge = np.linalg.solve(N_edge, b_edge)
|
| 1075 |
+
except np.linalg.LinAlgError:
|
| 1076 |
+
# if image is constant the system is singular
|
| 1077 |
+
corners_subpix[i, :] = np.nan, np.nan
|
| 1078 |
+
continue
|
| 1079 |
+
|
| 1080 |
+
# residuals
|
| 1081 |
+
ry_dot = y - est_dot[0]
|
| 1082 |
+
rx_dot = x - est_dot[1]
|
| 1083 |
+
ry_edge = y - est_edge[0]
|
| 1084 |
+
rx_edge = x - est_edge[1]
|
| 1085 |
+
# squared residuals
|
| 1086 |
+
rxx_dot = rx_dot * rx_dot
|
| 1087 |
+
rxy_dot = rx_dot * ry_dot
|
| 1088 |
+
ryy_dot = ry_dot * ry_dot
|
| 1089 |
+
rxx_edge = rx_edge * rx_edge
|
| 1090 |
+
rxy_edge = rx_edge * ry_edge
|
| 1091 |
+
ryy_edge = ry_edge * ry_edge
|
| 1092 |
+
|
| 1093 |
+
# determine corner class (dot or edge)
|
| 1094 |
+
# variance for different models
|
| 1095 |
+
var_dot = np.sum(
|
| 1096 |
+
winx_winx * ryy_dot - 2 * winx_winy * rxy_dot + winy_winy * rxx_dot
|
| 1097 |
+
)
|
| 1098 |
+
var_edge = np.sum(
|
| 1099 |
+
winy_winy * ryy_edge + 2 * winx_winy * rxy_edge + winx_winx * rxx_edge
|
| 1100 |
+
)
|
| 1101 |
+
|
| 1102 |
+
# test value (F-distributed)
|
| 1103 |
+
if var_dot < np.spacing(1) and var_edge < np.spacing(1):
|
| 1104 |
+
t = np.nan
|
| 1105 |
+
elif var_dot == 0:
|
| 1106 |
+
t = np.inf
|
| 1107 |
+
else:
|
| 1108 |
+
t = var_edge / var_dot
|
| 1109 |
+
|
| 1110 |
+
# 1 for edge, -1 for dot, 0 for "not classified"
|
| 1111 |
+
corner_class = int(t < t_crit_edge) - int(t > t_crit_dot)
|
| 1112 |
+
|
| 1113 |
+
if corner_class == -1:
|
| 1114 |
+
corners_subpix[i, :] = y0 + est_dot[0], x0 + est_dot[1]
|
| 1115 |
+
elif corner_class == 0:
|
| 1116 |
+
corners_subpix[i, :] = np.nan, np.nan
|
| 1117 |
+
elif corner_class == 1:
|
| 1118 |
+
corners_subpix[i, :] = y0 + est_edge[0], x0 + est_edge[1]
|
| 1119 |
+
|
| 1120 |
+
# subtract pad width
|
| 1121 |
+
corners_subpix -= wext
|
| 1122 |
+
|
| 1123 |
+
return corners_subpix
|
| 1124 |
+
|
| 1125 |
+
|
| 1126 |
+
def corner_peaks(
|
| 1127 |
+
image,
|
| 1128 |
+
min_distance=1,
|
| 1129 |
+
threshold_abs=None,
|
| 1130 |
+
threshold_rel=None,
|
| 1131 |
+
exclude_border=True,
|
| 1132 |
+
indices=True,
|
| 1133 |
+
num_peaks=np.inf,
|
| 1134 |
+
footprint=None,
|
| 1135 |
+
labels=None,
|
| 1136 |
+
*,
|
| 1137 |
+
num_peaks_per_label=np.inf,
|
| 1138 |
+
p_norm=np.inf,
|
| 1139 |
+
):
|
| 1140 |
+
"""Find peaks in corner measure response image.
|
| 1141 |
+
|
| 1142 |
+
This differs from `skimage.feature.peak_local_max` in that it suppresses
|
| 1143 |
+
multiple connected peaks with the same accumulator value.
|
| 1144 |
+
|
| 1145 |
+
Parameters
|
| 1146 |
+
----------
|
| 1147 |
+
image : (M, N) ndarray
|
| 1148 |
+
Input image.
|
| 1149 |
+
min_distance : int, optional
|
| 1150 |
+
The minimal allowed distance separating peaks.
|
| 1151 |
+
* : *
|
| 1152 |
+
See :py:meth:`skimage.feature.peak_local_max`.
|
| 1153 |
+
p_norm : float
|
| 1154 |
+
Which Minkowski p-norm to use. Should be in the range [1, inf].
|
| 1155 |
+
A finite large p may cause a ValueError if overflow can occur.
|
| 1156 |
+
``inf`` corresponds to the Chebyshev distance and 2 to the
|
| 1157 |
+
Euclidean distance.
|
| 1158 |
+
|
| 1159 |
+
Returns
|
| 1160 |
+
-------
|
| 1161 |
+
output : ndarray or ndarray of bools
|
| 1162 |
+
|
| 1163 |
+
* If `indices = True` : (row, column, ...) coordinates of peaks.
|
| 1164 |
+
* If `indices = False` : Boolean array shaped like `image`, with peaks
|
| 1165 |
+
represented by True values.
|
| 1166 |
+
|
| 1167 |
+
See also
|
| 1168 |
+
--------
|
| 1169 |
+
skimage.feature.peak_local_max
|
| 1170 |
+
|
| 1171 |
+
Notes
|
| 1172 |
+
-----
|
| 1173 |
+
.. versionchanged:: 0.18
|
| 1174 |
+
The default value of `threshold_rel` has changed to None, which
|
| 1175 |
+
corresponds to letting `skimage.feature.peak_local_max` decide on the
|
| 1176 |
+
default. This is equivalent to `threshold_rel=0`.
|
| 1177 |
+
|
| 1178 |
+
The `num_peaks` limit is applied before suppression of connected peaks.
|
| 1179 |
+
To limit the number of peaks after suppression, set `num_peaks=np.inf` and
|
| 1180 |
+
post-process the output of this function.
|
| 1181 |
+
|
| 1182 |
+
Examples
|
| 1183 |
+
--------
|
| 1184 |
+
>>> from skimage.feature import peak_local_max
|
| 1185 |
+
>>> response = np.zeros((5, 5))
|
| 1186 |
+
>>> response[2:4, 2:4] = 1
|
| 1187 |
+
>>> response
|
| 1188 |
+
array([[0., 0., 0., 0., 0.],
|
| 1189 |
+
[0., 0., 0., 0., 0.],
|
| 1190 |
+
[0., 0., 1., 1., 0.],
|
| 1191 |
+
[0., 0., 1., 1., 0.],
|
| 1192 |
+
[0., 0., 0., 0., 0.]])
|
| 1193 |
+
>>> peak_local_max(response)
|
| 1194 |
+
array([[2, 2],
|
| 1195 |
+
[2, 3],
|
| 1196 |
+
[3, 2],
|
| 1197 |
+
[3, 3]])
|
| 1198 |
+
>>> corner_peaks(response)
|
| 1199 |
+
array([[2, 2]])
|
| 1200 |
+
|
| 1201 |
+
"""
|
| 1202 |
+
if np.isinf(num_peaks):
|
| 1203 |
+
num_peaks = None
|
| 1204 |
+
|
| 1205 |
+
# Get the coordinates of the detected peaks
|
| 1206 |
+
coords = peak_local_max(
|
| 1207 |
+
image,
|
| 1208 |
+
min_distance=min_distance,
|
| 1209 |
+
threshold_abs=threshold_abs,
|
| 1210 |
+
threshold_rel=threshold_rel,
|
| 1211 |
+
exclude_border=exclude_border,
|
| 1212 |
+
num_peaks=np.inf,
|
| 1213 |
+
footprint=footprint,
|
| 1214 |
+
labels=labels,
|
| 1215 |
+
num_peaks_per_label=num_peaks_per_label,
|
| 1216 |
+
)
|
| 1217 |
+
|
| 1218 |
+
if len(coords):
|
| 1219 |
+
# Use KDtree to find the peaks that are too close to each other
|
| 1220 |
+
tree = spatial.cKDTree(coords)
|
| 1221 |
+
|
| 1222 |
+
rejected_peaks_indices = set()
|
| 1223 |
+
for idx, point in enumerate(coords):
|
| 1224 |
+
if idx not in rejected_peaks_indices:
|
| 1225 |
+
candidates = tree.query_ball_point(point, r=min_distance, p=p_norm)
|
| 1226 |
+
candidates.remove(idx)
|
| 1227 |
+
rejected_peaks_indices.update(candidates)
|
| 1228 |
+
|
| 1229 |
+
# Remove the peaks that are too close to each other
|
| 1230 |
+
coords = np.delete(coords, tuple(rejected_peaks_indices), axis=0)[:num_peaks]
|
| 1231 |
+
|
| 1232 |
+
if indices:
|
| 1233 |
+
return coords
|
| 1234 |
+
|
| 1235 |
+
peaks = np.zeros_like(image, dtype=bool)
|
| 1236 |
+
peaks[tuple(coords.T)] = True
|
| 1237 |
+
|
| 1238 |
+
return peaks
|
| 1239 |
+
|
| 1240 |
+
|
| 1241 |
+
def corner_moravec(image, window_size=1):
|
| 1242 |
+
"""Compute Moravec corner measure response image.
|
| 1243 |
+
|
| 1244 |
+
This is one of the simplest corner detectors and is comparatively fast but
|
| 1245 |
+
has several limitations (e.g. not rotation invariant).
|
| 1246 |
+
|
| 1247 |
+
Parameters
|
| 1248 |
+
----------
|
| 1249 |
+
image : (M, N) ndarray
|
| 1250 |
+
Input image.
|
| 1251 |
+
window_size : int, optional
|
| 1252 |
+
Window size.
|
| 1253 |
+
|
| 1254 |
+
Returns
|
| 1255 |
+
-------
|
| 1256 |
+
response : ndarray
|
| 1257 |
+
Moravec response image.
|
| 1258 |
+
|
| 1259 |
+
References
|
| 1260 |
+
----------
|
| 1261 |
+
.. [1] https://en.wikipedia.org/wiki/Corner_detection
|
| 1262 |
+
|
| 1263 |
+
Examples
|
| 1264 |
+
--------
|
| 1265 |
+
>>> from skimage.feature import corner_moravec
|
| 1266 |
+
>>> square = np.zeros([7, 7])
|
| 1267 |
+
>>> square[3, 3] = 1
|
| 1268 |
+
>>> square.astype(int)
|
| 1269 |
+
array([[0, 0, 0, 0, 0, 0, 0],
|
| 1270 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1271 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1272 |
+
[0, 0, 0, 1, 0, 0, 0],
|
| 1273 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1274 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1275 |
+
[0, 0, 0, 0, 0, 0, 0]])
|
| 1276 |
+
>>> corner_moravec(square).astype(int)
|
| 1277 |
+
array([[0, 0, 0, 0, 0, 0, 0],
|
| 1278 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1279 |
+
[0, 0, 1, 1, 1, 0, 0],
|
| 1280 |
+
[0, 0, 1, 2, 1, 0, 0],
|
| 1281 |
+
[0, 0, 1, 1, 1, 0, 0],
|
| 1282 |
+
[0, 0, 0, 0, 0, 0, 0],
|
| 1283 |
+
[0, 0, 0, 0, 0, 0, 0]])
|
| 1284 |
+
"""
|
| 1285 |
+
image = img_as_float(image)
|
| 1286 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 1287 |
+
image = image.astype(float_dtype, copy=False)
|
| 1288 |
+
return _corner_moravec(np.ascontiguousarray(image), window_size)
|
| 1289 |
+
|
| 1290 |
+
|
| 1291 |
+
def corner_orientations(image, corners, mask):
|
| 1292 |
+
"""Compute the orientation of corners.
|
| 1293 |
+
|
| 1294 |
+
The orientation of corners is computed using the first order central moment
|
| 1295 |
+
i.e. the center of mass approach. The corner orientation is the angle of
|
| 1296 |
+
the vector from the corner coordinate to the intensity centroid in the
|
| 1297 |
+
local neighborhood around the corner calculated using first order central
|
| 1298 |
+
moment.
|
| 1299 |
+
|
| 1300 |
+
Parameters
|
| 1301 |
+
----------
|
| 1302 |
+
image : (M, N) array
|
| 1303 |
+
Input grayscale image.
|
| 1304 |
+
corners : (K, 2) array
|
| 1305 |
+
Corner coordinates as ``(row, col)``.
|
| 1306 |
+
mask : 2D array
|
| 1307 |
+
Mask defining the local neighborhood of the corner used for the
|
| 1308 |
+
calculation of the central moment.
|
| 1309 |
+
|
| 1310 |
+
Returns
|
| 1311 |
+
-------
|
| 1312 |
+
orientations : (K, 1) array
|
| 1313 |
+
Orientations of corners in the range [-pi, pi].
|
| 1314 |
+
|
| 1315 |
+
References
|
| 1316 |
+
----------
|
| 1317 |
+
.. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski
|
| 1318 |
+
"ORB : An efficient alternative to SIFT and SURF"
|
| 1319 |
+
http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf
|
| 1320 |
+
.. [2] Paul L. Rosin, "Measuring Corner Properties"
|
| 1321 |
+
http://users.cs.cf.ac.uk/Paul.Rosin/corner2.pdf
|
| 1322 |
+
|
| 1323 |
+
Examples
|
| 1324 |
+
--------
|
| 1325 |
+
>>> from skimage.morphology import octagon
|
| 1326 |
+
>>> from skimage.feature import (corner_fast, corner_peaks,
|
| 1327 |
+
... corner_orientations)
|
| 1328 |
+
>>> square = np.zeros((12, 12))
|
| 1329 |
+
>>> square[3:9, 3:9] = 1
|
| 1330 |
+
>>> square.astype(int)
|
| 1331 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 1332 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 1333 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 1334 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1335 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1336 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1337 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1338 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1339 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 1340 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 1341 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 1342 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 1343 |
+
>>> corners = corner_peaks(corner_fast(square, 9), min_distance=1)
|
| 1344 |
+
>>> corners
|
| 1345 |
+
array([[3, 3],
|
| 1346 |
+
[3, 8],
|
| 1347 |
+
[8, 3],
|
| 1348 |
+
[8, 8]])
|
| 1349 |
+
>>> orientations = corner_orientations(square, corners, octagon(3, 2))
|
| 1350 |
+
>>> np.rad2deg(orientations)
|
| 1351 |
+
array([ 45., 135., -45., -135.])
|
| 1352 |
+
|
| 1353 |
+
"""
|
| 1354 |
+
image = _prepare_grayscale_input_2D(image)
|
| 1355 |
+
return _corner_orientations(image, corners, mask)
|
envs/kitoverlay/skimage/feature/haar.py
ADDED
|
@@ -0,0 +1,339 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from itertools import chain
|
| 2 |
+
from operator import add
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from ._haar import haar_like_feature_coord_wrapper
|
| 7 |
+
from ._haar import haar_like_feature_wrapper
|
| 8 |
+
from ..color import gray2rgb
|
| 9 |
+
from ..draw import rectangle
|
| 10 |
+
from ..util import img_as_float
|
| 11 |
+
|
| 12 |
+
FEATURE_TYPE = ('type-2-x', 'type-2-y', 'type-3-x', 'type-3-y', 'type-4')
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def _validate_feature_type(feature_type):
|
| 16 |
+
"""Transform feature type to an iterable and check that it exists."""
|
| 17 |
+
if feature_type is None:
|
| 18 |
+
feature_type_ = FEATURE_TYPE
|
| 19 |
+
else:
|
| 20 |
+
if isinstance(feature_type, str):
|
| 21 |
+
feature_type_ = [feature_type]
|
| 22 |
+
else:
|
| 23 |
+
feature_type_ = feature_type
|
| 24 |
+
for feat_t in feature_type_:
|
| 25 |
+
if feat_t not in FEATURE_TYPE:
|
| 26 |
+
raise ValueError(
|
| 27 |
+
f'The given feature type is unknown. Got {feat_t} instead of one '
|
| 28 |
+
f'of {FEATURE_TYPE}.'
|
| 29 |
+
)
|
| 30 |
+
return feature_type_
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def haar_like_feature_coord(width, height, feature_type=None):
|
| 34 |
+
"""Compute the coordinates of Haar-like features.
|
| 35 |
+
|
| 36 |
+
Parameters
|
| 37 |
+
----------
|
| 38 |
+
width : int
|
| 39 |
+
Width of the detection window.
|
| 40 |
+
height : int
|
| 41 |
+
Height of the detection window.
|
| 42 |
+
feature_type : str or list of str or None, optional
|
| 43 |
+
The type of feature to consider:
|
| 44 |
+
|
| 45 |
+
- 'type-2-x': 2 rectangles varying along the x axis;
|
| 46 |
+
- 'type-2-y': 2 rectangles varying along the y axis;
|
| 47 |
+
- 'type-3-x': 3 rectangles varying along the x axis;
|
| 48 |
+
- 'type-3-y': 3 rectangles varying along the y axis;
|
| 49 |
+
- 'type-4': 4 rectangles varying along x and y axis.
|
| 50 |
+
|
| 51 |
+
By default all features are extracted.
|
| 52 |
+
|
| 53 |
+
Returns
|
| 54 |
+
-------
|
| 55 |
+
feature_coord : (n_features, n_rectangles, 2, 2), ndarray of list of \
|
| 56 |
+
tuple coord
|
| 57 |
+
Coordinates of the rectangles for each feature.
|
| 58 |
+
feature_type : (n_features,), ndarray of str
|
| 59 |
+
The corresponding type for each feature.
|
| 60 |
+
|
| 61 |
+
Examples
|
| 62 |
+
--------
|
| 63 |
+
>>> import numpy as np
|
| 64 |
+
>>> from skimage.transform import integral_image
|
| 65 |
+
>>> from skimage.feature import haar_like_feature_coord
|
| 66 |
+
>>> feat_coord, feat_type = haar_like_feature_coord(2, 2, 'type-4')
|
| 67 |
+
>>> feat_coord # doctest: +SKIP
|
| 68 |
+
array([ list([[(0, 0), (0, 0)], [(0, 1), (0, 1)],
|
| 69 |
+
[(1, 1), (1, 1)], [(1, 0), (1, 0)]])], dtype=object)
|
| 70 |
+
>>> feat_type
|
| 71 |
+
array(['type-4'], dtype=object)
|
| 72 |
+
|
| 73 |
+
"""
|
| 74 |
+
feature_type_ = _validate_feature_type(feature_type)
|
| 75 |
+
|
| 76 |
+
feat_coord, feat_type = zip(
|
| 77 |
+
*[
|
| 78 |
+
haar_like_feature_coord_wrapper(width, height, feat_t)
|
| 79 |
+
for feat_t in feature_type_
|
| 80 |
+
]
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
return np.concatenate(feat_coord), np.hstack(feat_type)
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
def haar_like_feature(
|
| 87 |
+
int_image, r, c, width, height, feature_type=None, feature_coord=None
|
| 88 |
+
):
|
| 89 |
+
"""Compute the Haar-like features for a region of interest (ROI) of an
|
| 90 |
+
integral image.
|
| 91 |
+
|
| 92 |
+
Haar-like features have been successfully used for image classification and
|
| 93 |
+
object detection [1]_. It has been used for real-time face detection
|
| 94 |
+
algorithm proposed in [2]_.
|
| 95 |
+
|
| 96 |
+
Parameters
|
| 97 |
+
----------
|
| 98 |
+
int_image : (M, N) ndarray
|
| 99 |
+
Integral image for which the features need to be computed.
|
| 100 |
+
r : int
|
| 101 |
+
Row-coordinate of top left corner of the detection window.
|
| 102 |
+
c : int
|
| 103 |
+
Column-coordinate of top left corner of the detection window.
|
| 104 |
+
width : int
|
| 105 |
+
Width of the detection window.
|
| 106 |
+
height : int
|
| 107 |
+
Height of the detection window.
|
| 108 |
+
feature_type : str or list of str or None, optional
|
| 109 |
+
The type of feature to consider:
|
| 110 |
+
|
| 111 |
+
- 'type-2-x': 2 rectangles varying along the x axis;
|
| 112 |
+
- 'type-2-y': 2 rectangles varying along the y axis;
|
| 113 |
+
- 'type-3-x': 3 rectangles varying along the x axis;
|
| 114 |
+
- 'type-3-y': 3 rectangles varying along the y axis;
|
| 115 |
+
- 'type-4': 4 rectangles varying along x and y axis.
|
| 116 |
+
|
| 117 |
+
By default all features are extracted.
|
| 118 |
+
|
| 119 |
+
If using with `feature_coord`, it should correspond to the feature
|
| 120 |
+
type of each associated coordinate feature.
|
| 121 |
+
feature_coord : ndarray of list of tuples or None, optional
|
| 122 |
+
The array of coordinates to be extracted. This is useful when you want
|
| 123 |
+
to recompute only a subset of features. In this case `feature_type`
|
| 124 |
+
needs to be an array containing the type of each feature, as returned
|
| 125 |
+
by :func:`haar_like_feature_coord`. By default, all coordinates are
|
| 126 |
+
computed.
|
| 127 |
+
|
| 128 |
+
Returns
|
| 129 |
+
-------
|
| 130 |
+
haar_features : (n_features,) ndarray of int or float
|
| 131 |
+
Resulting Haar-like features. Each value is equal to the subtraction of
|
| 132 |
+
sums of the positive and negative rectangles. The data type depends of
|
| 133 |
+
the data type of `int_image`: `int` when the data type of `int_image`
|
| 134 |
+
is `uint` or `int` and `float` when the data type of `int_image` is
|
| 135 |
+
`float`.
|
| 136 |
+
|
| 137 |
+
Notes
|
| 138 |
+
-----
|
| 139 |
+
When extracting those features in parallel, be aware that the choice of the
|
| 140 |
+
backend (i.e. multiprocessing vs threading) will have an impact on the
|
| 141 |
+
performance. The rule of thumb is as follows: use multiprocessing when
|
| 142 |
+
extracting features for all possible ROI in an image; use threading when
|
| 143 |
+
extracting the feature at specific location for a limited number of ROIs.
|
| 144 |
+
Refer to the example
|
| 145 |
+
:ref:`sphx_glr_auto_examples_applications_plot_haar_extraction_selection_classification.py`
|
| 146 |
+
for more insights.
|
| 147 |
+
|
| 148 |
+
Examples
|
| 149 |
+
--------
|
| 150 |
+
>>> import numpy as np
|
| 151 |
+
>>> from skimage.transform import integral_image
|
| 152 |
+
>>> from skimage.feature import haar_like_feature
|
| 153 |
+
>>> img = np.ones((5, 5), dtype=np.uint8)
|
| 154 |
+
>>> img_ii = integral_image(img)
|
| 155 |
+
>>> feature = haar_like_feature(img_ii, 0, 0, 5, 5, 'type-3-x')
|
| 156 |
+
>>> feature
|
| 157 |
+
array([-1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2, -3, -4, -5, -1, -2,
|
| 158 |
+
-3, -4, -1, -2, -3, -4, -1, -2, -3, -4, -1, -2, -3, -1, -2, -3, -1,
|
| 159 |
+
-2, -3, -1, -2, -1, -2, -1, -2, -1, -1, -1])
|
| 160 |
+
|
| 161 |
+
You can compute the feature for some pre-computed coordinates.
|
| 162 |
+
|
| 163 |
+
>>> from skimage.feature import haar_like_feature_coord
|
| 164 |
+
>>> feature_coord, feature_type = zip(
|
| 165 |
+
... *[haar_like_feature_coord(5, 5, feat_t)
|
| 166 |
+
... for feat_t in ('type-2-x', 'type-3-x')])
|
| 167 |
+
>>> # only select one feature over two
|
| 168 |
+
>>> feature_coord = np.concatenate([x[::2] for x in feature_coord])
|
| 169 |
+
>>> feature_type = np.concatenate([x[::2] for x in feature_type])
|
| 170 |
+
>>> feature = haar_like_feature(img_ii, 0, 0, 5, 5,
|
| 171 |
+
... feature_type=feature_type,
|
| 172 |
+
... feature_coord=feature_coord)
|
| 173 |
+
>>> feature
|
| 174 |
+
array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 175 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
| 176 |
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -3, -5, -2, -4, -1,
|
| 177 |
+
-3, -5, -2, -4, -2, -4, -2, -4, -2, -1, -3, -2, -1, -1, -1, -1, -1])
|
| 178 |
+
|
| 179 |
+
References
|
| 180 |
+
----------
|
| 181 |
+
.. [1] https://en.wikipedia.org/wiki/Haar-like_feature
|
| 182 |
+
.. [2] Oren, M., Papageorgiou, C., Sinha, P., Osuna, E., & Poggio, T.
|
| 183 |
+
(1997, June). Pedestrian detection using wavelet templates.
|
| 184 |
+
In Computer Vision and Pattern Recognition, 1997. Proceedings.,
|
| 185 |
+
1997 IEEE Computer Society Conference on (pp. 193-199). IEEE.
|
| 186 |
+
http://tinyurl.com/y6ulxfta
|
| 187 |
+
:DOI:`10.1109/CVPR.1997.609319`
|
| 188 |
+
.. [3] Viola, Paul, and Michael J. Jones. "Robust real-time face
|
| 189 |
+
detection." International journal of computer vision 57.2
|
| 190 |
+
(2004): 137-154.
|
| 191 |
+
https://www.merl.com/publications/docs/TR2004-043.pdf
|
| 192 |
+
:DOI:`10.1109/CVPR.2001.990517`
|
| 193 |
+
|
| 194 |
+
"""
|
| 195 |
+
if feature_coord is None:
|
| 196 |
+
feature_type_ = _validate_feature_type(feature_type)
|
| 197 |
+
|
| 198 |
+
return np.hstack(
|
| 199 |
+
list(
|
| 200 |
+
chain.from_iterable(
|
| 201 |
+
haar_like_feature_wrapper(
|
| 202 |
+
int_image, r, c, width, height, feat_t, feature_coord
|
| 203 |
+
)
|
| 204 |
+
for feat_t in feature_type_
|
| 205 |
+
)
|
| 206 |
+
)
|
| 207 |
+
)
|
| 208 |
+
else:
|
| 209 |
+
if feature_coord.shape[0] != feature_type.shape[0]:
|
| 210 |
+
raise ValueError(
|
| 211 |
+
"Inconsistent size between feature coordinates" "and feature types."
|
| 212 |
+
)
|
| 213 |
+
|
| 214 |
+
mask_feature = [feature_type == feat_t for feat_t in FEATURE_TYPE]
|
| 215 |
+
haar_feature_idx, haar_feature = zip(
|
| 216 |
+
*[
|
| 217 |
+
(
|
| 218 |
+
np.flatnonzero(mask),
|
| 219 |
+
haar_like_feature_wrapper(
|
| 220 |
+
int_image, r, c, width, height, feat_t, feature_coord[mask]
|
| 221 |
+
),
|
| 222 |
+
)
|
| 223 |
+
for mask, feat_t in zip(mask_feature, FEATURE_TYPE)
|
| 224 |
+
if np.count_nonzero(mask)
|
| 225 |
+
]
|
| 226 |
+
)
|
| 227 |
+
|
| 228 |
+
haar_feature_idx = np.concatenate(haar_feature_idx)
|
| 229 |
+
haar_feature = np.concatenate(haar_feature)
|
| 230 |
+
|
| 231 |
+
haar_feature[haar_feature_idx] = haar_feature.copy()
|
| 232 |
+
return haar_feature
|
| 233 |
+
|
| 234 |
+
|
| 235 |
+
def draw_haar_like_feature(
|
| 236 |
+
image,
|
| 237 |
+
r,
|
| 238 |
+
c,
|
| 239 |
+
width,
|
| 240 |
+
height,
|
| 241 |
+
feature_coord,
|
| 242 |
+
color_positive_block=(1.0, 0.0, 0.0),
|
| 243 |
+
color_negative_block=(0.0, 1.0, 0.0),
|
| 244 |
+
alpha=0.5,
|
| 245 |
+
max_n_features=None,
|
| 246 |
+
rng=None,
|
| 247 |
+
):
|
| 248 |
+
"""Visualization of Haar-like features.
|
| 249 |
+
|
| 250 |
+
Parameters
|
| 251 |
+
----------
|
| 252 |
+
image : (M, N) ndarray
|
| 253 |
+
The region of an integral image for which the features need to be
|
| 254 |
+
computed.
|
| 255 |
+
r : int
|
| 256 |
+
Row-coordinate of top left corner of the detection window.
|
| 257 |
+
c : int
|
| 258 |
+
Column-coordinate of top left corner of the detection window.
|
| 259 |
+
width : int
|
| 260 |
+
Width of the detection window.
|
| 261 |
+
height : int
|
| 262 |
+
Height of the detection window.
|
| 263 |
+
feature_coord : ndarray of list of tuples or None, optional
|
| 264 |
+
The array of coordinates to be extracted. This is useful when you want
|
| 265 |
+
to recompute only a subset of features. In this case `feature_type`
|
| 266 |
+
needs to be an array containing the type of each feature, as returned
|
| 267 |
+
by :func:`haar_like_feature_coord`. By default, all coordinates are
|
| 268 |
+
computed.
|
| 269 |
+
color_positive_block : tuple of 3 floats
|
| 270 |
+
Floats specifying the color for the positive block. Corresponding
|
| 271 |
+
values define (R, G, B) values. Default value is red (1, 0, 0).
|
| 272 |
+
color_negative_block : tuple of 3 floats
|
| 273 |
+
Floats specifying the color for the negative block Corresponding values
|
| 274 |
+
define (R, G, B) values. Default value is blue (0, 1, 0).
|
| 275 |
+
alpha : float
|
| 276 |
+
Value in the range [0, 1] that specifies opacity of visualization. 1 -
|
| 277 |
+
fully transparent, 0 - opaque.
|
| 278 |
+
max_n_features : int, default=None
|
| 279 |
+
The maximum number of features to be returned.
|
| 280 |
+
By default, all features are returned.
|
| 281 |
+
rng : {`numpy.random.Generator`, int}, optional
|
| 282 |
+
Pseudo-random number generator.
|
| 283 |
+
By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
|
| 284 |
+
If `rng` is an int, it is used to seed the generator.
|
| 285 |
+
|
| 286 |
+
The rng is used when generating a set of features smaller than
|
| 287 |
+
the total number of available features.
|
| 288 |
+
|
| 289 |
+
Returns
|
| 290 |
+
-------
|
| 291 |
+
features : (M, N), ndarray
|
| 292 |
+
An image in which the different features will be added.
|
| 293 |
+
|
| 294 |
+
Examples
|
| 295 |
+
--------
|
| 296 |
+
>>> import numpy as np
|
| 297 |
+
>>> from skimage.feature import haar_like_feature_coord
|
| 298 |
+
>>> from skimage.feature import draw_haar_like_feature
|
| 299 |
+
>>> feature_coord, _ = haar_like_feature_coord(2, 2, 'type-4')
|
| 300 |
+
>>> image = draw_haar_like_feature(np.zeros((2, 2)),
|
| 301 |
+
... 0, 0, 2, 2,
|
| 302 |
+
... feature_coord,
|
| 303 |
+
... max_n_features=1)
|
| 304 |
+
>>> image
|
| 305 |
+
array([[[0. , 0.5, 0. ],
|
| 306 |
+
[0.5, 0. , 0. ]],
|
| 307 |
+
<BLANKLINE>
|
| 308 |
+
[[0.5, 0. , 0. ],
|
| 309 |
+
[0. , 0.5, 0. ]]])
|
| 310 |
+
|
| 311 |
+
"""
|
| 312 |
+
rng = np.random.default_rng(rng)
|
| 313 |
+
color_positive_block = np.asarray(color_positive_block, dtype=np.float64)
|
| 314 |
+
color_negative_block = np.asarray(color_negative_block, dtype=np.float64)
|
| 315 |
+
|
| 316 |
+
if max_n_features is None:
|
| 317 |
+
feature_coord_ = feature_coord
|
| 318 |
+
else:
|
| 319 |
+
feature_coord_ = rng.choice(feature_coord, size=max_n_features, replace=False)
|
| 320 |
+
|
| 321 |
+
output = np.copy(image)
|
| 322 |
+
if len(image.shape) < 3:
|
| 323 |
+
output = gray2rgb(image)
|
| 324 |
+
output = img_as_float(output)
|
| 325 |
+
|
| 326 |
+
for coord in feature_coord_:
|
| 327 |
+
for idx_rect, rect in enumerate(coord):
|
| 328 |
+
coord_start, coord_end = rect
|
| 329 |
+
coord_start = tuple(map(add, coord_start, [r, c]))
|
| 330 |
+
coord_end = tuple(map(add, coord_end, [r, c]))
|
| 331 |
+
rr, cc = rectangle(coord_start, coord_end)
|
| 332 |
+
|
| 333 |
+
if ((idx_rect + 1) % 2) == 0:
|
| 334 |
+
new_value = (1 - alpha) * output[rr, cc] + alpha * color_positive_block
|
| 335 |
+
else:
|
| 336 |
+
new_value = (1 - alpha) * output[rr, cc] + alpha * color_negative_block
|
| 337 |
+
output[rr, cc] = new_value
|
| 338 |
+
|
| 339 |
+
return output
|
envs/kitoverlay/skimage/feature/match.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.spatial.distance import cdist
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def match_descriptors(
|
| 6 |
+
descriptors1,
|
| 7 |
+
descriptors2,
|
| 8 |
+
metric=None,
|
| 9 |
+
p=2,
|
| 10 |
+
max_distance=np.inf,
|
| 11 |
+
cross_check=True,
|
| 12 |
+
max_ratio=1.0,
|
| 13 |
+
):
|
| 14 |
+
"""Brute-force matching of descriptors.
|
| 15 |
+
|
| 16 |
+
For each descriptor in the first set this matcher finds the closest
|
| 17 |
+
descriptor in the second set (and vice-versa in the case of enabled
|
| 18 |
+
cross-checking).
|
| 19 |
+
|
| 20 |
+
Parameters
|
| 21 |
+
----------
|
| 22 |
+
descriptors1 : (M, P) array
|
| 23 |
+
Descriptors of size P about M keypoints in the first image.
|
| 24 |
+
descriptors2 : (N, P) array
|
| 25 |
+
Descriptors of size P about N keypoints in the second image.
|
| 26 |
+
metric : {'euclidean', 'cityblock', 'minkowski', 'hamming', ...} , optional
|
| 27 |
+
The metric to compute the distance between two descriptors. See
|
| 28 |
+
`scipy.spatial.distance.cdist` for all possible types. The hamming
|
| 29 |
+
distance should be used for binary descriptors. By default the L2-norm
|
| 30 |
+
is used for all descriptors of dtype float or double and the Hamming
|
| 31 |
+
distance is used for binary descriptors automatically.
|
| 32 |
+
p : int, optional
|
| 33 |
+
The p-norm to apply for ``metric='minkowski'``.
|
| 34 |
+
max_distance : float, optional
|
| 35 |
+
Maximum allowed distance between descriptors of two keypoints
|
| 36 |
+
in separate images to be regarded as a match.
|
| 37 |
+
cross_check : bool, optional
|
| 38 |
+
If True, the matched keypoints are returned after cross checking i.e. a
|
| 39 |
+
matched pair (keypoint1, keypoint2) is returned if keypoint2 is the
|
| 40 |
+
best match for keypoint1 in second image and keypoint1 is the best
|
| 41 |
+
match for keypoint2 in first image.
|
| 42 |
+
max_ratio : float, optional
|
| 43 |
+
Maximum ratio of distances between first and second closest descriptor
|
| 44 |
+
in the second set of descriptors. This threshold is useful to filter
|
| 45 |
+
ambiguous matches between the two descriptor sets. The choice of this
|
| 46 |
+
value depends on the statistics of the chosen descriptor, e.g.,
|
| 47 |
+
for SIFT descriptors a value of 0.8 is usually chosen, see
|
| 48 |
+
D.G. Lowe, "Distinctive Image Features from Scale-Invariant Keypoints",
|
| 49 |
+
International Journal of Computer Vision, 2004.
|
| 50 |
+
|
| 51 |
+
Returns
|
| 52 |
+
-------
|
| 53 |
+
matches : (Q, 2) array
|
| 54 |
+
Indices of corresponding matches in first and second set of
|
| 55 |
+
descriptors, where ``matches[:, 0]`` denote the indices in the first
|
| 56 |
+
and ``matches[:, 1]`` the indices in the second set of descriptors.
|
| 57 |
+
|
| 58 |
+
"""
|
| 59 |
+
|
| 60 |
+
if descriptors1.shape[1] != descriptors2.shape[1]:
|
| 61 |
+
raise ValueError("Descriptor length must equal.")
|
| 62 |
+
|
| 63 |
+
if metric is None:
|
| 64 |
+
if np.issubdtype(descriptors1.dtype, bool):
|
| 65 |
+
metric = 'hamming'
|
| 66 |
+
else:
|
| 67 |
+
metric = 'euclidean'
|
| 68 |
+
|
| 69 |
+
kwargs = {}
|
| 70 |
+
# Scipy raises an error if p is passed as an extra argument when it isn't
|
| 71 |
+
# necessary for the chosen metric.
|
| 72 |
+
if metric == 'minkowski':
|
| 73 |
+
kwargs['p'] = p
|
| 74 |
+
distances = cdist(descriptors1, descriptors2, metric=metric, **kwargs)
|
| 75 |
+
|
| 76 |
+
indices1 = np.arange(descriptors1.shape[0])
|
| 77 |
+
indices2 = np.argmin(distances, axis=1)
|
| 78 |
+
|
| 79 |
+
if cross_check:
|
| 80 |
+
matches1 = np.argmin(distances, axis=0)
|
| 81 |
+
mask = indices1 == matches1[indices2]
|
| 82 |
+
indices1 = indices1[mask]
|
| 83 |
+
indices2 = indices2[mask]
|
| 84 |
+
|
| 85 |
+
if max_distance < np.inf:
|
| 86 |
+
mask = distances[indices1, indices2] < max_distance
|
| 87 |
+
indices1 = indices1[mask]
|
| 88 |
+
indices2 = indices2[mask]
|
| 89 |
+
|
| 90 |
+
if max_ratio < 1.0:
|
| 91 |
+
best_distances = distances[indices1, indices2]
|
| 92 |
+
distances[indices1, indices2] = np.inf
|
| 93 |
+
second_best_indices2 = np.argmin(distances[indices1], axis=1)
|
| 94 |
+
second_best_distances = distances[indices1, second_best_indices2]
|
| 95 |
+
second_best_distances[second_best_distances == 0] = np.finfo(np.float64).eps
|
| 96 |
+
ratio = best_distances / second_best_distances
|
| 97 |
+
mask = ratio < max_ratio
|
| 98 |
+
indices1 = indices1[mask]
|
| 99 |
+
indices2 = indices2[mask]
|
| 100 |
+
|
| 101 |
+
matches = np.column_stack((indices1, indices2))
|
| 102 |
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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from ..feature.util import (
|
| 4 |
+
FeatureDetector,
|
| 5 |
+
DescriptorExtractor,
|
| 6 |
+
_mask_border_keypoints,
|
| 7 |
+
_prepare_grayscale_input_2D,
|
| 8 |
+
)
|
| 9 |
+
|
| 10 |
+
from .corner import corner_fast, corner_orientations, corner_peaks, corner_harris
|
| 11 |
+
from ..transform import pyramid_gaussian
|
| 12 |
+
from .._shared.utils import check_nD
|
| 13 |
+
from .._shared.compat import NP_COPY_IF_NEEDED
|
| 14 |
+
|
| 15 |
+
from .orb_cy import _orb_loop
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
OFAST_MASK = np.zeros((31, 31))
|
| 19 |
+
OFAST_UMAX = [15, 15, 15, 15, 14, 14, 14, 13, 13, 12, 11, 10, 9, 8, 6, 3]
|
| 20 |
+
for i in range(-15, 16):
|
| 21 |
+
for j in range(-OFAST_UMAX[abs(i)], OFAST_UMAX[abs(i)] + 1):
|
| 22 |
+
OFAST_MASK[15 + j, 15 + i] = 1
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
class ORB(FeatureDetector, DescriptorExtractor):
|
| 26 |
+
"""Oriented FAST and rotated BRIEF feature detector and binary descriptor
|
| 27 |
+
extractor.
|
| 28 |
+
|
| 29 |
+
Parameters
|
| 30 |
+
----------
|
| 31 |
+
n_keypoints : int, optional
|
| 32 |
+
Number of keypoints to be returned. The function will return the best
|
| 33 |
+
`n_keypoints` according to the Harris corner response if more than
|
| 34 |
+
`n_keypoints` are detected. If not, then all the detected keypoints
|
| 35 |
+
are returned.
|
| 36 |
+
fast_n : int, optional
|
| 37 |
+
The `n` parameter in `skimage.feature.corner_fast`. Minimum number of
|
| 38 |
+
consecutive pixels out of 16 pixels on the circle that should all be
|
| 39 |
+
either brighter or darker w.r.t test-pixel. A point c on the circle is
|
| 40 |
+
darker w.r.t test pixel p if ``Ic < Ip - threshold`` and brighter if
|
| 41 |
+
``Ic > Ip + threshold``. Also stands for the n in ``FAST-n`` corner
|
| 42 |
+
detector.
|
| 43 |
+
fast_threshold : float, optional
|
| 44 |
+
The ``threshold`` parameter in ``feature.corner_fast``. Threshold used
|
| 45 |
+
to decide whether the pixels on the circle are brighter, darker or
|
| 46 |
+
similar w.r.t. the test pixel. Decrease the threshold when more
|
| 47 |
+
corners are desired and vice-versa.
|
| 48 |
+
harris_k : float, optional
|
| 49 |
+
The `k` parameter in `skimage.feature.corner_harris`. Sensitivity
|
| 50 |
+
factor to separate corners from edges, typically in range ``[0, 0.2]``.
|
| 51 |
+
Small values of `k` result in detection of sharp corners.
|
| 52 |
+
downscale : float, optional
|
| 53 |
+
Downscale factor for the image pyramid. Default value 1.2 is chosen so
|
| 54 |
+
that there are more dense scales which enable robust scale invariance
|
| 55 |
+
for a subsequent feature description.
|
| 56 |
+
n_scales : int, optional
|
| 57 |
+
Maximum number of scales from the bottom of the image pyramid to
|
| 58 |
+
extract the features from.
|
| 59 |
+
|
| 60 |
+
Attributes
|
| 61 |
+
----------
|
| 62 |
+
keypoints : (N, 2) array
|
| 63 |
+
Keypoint coordinates as ``(row, col)``.
|
| 64 |
+
scales : (N,) array
|
| 65 |
+
Corresponding scales.
|
| 66 |
+
orientations : (N,) array
|
| 67 |
+
Corresponding orientations in radians.
|
| 68 |
+
responses : (N,) array
|
| 69 |
+
Corresponding Harris corner responses.
|
| 70 |
+
descriptors : (Q, `descriptor_size`) array of dtype bool
|
| 71 |
+
2D array of binary descriptors of size `descriptor_size` for Q
|
| 72 |
+
keypoints after filtering out border keypoints with value at an
|
| 73 |
+
index ``(i, j)`` either being ``True`` or ``False`` representing
|
| 74 |
+
the outcome of the intensity comparison for i-th keypoint on j-th
|
| 75 |
+
decision pixel-pair. It is ``Q == np.sum(mask)``.
|
| 76 |
+
|
| 77 |
+
References
|
| 78 |
+
----------
|
| 79 |
+
.. [1] Ethan Rublee, Vincent Rabaud, Kurt Konolige and Gary Bradski
|
| 80 |
+
"ORB: An efficient alternative to SIFT and SURF"
|
| 81 |
+
http://www.vision.cs.chubu.ac.jp/CV-R/pdf/Rublee_iccv2011.pdf
|
| 82 |
+
|
| 83 |
+
Examples
|
| 84 |
+
--------
|
| 85 |
+
>>> from skimage.feature import ORB, match_descriptors
|
| 86 |
+
>>> img1 = np.zeros((100, 100))
|
| 87 |
+
>>> img2 = np.zeros_like(img1)
|
| 88 |
+
>>> rng = np.random.default_rng(19481137) # do not copy this value
|
| 89 |
+
>>> square = rng.random((20, 20))
|
| 90 |
+
>>> img1[40:60, 40:60] = square
|
| 91 |
+
>>> img2[53:73, 53:73] = square
|
| 92 |
+
>>> detector_extractor1 = ORB(n_keypoints=5)
|
| 93 |
+
>>> detector_extractor2 = ORB(n_keypoints=5)
|
| 94 |
+
>>> detector_extractor1.detect_and_extract(img1)
|
| 95 |
+
>>> detector_extractor2.detect_and_extract(img2)
|
| 96 |
+
>>> matches = match_descriptors(detector_extractor1.descriptors,
|
| 97 |
+
... detector_extractor2.descriptors)
|
| 98 |
+
>>> matches
|
| 99 |
+
array([[0, 0],
|
| 100 |
+
[1, 1],
|
| 101 |
+
[2, 2],
|
| 102 |
+
[3, 4],
|
| 103 |
+
[4, 3]])
|
| 104 |
+
>>> detector_extractor1.keypoints[matches[:, 0]]
|
| 105 |
+
array([[59. , 59. ],
|
| 106 |
+
[40. , 40. ],
|
| 107 |
+
[57. , 40. ],
|
| 108 |
+
[46. , 58. ],
|
| 109 |
+
[58.8, 58.8]])
|
| 110 |
+
>>> detector_extractor2.keypoints[matches[:, 1]]
|
| 111 |
+
array([[72., 72.],
|
| 112 |
+
[53., 53.],
|
| 113 |
+
[70., 53.],
|
| 114 |
+
[59., 71.],
|
| 115 |
+
[72., 72.]])
|
| 116 |
+
|
| 117 |
+
"""
|
| 118 |
+
|
| 119 |
+
def __init__(
|
| 120 |
+
self,
|
| 121 |
+
downscale=1.2,
|
| 122 |
+
n_scales=8,
|
| 123 |
+
n_keypoints=500,
|
| 124 |
+
fast_n=9,
|
| 125 |
+
fast_threshold=0.08,
|
| 126 |
+
harris_k=0.04,
|
| 127 |
+
):
|
| 128 |
+
self.downscale = downscale
|
| 129 |
+
self.n_scales = n_scales
|
| 130 |
+
self.n_keypoints = n_keypoints
|
| 131 |
+
self.fast_n = fast_n
|
| 132 |
+
self.fast_threshold = fast_threshold
|
| 133 |
+
self.harris_k = harris_k
|
| 134 |
+
|
| 135 |
+
self.keypoints = None
|
| 136 |
+
self.scales = None
|
| 137 |
+
self.responses = None
|
| 138 |
+
self.orientations = None
|
| 139 |
+
self.descriptors = None
|
| 140 |
+
|
| 141 |
+
def _build_pyramid(self, image):
|
| 142 |
+
image = _prepare_grayscale_input_2D(image)
|
| 143 |
+
return list(
|
| 144 |
+
pyramid_gaussian(
|
| 145 |
+
image, self.n_scales - 1, self.downscale, channel_axis=None
|
| 146 |
+
)
|
| 147 |
+
)
|
| 148 |
+
|
| 149 |
+
def _detect_octave(self, octave_image):
|
| 150 |
+
dtype = octave_image.dtype
|
| 151 |
+
# Extract keypoints for current octave
|
| 152 |
+
fast_response = corner_fast(octave_image, self.fast_n, self.fast_threshold)
|
| 153 |
+
keypoints = corner_peaks(fast_response, min_distance=1)
|
| 154 |
+
|
| 155 |
+
if len(keypoints) == 0:
|
| 156 |
+
return (
|
| 157 |
+
np.zeros((0, 2), dtype=dtype),
|
| 158 |
+
np.zeros((0,), dtype=dtype),
|
| 159 |
+
np.zeros((0,), dtype=dtype),
|
| 160 |
+
)
|
| 161 |
+
|
| 162 |
+
mask = _mask_border_keypoints(octave_image.shape, keypoints, distance=16)
|
| 163 |
+
keypoints = keypoints[mask]
|
| 164 |
+
|
| 165 |
+
orientations = corner_orientations(octave_image, keypoints, OFAST_MASK)
|
| 166 |
+
|
| 167 |
+
harris_response = corner_harris(octave_image, method='k', k=self.harris_k)
|
| 168 |
+
responses = harris_response[keypoints[:, 0], keypoints[:, 1]]
|
| 169 |
+
|
| 170 |
+
return keypoints, orientations, responses
|
| 171 |
+
|
| 172 |
+
def detect(self, image):
|
| 173 |
+
"""Detect oriented FAST keypoints along with the corresponding scale.
|
| 174 |
+
|
| 175 |
+
Parameters
|
| 176 |
+
----------
|
| 177 |
+
image : 2D array
|
| 178 |
+
Input image.
|
| 179 |
+
|
| 180 |
+
"""
|
| 181 |
+
check_nD(image, 2)
|
| 182 |
+
|
| 183 |
+
pyramid = self._build_pyramid(image)
|
| 184 |
+
|
| 185 |
+
keypoints_list = []
|
| 186 |
+
orientations_list = []
|
| 187 |
+
scales_list = []
|
| 188 |
+
responses_list = []
|
| 189 |
+
|
| 190 |
+
for octave in range(len(pyramid)):
|
| 191 |
+
octave_image = np.ascontiguousarray(pyramid[octave])
|
| 192 |
+
|
| 193 |
+
if np.squeeze(octave_image).ndim < 2:
|
| 194 |
+
# No further keypoints can be detected if the image is not really 2d
|
| 195 |
+
break
|
| 196 |
+
|
| 197 |
+
keypoints, orientations, responses = self._detect_octave(octave_image)
|
| 198 |
+
|
| 199 |
+
keypoints_list.append(keypoints * self.downscale**octave)
|
| 200 |
+
orientations_list.append(orientations)
|
| 201 |
+
scales_list.append(
|
| 202 |
+
np.full(
|
| 203 |
+
keypoints.shape[0],
|
| 204 |
+
self.downscale**octave,
|
| 205 |
+
dtype=octave_image.dtype,
|
| 206 |
+
)
|
| 207 |
+
)
|
| 208 |
+
responses_list.append(responses)
|
| 209 |
+
|
| 210 |
+
keypoints = np.vstack(keypoints_list)
|
| 211 |
+
orientations = np.hstack(orientations_list)
|
| 212 |
+
scales = np.hstack(scales_list)
|
| 213 |
+
responses = np.hstack(responses_list)
|
| 214 |
+
|
| 215 |
+
if keypoints.shape[0] < self.n_keypoints:
|
| 216 |
+
self.keypoints = keypoints
|
| 217 |
+
self.scales = scales
|
| 218 |
+
self.orientations = orientations
|
| 219 |
+
self.responses = responses
|
| 220 |
+
else:
|
| 221 |
+
# Choose best n_keypoints according to Harris corner response
|
| 222 |
+
best_indices = responses.argsort()[::-1][: self.n_keypoints]
|
| 223 |
+
self.keypoints = keypoints[best_indices]
|
| 224 |
+
self.scales = scales[best_indices]
|
| 225 |
+
self.orientations = orientations[best_indices]
|
| 226 |
+
self.responses = responses[best_indices]
|
| 227 |
+
|
| 228 |
+
def _extract_octave(self, octave_image, keypoints, orientations):
|
| 229 |
+
mask = _mask_border_keypoints(octave_image.shape, keypoints, distance=20)
|
| 230 |
+
keypoints = np.array(
|
| 231 |
+
keypoints[mask], dtype=np.intp, order='C', copy=NP_COPY_IF_NEEDED
|
| 232 |
+
)
|
| 233 |
+
orientations = np.array(orientations[mask], order='C', copy=False)
|
| 234 |
+
|
| 235 |
+
descriptors = _orb_loop(octave_image, keypoints, orientations)
|
| 236 |
+
|
| 237 |
+
return descriptors, mask
|
| 238 |
+
|
| 239 |
+
def extract(self, image, keypoints, scales, orientations):
|
| 240 |
+
"""Extract rBRIEF binary descriptors for given keypoints in image.
|
| 241 |
+
|
| 242 |
+
Note that the keypoints must be extracted using the same `downscale`
|
| 243 |
+
and `n_scales` parameters. Additionally, if you want to extract both
|
| 244 |
+
keypoints and descriptors you should use the faster
|
| 245 |
+
`detect_and_extract`.
|
| 246 |
+
|
| 247 |
+
Parameters
|
| 248 |
+
----------
|
| 249 |
+
image : 2D array
|
| 250 |
+
Input image.
|
| 251 |
+
keypoints : (N, 2) array
|
| 252 |
+
Keypoint coordinates as ``(row, col)``.
|
| 253 |
+
scales : (N,) array
|
| 254 |
+
Corresponding scales.
|
| 255 |
+
orientations : (N,) array
|
| 256 |
+
Corresponding orientations in radians.
|
| 257 |
+
|
| 258 |
+
"""
|
| 259 |
+
check_nD(image, 2)
|
| 260 |
+
|
| 261 |
+
pyramid = self._build_pyramid(image)
|
| 262 |
+
|
| 263 |
+
descriptors_list = []
|
| 264 |
+
mask_list = []
|
| 265 |
+
|
| 266 |
+
# Determine octaves from scales
|
| 267 |
+
octaves = (np.log(scales) / np.log(self.downscale)).astype(np.intp)
|
| 268 |
+
|
| 269 |
+
for octave in range(len(pyramid)):
|
| 270 |
+
# Mask for all keypoints in current octave
|
| 271 |
+
octave_mask = octaves == octave
|
| 272 |
+
|
| 273 |
+
if np.sum(octave_mask) > 0:
|
| 274 |
+
octave_image = np.ascontiguousarray(pyramid[octave])
|
| 275 |
+
|
| 276 |
+
octave_keypoints = keypoints[octave_mask]
|
| 277 |
+
octave_keypoints /= self.downscale**octave
|
| 278 |
+
octave_orientations = orientations[octave_mask]
|
| 279 |
+
|
| 280 |
+
descriptors, mask = self._extract_octave(
|
| 281 |
+
octave_image, octave_keypoints, octave_orientations
|
| 282 |
+
)
|
| 283 |
+
|
| 284 |
+
descriptors_list.append(descriptors)
|
| 285 |
+
mask_list.append(mask)
|
| 286 |
+
|
| 287 |
+
self.descriptors = np.vstack(descriptors_list).view(bool)
|
| 288 |
+
self.mask_ = np.hstack(mask_list)
|
| 289 |
+
|
| 290 |
+
def detect_and_extract(self, image):
|
| 291 |
+
"""Detect oriented FAST keypoints and extract rBRIEF descriptors.
|
| 292 |
+
|
| 293 |
+
Note that this is faster than first calling `detect` and then
|
| 294 |
+
`extract`.
|
| 295 |
+
|
| 296 |
+
Parameters
|
| 297 |
+
----------
|
| 298 |
+
image : 2D array
|
| 299 |
+
Input image.
|
| 300 |
+
|
| 301 |
+
"""
|
| 302 |
+
check_nD(image, 2)
|
| 303 |
+
|
| 304 |
+
pyramid = self._build_pyramid(image)
|
| 305 |
+
|
| 306 |
+
keypoints_list = []
|
| 307 |
+
responses_list = []
|
| 308 |
+
scales_list = []
|
| 309 |
+
orientations_list = []
|
| 310 |
+
descriptors_list = []
|
| 311 |
+
|
| 312 |
+
for octave in range(len(pyramid)):
|
| 313 |
+
octave_image = np.ascontiguousarray(pyramid[octave])
|
| 314 |
+
|
| 315 |
+
if np.squeeze(octave_image).ndim < 2:
|
| 316 |
+
# No further keypoints can be detected if the image is not really 2d
|
| 317 |
+
break
|
| 318 |
+
|
| 319 |
+
keypoints, orientations, responses = self._detect_octave(octave_image)
|
| 320 |
+
|
| 321 |
+
if len(keypoints) == 0:
|
| 322 |
+
keypoints_list.append(keypoints)
|
| 323 |
+
responses_list.append(responses)
|
| 324 |
+
descriptors_list.append(np.zeros((0, 256), dtype=bool))
|
| 325 |
+
continue
|
| 326 |
+
|
| 327 |
+
descriptors, mask = self._extract_octave(
|
| 328 |
+
octave_image, keypoints, orientations
|
| 329 |
+
)
|
| 330 |
+
|
| 331 |
+
scaled_keypoints = keypoints[mask] * self.downscale**octave
|
| 332 |
+
keypoints_list.append(scaled_keypoints)
|
| 333 |
+
responses_list.append(responses[mask])
|
| 334 |
+
orientations_list.append(orientations[mask])
|
| 335 |
+
scales_list.append(
|
| 336 |
+
self.downscale**octave
|
| 337 |
+
* np.ones(scaled_keypoints.shape[0], dtype=np.intp)
|
| 338 |
+
)
|
| 339 |
+
descriptors_list.append(descriptors)
|
| 340 |
+
|
| 341 |
+
if len(scales_list) == 0:
|
| 342 |
+
raise RuntimeError(
|
| 343 |
+
"ORB found no features. Try passing in an image containing "
|
| 344 |
+
"greater intensity contrasts between adjacent pixels."
|
| 345 |
+
)
|
| 346 |
+
|
| 347 |
+
keypoints = np.vstack(keypoints_list)
|
| 348 |
+
responses = np.hstack(responses_list)
|
| 349 |
+
scales = np.hstack(scales_list)
|
| 350 |
+
orientations = np.hstack(orientations_list)
|
| 351 |
+
descriptors = np.vstack(descriptors_list).view(bool)
|
| 352 |
+
|
| 353 |
+
if keypoints.shape[0] < self.n_keypoints:
|
| 354 |
+
self.keypoints = keypoints
|
| 355 |
+
self.scales = scales
|
| 356 |
+
self.orientations = orientations
|
| 357 |
+
self.responses = responses
|
| 358 |
+
self.descriptors = descriptors
|
| 359 |
+
else:
|
| 360 |
+
# Choose best n_keypoints according to Harris corner response
|
| 361 |
+
best_indices = responses.argsort()[::-1][: self.n_keypoints]
|
| 362 |
+
self.keypoints = keypoints[best_indices]
|
| 363 |
+
self.scales = scales[best_indices]
|
| 364 |
+
self.orientations = orientations[best_indices]
|
| 365 |
+
self.responses = responses[best_indices]
|
| 366 |
+
self.descriptors = descriptors[best_indices]
|
envs/kitoverlay/skimage/feature/orb_descriptor_positions.txt
ADDED
|
@@ -0,0 +1,256 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
-11 7 -9 12
|
| 13 |
+
7 7 12 6
|
| 14 |
+
-4 -5 -3 0
|
| 15 |
+
-13 2 -12 -3
|
| 16 |
+
-9 0 -7 5
|
| 17 |
+
12 -6 12 -1
|
| 18 |
+
-3 6 -2 12
|
| 19 |
+
-6 -13 -4 -8
|
| 20 |
+
11 -13 12 -8
|
| 21 |
+
4 7 5 1
|
| 22 |
+
5 -3 10 -3
|
| 23 |
+
3 -7 6 12
|
| 24 |
+
-8 -7 -6 -2
|
| 25 |
+
-2 11 -1 -10
|
| 26 |
+
-13 12 -8 10
|
| 27 |
+
-7 3 -5 -3
|
| 28 |
+
-4 2 -3 7
|
| 29 |
+
-10 -12 -6 11
|
| 30 |
+
5 -12 6 -7
|
| 31 |
+
5 -6 7 -1
|
| 32 |
+
1 0 4 -5
|
| 33 |
+
9 11 11 -13
|
| 34 |
+
4 7 4 12
|
| 35 |
+
2 -1 4 4
|
| 36 |
+
-4 -12 -2 7
|
| 37 |
+
-8 -5 -7 -10
|
| 38 |
+
4 11 9 12
|
| 39 |
+
0 -8 1 -13
|
| 40 |
+
-13 -2 -8 2
|
| 41 |
+
-3 -2 -2 3
|
| 42 |
+
-6 9 -4 -9
|
| 43 |
+
8 12 10 7
|
| 44 |
+
0 9 1 3
|
| 45 |
+
7 -5 11 -10
|
| 46 |
+
-13 -6 -11 0
|
| 47 |
+
10 7 12 1
|
| 48 |
+
-6 -3 -6 12
|
| 49 |
+
10 -9 12 -4
|
| 50 |
+
-13 8 -8 -12
|
| 51 |
+
-13 0 -8 -4
|
| 52 |
+
3 3 7 8
|
| 53 |
+
5 7 10 -7
|
| 54 |
+
-1 7 1 -12
|
| 55 |
+
3 -10 5 6
|
| 56 |
+
2 -4 3 -10
|
| 57 |
+
-13 0 -13 5
|
| 58 |
+
-13 -7 -12 12
|
| 59 |
+
-13 3 -11 8
|
| 60 |
+
-7 12 -4 7
|
| 61 |
+
6 -10 12 8
|
| 62 |
+
-9 -1 -7 -6
|
| 63 |
+
-2 -5 0 12
|
| 64 |
+
-12 5 -7 5
|
| 65 |
+
3 -10 8 -13
|
| 66 |
+
-7 -7 -4 5
|
| 67 |
+
-3 -2 -1 -7
|
| 68 |
+
2 9 5 -11
|
| 69 |
+
-11 -13 -5 -13
|
| 70 |
+
-1 6 0 -1
|
| 71 |
+
5 -3 5 2
|
| 72 |
+
-4 -13 -4 12
|
| 73 |
+
-9 -6 -9 6
|
| 74 |
+
-12 -10 -8 -4
|
| 75 |
+
10 2 12 -3
|
| 76 |
+
7 12 12 12
|
| 77 |
+
-7 -13 -6 5
|
| 78 |
+
-4 9 -3 4
|
| 79 |
+
7 -1 12 2
|
| 80 |
+
-7 6 -5 1
|
| 81 |
+
-13 11 -12 5
|
| 82 |
+
-3 7 -2 -6
|
| 83 |
+
7 -8 12 -7
|
| 84 |
+
-13 -7 -11 -12
|
| 85 |
+
1 -3 12 12
|
| 86 |
+
2 -6 3 0
|
| 87 |
+
-4 3 -2 -13
|
| 88 |
+
-1 -13 1 9
|
| 89 |
+
7 1 8 -6
|
| 90 |
+
1 -1 3 12
|
| 91 |
+
9 1 12 6
|
| 92 |
+
-1 -9 -1 3
|
| 93 |
+
-13 -13 -10 5
|
| 94 |
+
7 7 10 12
|
| 95 |
+
12 -5 12 9
|
| 96 |
+
6 3 7 11
|
| 97 |
+
5 -13 6 10
|
| 98 |
+
2 -12 2 3
|
| 99 |
+
3 8 4 -6
|
| 100 |
+
2 6 12 -13
|
| 101 |
+
9 -12 10 3
|
| 102 |
+
-8 4 -7 9
|
| 103 |
+
-11 12 -4 -6
|
| 104 |
+
1 12 2 -8
|
| 105 |
+
6 -9 7 -4
|
| 106 |
+
2 3 3 -2
|
| 107 |
+
6 3 11 0
|
| 108 |
+
3 -3 8 -8
|
| 109 |
+
7 8 9 3
|
| 110 |
+
-11 -5 -6 -4
|
| 111 |
+
-10 11 -5 10
|
| 112 |
+
-5 -8 -3 12
|
| 113 |
+
-10 5 -9 0
|
| 114 |
+
8 -1 12 -6
|
| 115 |
+
4 -6 6 -11
|
| 116 |
+
-10 12 -8 7
|
| 117 |
+
4 -2 6 7
|
| 118 |
+
-2 0 -2 12
|
| 119 |
+
-5 -8 -5 2
|
| 120 |
+
7 -6 10 12
|
| 121 |
+
-9 -13 -8 -8
|
| 122 |
+
-5 -13 -5 -2
|
| 123 |
+
8 -8 9 -13
|
| 124 |
+
-9 -11 -9 0
|
| 125 |
+
1 -8 1 -2
|
| 126 |
+
7 -4 9 1
|
| 127 |
+
-2 1 -1 -4
|
| 128 |
+
11 -6 12 -11
|
| 129 |
+
-12 -9 -6 4
|
| 130 |
+
3 7 7 12
|
| 131 |
+
5 5 10 8
|
| 132 |
+
0 -4 2 8
|
| 133 |
+
-9 12 -5 -13
|
| 134 |
+
0 7 2 12
|
| 135 |
+
-1 2 1 7
|
| 136 |
+
5 11 7 -9
|
| 137 |
+
3 5 6 -8
|
| 138 |
+
-13 -4 -8 9
|
| 139 |
+
-5 9 -3 -3
|
| 140 |
+
-4 -7 -3 -12
|
| 141 |
+
6 5 8 0
|
| 142 |
+
-7 6 -6 12
|
| 143 |
+
-13 6 -5 -2
|
| 144 |
+
1 -10 3 10
|
| 145 |
+
4 1 8 -4
|
| 146 |
+
-2 -2 2 -13
|
| 147 |
+
2 -12 12 12
|
| 148 |
+
-2 -13 0 -6
|
| 149 |
+
4 1 9 3
|
| 150 |
+
-6 -10 -3 -5
|
| 151 |
+
-3 -13 -1 1
|
| 152 |
+
7 5 12 -11
|
| 153 |
+
4 -2 5 -7
|
| 154 |
+
-13 9 -9 -5
|
| 155 |
+
7 1 8 6
|
| 156 |
+
7 -8 7 6
|
| 157 |
+
-7 -4 -7 1
|
| 158 |
+
-8 11 -7 -8
|
| 159 |
+
-13 6 -12 -8
|
| 160 |
+
2 4 3 9
|
| 161 |
+
10 -5 12 3
|
| 162 |
+
-6 -5 -6 7
|
| 163 |
+
8 -3 9 -8
|
| 164 |
+
2 -12 2 8
|
| 165 |
+
-11 -2 -10 3
|
| 166 |
+
-12 -13 -7 -9
|
| 167 |
+
-11 0 -10 -5
|
| 168 |
+
5 -3 11 8
|
| 169 |
+
-2 -13 -1 12
|
| 170 |
+
-1 -8 0 9
|
| 171 |
+
-13 -11 -12 -5
|
| 172 |
+
-10 -2 -10 11
|
| 173 |
+
-3 9 -2 -13
|
| 174 |
+
2 -3 3 2
|
| 175 |
+
-9 -13 -4 0
|
| 176 |
+
-4 6 -3 -10
|
| 177 |
+
-4 12 -2 -7
|
| 178 |
+
-6 -11 -4 9
|
| 179 |
+
6 -3 6 11
|
| 180 |
+
-13 11 -5 5
|
| 181 |
+
11 11 12 6
|
| 182 |
+
7 -5 12 -2
|
| 183 |
+
-1 12 0 7
|
| 184 |
+
-4 -8 -3 -2
|
| 185 |
+
-7 1 -6 7
|
| 186 |
+
-13 -12 -8 -13
|
| 187 |
+
-7 -2 -6 -8
|
| 188 |
+
-8 5 -6 -9
|
| 189 |
+
-5 -1 -4 5
|
| 190 |
+
-13 7 -8 10
|
| 191 |
+
1 5 5 -13
|
| 192 |
+
1 0 10 -13
|
| 193 |
+
9 12 10 -1
|
| 194 |
+
5 -8 10 -9
|
| 195 |
+
-1 11 1 -13
|
| 196 |
+
-9 -3 -6 2
|
| 197 |
+
-1 -10 1 12
|
| 198 |
+
-13 1 -8 -10
|
| 199 |
+
8 -11 10 -6
|
| 200 |
+
2 -13 3 -6
|
| 201 |
+
7 -13 12 -9
|
| 202 |
+
-10 -10 -5 -7
|
| 203 |
+
-10 -8 -8 -13
|
| 204 |
+
4 -6 8 5
|
| 205 |
+
3 12 8 -13
|
| 206 |
+
-4 2 -3 -3
|
| 207 |
+
5 -13 10 -12
|
| 208 |
+
4 -13 5 -1
|
| 209 |
+
-9 9 -4 3
|
| 210 |
+
0 3 3 -9
|
| 211 |
+
-12 1 -6 1
|
| 212 |
+
3 2 4 -8
|
| 213 |
+
-10 -10 -10 9
|
| 214 |
+
8 -13 12 12
|
| 215 |
+
-8 -12 -6 -5
|
| 216 |
+
2 2 3 7
|
| 217 |
+
10 6 11 -8
|
| 218 |
+
6 8 8 -12
|
| 219 |
+
-7 10 -6 5
|
| 220 |
+
-3 -9 -3 9
|
| 221 |
+
-1 -13 -1 5
|
| 222 |
+
-3 -7 -3 4
|
| 223 |
+
-8 -2 -8 3
|
| 224 |
+
4 2 12 12
|
| 225 |
+
2 -5 3 11
|
| 226 |
+
6 -9 11 -13
|
| 227 |
+
3 -1 7 12
|
| 228 |
+
11 -1 12 4
|
| 229 |
+
-3 0 -3 6
|
| 230 |
+
4 -11 4 12
|
| 231 |
+
2 -4 2 1
|
| 232 |
+
-10 -6 -8 1
|
| 233 |
+
-13 7 -11 1
|
| 234 |
+
-13 12 -11 -13
|
| 235 |
+
6 0 11 -13
|
| 236 |
+
0 -1 1 4
|
| 237 |
+
-13 3 -9 -2
|
| 238 |
+
-9 8 -6 -3
|
| 239 |
+
-13 -6 -8 -2
|
| 240 |
+
5 -9 8 10
|
| 241 |
+
2 7 3 -9
|
| 242 |
+
-1 -6 -1 -1
|
| 243 |
+
9 5 11 -2
|
| 244 |
+
11 -3 12 -8
|
| 245 |
+
3 0 3 5
|
| 246 |
+
-1 4 0 10
|
| 247 |
+
3 -6 4 5
|
| 248 |
+
-13 0 -10 5
|
| 249 |
+
5 8 12 11
|
| 250 |
+
8 9 9 -6
|
| 251 |
+
7 -4 8 -12
|
| 252 |
+
-10 4 -10 9
|
| 253 |
+
7 3 12 4
|
| 254 |
+
9 -7 10 -2
|
| 255 |
+
7 0 12 -2
|
| 256 |
+
-1 -6 0 -11
|
envs/kitoverlay/skimage/feature/peak.py
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from warnings import warn
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import scipy.ndimage as ndi
|
| 5 |
+
|
| 6 |
+
from .. import measure
|
| 7 |
+
from .._shared.coord import ensure_spacing
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
def _get_high_intensity_peaks(image, mask, num_peaks, min_distance, p_norm):
|
| 11 |
+
"""
|
| 12 |
+
Return the highest intensity peak coordinates.
|
| 13 |
+
"""
|
| 14 |
+
# get coordinates of peaks
|
| 15 |
+
coord = np.nonzero(mask)
|
| 16 |
+
intensities = image[coord]
|
| 17 |
+
# Highest peak first
|
| 18 |
+
idx_maxsort = np.argsort(-intensities, kind="stable")
|
| 19 |
+
coord = np.transpose(coord)[idx_maxsort]
|
| 20 |
+
|
| 21 |
+
if np.isfinite(num_peaks):
|
| 22 |
+
max_out = int(num_peaks)
|
| 23 |
+
else:
|
| 24 |
+
max_out = None
|
| 25 |
+
|
| 26 |
+
if min_distance > 1:
|
| 27 |
+
coord = ensure_spacing(
|
| 28 |
+
coord, spacing=min_distance, p_norm=p_norm, max_out=max_out
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
if len(coord) > num_peaks:
|
| 32 |
+
coord = coord[:num_peaks]
|
| 33 |
+
|
| 34 |
+
return coord
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
def _get_peak_mask(image, footprint, threshold, mask=None):
|
| 38 |
+
"""
|
| 39 |
+
Return the mask containing all peak candidates above thresholds.
|
| 40 |
+
"""
|
| 41 |
+
if footprint.size == 1 or image.size == 1:
|
| 42 |
+
return image > threshold
|
| 43 |
+
|
| 44 |
+
image_max = ndi.maximum_filter(image, footprint=footprint, mode='nearest')
|
| 45 |
+
|
| 46 |
+
out = image == image_max
|
| 47 |
+
|
| 48 |
+
# no peak for a trivial image
|
| 49 |
+
image_is_trivial = np.all(out) if mask is None else np.all(out[mask])
|
| 50 |
+
if image_is_trivial:
|
| 51 |
+
out[:] = False
|
| 52 |
+
if mask is not None:
|
| 53 |
+
# isolated pixels in masked area are returned as peaks
|
| 54 |
+
isolated_px = np.logical_xor(mask, ndi.binary_opening(mask))
|
| 55 |
+
out[isolated_px] = True
|
| 56 |
+
|
| 57 |
+
out &= image > threshold
|
| 58 |
+
return out
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def _exclude_border(label, border_width):
|
| 62 |
+
"""Set label border values to 0."""
|
| 63 |
+
# zero out label borders
|
| 64 |
+
for i, width in enumerate(border_width):
|
| 65 |
+
if width == 0:
|
| 66 |
+
continue
|
| 67 |
+
label[(slice(None),) * i + (slice(None, width),)] = 0
|
| 68 |
+
label[(slice(None),) * i + (slice(-width, None),)] = 0
|
| 69 |
+
return label
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def _get_threshold(image, threshold_abs, threshold_rel):
|
| 73 |
+
"""Return the threshold value according to an absolute and a relative
|
| 74 |
+
value.
|
| 75 |
+
|
| 76 |
+
"""
|
| 77 |
+
threshold = threshold_abs if threshold_abs is not None else image.min()
|
| 78 |
+
|
| 79 |
+
if threshold_rel is not None:
|
| 80 |
+
threshold = max(threshold, threshold_rel * image.max())
|
| 81 |
+
|
| 82 |
+
return threshold
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def _get_excluded_border_width(image, min_distance, exclude_border):
|
| 86 |
+
"""Return border_width values relative to a min_distance if requested."""
|
| 87 |
+
|
| 88 |
+
if isinstance(exclude_border, bool):
|
| 89 |
+
border_width = (min_distance if exclude_border else 0,) * image.ndim
|
| 90 |
+
elif isinstance(exclude_border, int):
|
| 91 |
+
if exclude_border < 0:
|
| 92 |
+
raise ValueError("`exclude_border` cannot be a negative value")
|
| 93 |
+
border_width = (exclude_border,) * image.ndim
|
| 94 |
+
elif isinstance(exclude_border, tuple):
|
| 95 |
+
if len(exclude_border) != image.ndim:
|
| 96 |
+
raise ValueError(
|
| 97 |
+
"`exclude_border` should have the same length as the "
|
| 98 |
+
"dimensionality of the image."
|
| 99 |
+
)
|
| 100 |
+
for exclude in exclude_border:
|
| 101 |
+
if not isinstance(exclude, int):
|
| 102 |
+
raise ValueError(
|
| 103 |
+
"`exclude_border`, when expressed as a tuple, must only "
|
| 104 |
+
"contain ints."
|
| 105 |
+
)
|
| 106 |
+
if exclude < 0:
|
| 107 |
+
raise ValueError("`exclude_border` can not be a negative value")
|
| 108 |
+
border_width = exclude_border
|
| 109 |
+
else:
|
| 110 |
+
raise TypeError(
|
| 111 |
+
"`exclude_border` must be bool, int, or tuple with the same "
|
| 112 |
+
"length as the dimensionality of the image."
|
| 113 |
+
)
|
| 114 |
+
|
| 115 |
+
return border_width
|
| 116 |
+
|
| 117 |
+
|
| 118 |
+
def peak_local_max(
|
| 119 |
+
image,
|
| 120 |
+
min_distance=1,
|
| 121 |
+
threshold_abs=None,
|
| 122 |
+
threshold_rel=None,
|
| 123 |
+
exclude_border=True,
|
| 124 |
+
num_peaks=np.inf,
|
| 125 |
+
footprint=None,
|
| 126 |
+
labels=None,
|
| 127 |
+
num_peaks_per_label=np.inf,
|
| 128 |
+
p_norm=np.inf,
|
| 129 |
+
):
|
| 130 |
+
"""Find peaks in an image as coordinate list.
|
| 131 |
+
|
| 132 |
+
Peaks are the local maxima in a region of `2 * min_distance + 1`
|
| 133 |
+
(i.e. peaks are separated by at least `min_distance`).
|
| 134 |
+
|
| 135 |
+
If both `threshold_abs` and `threshold_rel` are provided, the maximum
|
| 136 |
+
of the two is chosen as the minimum intensity threshold of peaks.
|
| 137 |
+
|
| 138 |
+
.. versionchanged:: 0.18
|
| 139 |
+
Prior to version 0.18, peaks of the same height within a radius of
|
| 140 |
+
`min_distance` were all returned, but this could cause unexpected
|
| 141 |
+
behaviour. From 0.18 onwards, an arbitrary peak within the region is
|
| 142 |
+
returned. See issue gh-2592.
|
| 143 |
+
|
| 144 |
+
Parameters
|
| 145 |
+
----------
|
| 146 |
+
image : ndarray
|
| 147 |
+
Input image.
|
| 148 |
+
min_distance : int, optional
|
| 149 |
+
The minimal allowed distance separating peaks. To find the
|
| 150 |
+
maximum number of peaks, use `min_distance=1`.
|
| 151 |
+
threshold_abs : float or None, optional
|
| 152 |
+
Minimum intensity of peaks. By default, the absolute threshold is
|
| 153 |
+
the minimum intensity of the image.
|
| 154 |
+
threshold_rel : float or None, optional
|
| 155 |
+
Minimum intensity of peaks, calculated as
|
| 156 |
+
``max(image) * threshold_rel``.
|
| 157 |
+
exclude_border : int, tuple of ints, or bool, optional
|
| 158 |
+
If positive integer, `exclude_border` excludes peaks from within
|
| 159 |
+
`exclude_border`-pixels of the border of the image.
|
| 160 |
+
If tuple of non-negative ints, the length of the tuple must match the
|
| 161 |
+
input array's dimensionality. Each element of the tuple will exclude
|
| 162 |
+
peaks from within `exclude_border`-pixels of the border of the image
|
| 163 |
+
along that dimension.
|
| 164 |
+
If True, takes the `min_distance` parameter as value.
|
| 165 |
+
If zero or False, peaks are identified regardless of their distance
|
| 166 |
+
from the border.
|
| 167 |
+
num_peaks : int, optional
|
| 168 |
+
Maximum number of peaks. When the number of peaks exceeds `num_peaks`,
|
| 169 |
+
return `num_peaks` peaks based on highest peak intensity.
|
| 170 |
+
footprint : ndarray of bools, optional
|
| 171 |
+
If provided, `footprint == 1` represents the local region within which
|
| 172 |
+
to search for peaks at every point in `image`.
|
| 173 |
+
labels : ndarray of ints, optional
|
| 174 |
+
If provided, each unique region `labels == value` represents a unique
|
| 175 |
+
region to search for peaks. Zero is reserved for background.
|
| 176 |
+
num_peaks_per_label : int, optional
|
| 177 |
+
Maximum number of peaks for each label.
|
| 178 |
+
p_norm : float
|
| 179 |
+
Which Minkowski p-norm to use. Should be in the range [1, inf].
|
| 180 |
+
A finite large p may cause a ValueError if overflow can occur.
|
| 181 |
+
``inf`` corresponds to the Chebyshev distance and 2 to the
|
| 182 |
+
Euclidean distance.
|
| 183 |
+
|
| 184 |
+
Returns
|
| 185 |
+
-------
|
| 186 |
+
output : ndarray
|
| 187 |
+
The coordinates of the peaks.
|
| 188 |
+
|
| 189 |
+
Notes
|
| 190 |
+
-----
|
| 191 |
+
The peak local maximum function returns the coordinates of local peaks
|
| 192 |
+
(maxima) in an image. Internally, a maximum filter is used for finding
|
| 193 |
+
local maxima. This operation dilates the original image. After comparison
|
| 194 |
+
of the dilated and original images, this function returns the coordinates
|
| 195 |
+
of the peaks where the dilated image equals the original image.
|
| 196 |
+
|
| 197 |
+
See also
|
| 198 |
+
--------
|
| 199 |
+
skimage.feature.corner_peaks
|
| 200 |
+
|
| 201 |
+
Examples
|
| 202 |
+
--------
|
| 203 |
+
>>> img1 = np.zeros((7, 7))
|
| 204 |
+
>>> img1[3, 4] = 1
|
| 205 |
+
>>> img1[3, 2] = 1.5
|
| 206 |
+
>>> img1
|
| 207 |
+
array([[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
|
| 208 |
+
[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
|
| 209 |
+
[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
|
| 210 |
+
[0. , 0. , 1.5, 0. , 1. , 0. , 0. ],
|
| 211 |
+
[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
|
| 212 |
+
[0. , 0. , 0. , 0. , 0. , 0. , 0. ],
|
| 213 |
+
[0. , 0. , 0. , 0. , 0. , 0. , 0. ]])
|
| 214 |
+
|
| 215 |
+
>>> peak_local_max(img1, min_distance=1)
|
| 216 |
+
array([[3, 2],
|
| 217 |
+
[3, 4]])
|
| 218 |
+
|
| 219 |
+
>>> peak_local_max(img1, min_distance=2)
|
| 220 |
+
array([[3, 2]])
|
| 221 |
+
|
| 222 |
+
>>> img2 = np.zeros((20, 20, 20))
|
| 223 |
+
>>> img2[10, 10, 10] = 1
|
| 224 |
+
>>> img2[15, 15, 15] = 1
|
| 225 |
+
>>> peak_idx = peak_local_max(img2, exclude_border=0)
|
| 226 |
+
>>> peak_idx
|
| 227 |
+
array([[10, 10, 10],
|
| 228 |
+
[15, 15, 15]])
|
| 229 |
+
|
| 230 |
+
>>> peak_mask = np.zeros_like(img2, dtype=bool)
|
| 231 |
+
>>> peak_mask[tuple(peak_idx.T)] = True
|
| 232 |
+
>>> np.argwhere(peak_mask)
|
| 233 |
+
array([[10, 10, 10],
|
| 234 |
+
[15, 15, 15]])
|
| 235 |
+
|
| 236 |
+
"""
|
| 237 |
+
if (footprint is None or footprint.size == 1) and min_distance < 1:
|
| 238 |
+
warn(
|
| 239 |
+
"When min_distance < 1, peak_local_max acts as finding "
|
| 240 |
+
"image > max(threshold_abs, threshold_rel * max(image)).",
|
| 241 |
+
RuntimeWarning,
|
| 242 |
+
stacklevel=2,
|
| 243 |
+
)
|
| 244 |
+
|
| 245 |
+
border_width = _get_excluded_border_width(image, min_distance, exclude_border)
|
| 246 |
+
|
| 247 |
+
threshold = _get_threshold(image, threshold_abs, threshold_rel)
|
| 248 |
+
|
| 249 |
+
if footprint is None:
|
| 250 |
+
size = 2 * min_distance + 1
|
| 251 |
+
footprint = np.ones((size,) * image.ndim, dtype=bool)
|
| 252 |
+
else:
|
| 253 |
+
footprint = np.asarray(footprint)
|
| 254 |
+
|
| 255 |
+
if labels is None:
|
| 256 |
+
# Non maximum filter
|
| 257 |
+
mask = _get_peak_mask(image, footprint, threshold)
|
| 258 |
+
|
| 259 |
+
mask = _exclude_border(mask, border_width)
|
| 260 |
+
|
| 261 |
+
# Select highest intensities (num_peaks)
|
| 262 |
+
coordinates = _get_high_intensity_peaks(
|
| 263 |
+
image, mask, num_peaks, min_distance, p_norm
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
else:
|
| 267 |
+
_labels = _exclude_border(labels.astype(int, casting="safe"), border_width)
|
| 268 |
+
|
| 269 |
+
if np.issubdtype(image.dtype, np.floating):
|
| 270 |
+
bg_val = np.finfo(image.dtype).min
|
| 271 |
+
else:
|
| 272 |
+
bg_val = np.iinfo(image.dtype).min
|
| 273 |
+
|
| 274 |
+
# For each label, extract a smaller image enclosing the object of
|
| 275 |
+
# interest, identify num_peaks_per_label peaks
|
| 276 |
+
labels_peak_coord = []
|
| 277 |
+
|
| 278 |
+
for label_idx, roi in enumerate(ndi.find_objects(_labels)):
|
| 279 |
+
if roi is None:
|
| 280 |
+
continue
|
| 281 |
+
|
| 282 |
+
# Get roi mask
|
| 283 |
+
label_mask = labels[roi] == label_idx + 1
|
| 284 |
+
# Extract image roi
|
| 285 |
+
img_object = image[roi].copy()
|
| 286 |
+
# Ensure masked values don't affect roi's local peaks
|
| 287 |
+
img_object[np.logical_not(label_mask)] = bg_val
|
| 288 |
+
|
| 289 |
+
mask = _get_peak_mask(img_object, footprint, threshold, label_mask)
|
| 290 |
+
|
| 291 |
+
coordinates = _get_high_intensity_peaks(
|
| 292 |
+
img_object, mask, num_peaks_per_label, min_distance, p_norm
|
| 293 |
+
)
|
| 294 |
+
|
| 295 |
+
# transform coordinates in global image indices space
|
| 296 |
+
for idx, s in enumerate(roi):
|
| 297 |
+
coordinates[:, idx] += s.start
|
| 298 |
+
|
| 299 |
+
labels_peak_coord.append(coordinates)
|
| 300 |
+
|
| 301 |
+
if labels_peak_coord:
|
| 302 |
+
coordinates = np.vstack(labels_peak_coord)
|
| 303 |
+
else:
|
| 304 |
+
coordinates = np.empty((0, 2), dtype=int)
|
| 305 |
+
|
| 306 |
+
if len(coordinates) > num_peaks:
|
| 307 |
+
out = np.zeros_like(image, dtype=bool)
|
| 308 |
+
out[tuple(coordinates.T)] = True
|
| 309 |
+
coordinates = _get_high_intensity_peaks(
|
| 310 |
+
image, out, num_peaks, min_distance, p_norm
|
| 311 |
+
)
|
| 312 |
+
|
| 313 |
+
return coordinates
|
| 314 |
+
|
| 315 |
+
|
| 316 |
+
def _prominent_peaks(
|
| 317 |
+
image, min_xdistance=1, min_ydistance=1, threshold=None, num_peaks=np.inf
|
| 318 |
+
):
|
| 319 |
+
"""Return peaks with non-maximum suppression.
|
| 320 |
+
|
| 321 |
+
Identifies most prominent features separated by certain distances.
|
| 322 |
+
Non-maximum suppression with different sizes is applied separately
|
| 323 |
+
in the first and second dimension of the image to identify peaks.
|
| 324 |
+
|
| 325 |
+
Parameters
|
| 326 |
+
----------
|
| 327 |
+
image : (M, N) ndarray
|
| 328 |
+
Input image.
|
| 329 |
+
min_xdistance : int
|
| 330 |
+
Minimum distance separating features in the x dimension.
|
| 331 |
+
min_ydistance : int
|
| 332 |
+
Minimum distance separating features in the y dimension.
|
| 333 |
+
threshold : float
|
| 334 |
+
Minimum intensity of peaks. Default is `0.5 * max(image)`.
|
| 335 |
+
num_peaks : int
|
| 336 |
+
Maximum number of peaks. When the number of peaks exceeds `num_peaks`,
|
| 337 |
+
return `num_peaks` coordinates based on peak intensity.
|
| 338 |
+
|
| 339 |
+
Returns
|
| 340 |
+
-------
|
| 341 |
+
intensity, xcoords, ycoords : tuple of array
|
| 342 |
+
Peak intensity values, x and y indices.
|
| 343 |
+
"""
|
| 344 |
+
|
| 345 |
+
img = image.copy()
|
| 346 |
+
rows, cols = img.shape
|
| 347 |
+
|
| 348 |
+
if threshold is None:
|
| 349 |
+
threshold = 0.5 * np.max(img)
|
| 350 |
+
|
| 351 |
+
ycoords_size = 2 * min_ydistance + 1
|
| 352 |
+
xcoords_size = 2 * min_xdistance + 1
|
| 353 |
+
img_max = ndi.maximum_filter1d(
|
| 354 |
+
img, size=ycoords_size, axis=0, mode='constant', cval=0
|
| 355 |
+
)
|
| 356 |
+
img_max = ndi.maximum_filter1d(
|
| 357 |
+
img_max, size=xcoords_size, axis=1, mode='constant', cval=0
|
| 358 |
+
)
|
| 359 |
+
mask = img == img_max
|
| 360 |
+
img *= mask
|
| 361 |
+
img_t = img > threshold
|
| 362 |
+
|
| 363 |
+
label_img = measure.label(img_t)
|
| 364 |
+
props = measure.regionprops(label_img, img_max)
|
| 365 |
+
|
| 366 |
+
# Sort the list of peaks by intensity, not left-right, so larger peaks
|
| 367 |
+
# in Hough space cannot be arbitrarily suppressed by smaller neighbors
|
| 368 |
+
props = sorted(props, key=lambda x: x.intensity_max)[::-1]
|
| 369 |
+
coords = np.array([np.round(p.centroid) for p in props], dtype=int)
|
| 370 |
+
|
| 371 |
+
img_peaks = []
|
| 372 |
+
ycoords_peaks = []
|
| 373 |
+
xcoords_peaks = []
|
| 374 |
+
|
| 375 |
+
# relative coordinate grid for local neighborhood suppression
|
| 376 |
+
ycoords_ext, xcoords_ext = np.mgrid[
|
| 377 |
+
-min_ydistance : min_ydistance + 1, -min_xdistance : min_xdistance + 1
|
| 378 |
+
]
|
| 379 |
+
|
| 380 |
+
for ycoords_idx, xcoords_idx in coords:
|
| 381 |
+
accum = img_max[ycoords_idx, xcoords_idx]
|
| 382 |
+
if accum > threshold:
|
| 383 |
+
# absolute coordinate grid for local neighborhood suppression
|
| 384 |
+
ycoords_nh = ycoords_idx + ycoords_ext
|
| 385 |
+
xcoords_nh = xcoords_idx + xcoords_ext
|
| 386 |
+
|
| 387 |
+
# no reflection for distance neighborhood
|
| 388 |
+
ycoords_in = np.logical_and(ycoords_nh > 0, ycoords_nh < rows)
|
| 389 |
+
ycoords_nh = ycoords_nh[ycoords_in]
|
| 390 |
+
xcoords_nh = xcoords_nh[ycoords_in]
|
| 391 |
+
|
| 392 |
+
# reflect xcoords and assume xcoords are continuous,
|
| 393 |
+
# e.g. for angles:
|
| 394 |
+
# (..., 88, 89, -90, -89, ..., 89, -90, -89, ...)
|
| 395 |
+
xcoords_low = xcoords_nh < 0
|
| 396 |
+
ycoords_nh[xcoords_low] = rows - ycoords_nh[xcoords_low]
|
| 397 |
+
xcoords_nh[xcoords_low] += cols
|
| 398 |
+
xcoords_high = xcoords_nh >= cols
|
| 399 |
+
ycoords_nh[xcoords_high] = rows - ycoords_nh[xcoords_high]
|
| 400 |
+
xcoords_nh[xcoords_high] -= cols
|
| 401 |
+
|
| 402 |
+
# suppress neighborhood
|
| 403 |
+
img_max[ycoords_nh, xcoords_nh] = 0
|
| 404 |
+
|
| 405 |
+
# add current feature to peaks
|
| 406 |
+
img_peaks.append(accum)
|
| 407 |
+
ycoords_peaks.append(ycoords_idx)
|
| 408 |
+
xcoords_peaks.append(xcoords_idx)
|
| 409 |
+
|
| 410 |
+
img_peaks = np.array(img_peaks)
|
| 411 |
+
ycoords_peaks = np.array(ycoords_peaks)
|
| 412 |
+
xcoords_peaks = np.array(xcoords_peaks)
|
| 413 |
+
|
| 414 |
+
if num_peaks < len(img_peaks):
|
| 415 |
+
idx_maxsort = np.argsort(img_peaks)[::-1][:num_peaks]
|
| 416 |
+
img_peaks = img_peaks[idx_maxsort]
|
| 417 |
+
ycoords_peaks = ycoords_peaks[idx_maxsort]
|
| 418 |
+
xcoords_peaks = xcoords_peaks[idx_maxsort]
|
| 419 |
+
|
| 420 |
+
return img_peaks, xcoords_peaks, ycoords_peaks
|
envs/kitoverlay/skimage/feature/sift.py
ADDED
|
@@ -0,0 +1,771 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
import scipy.ndimage as ndi
|
| 5 |
+
|
| 6 |
+
from .._shared.utils import check_nD, _supported_float_type
|
| 7 |
+
from ..feature.util import DescriptorExtractor, FeatureDetector
|
| 8 |
+
from .._shared.filters import gaussian
|
| 9 |
+
from ..transform import rescale
|
| 10 |
+
from ..util import img_as_float
|
| 11 |
+
from ._sift import _local_max, _ori_distances, _update_histogram
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
def _edgeness(hxx, hyy, hxy):
|
| 15 |
+
"""Compute edgeness (eq. 18 of Otero et. al. IPOL paper)"""
|
| 16 |
+
trace = hxx + hyy
|
| 17 |
+
determinant = hxx * hyy - hxy * hxy
|
| 18 |
+
return (trace * trace) / determinant
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _sparse_gradient(vol, positions):
|
| 22 |
+
"""Gradient of a 3D volume at the provided `positions`.
|
| 23 |
+
|
| 24 |
+
For SIFT we only need the gradient at specific positions and do not need
|
| 25 |
+
the gradient at the edge positions, so can just use this simple
|
| 26 |
+
implementation instead of numpy.gradient.
|
| 27 |
+
"""
|
| 28 |
+
p0 = positions[..., 0]
|
| 29 |
+
p1 = positions[..., 1]
|
| 30 |
+
p2 = positions[..., 2]
|
| 31 |
+
g0 = vol[p0 + 1, p1, p2] - vol[p0 - 1, p1, p2]
|
| 32 |
+
g0 *= 0.5
|
| 33 |
+
g1 = vol[p0, p1 + 1, p2] - vol[p0, p1 - 1, p2]
|
| 34 |
+
g1 *= 0.5
|
| 35 |
+
g2 = vol[p0, p1, p2 + 1] - vol[p0, p1, p2 - 1]
|
| 36 |
+
g2 *= 0.5
|
| 37 |
+
return g0, g1, g2
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def _hessian(d, positions):
|
| 41 |
+
"""Compute the non-redundant 3D Hessian terms at the requested positions.
|
| 42 |
+
|
| 43 |
+
Source: "Anatomy of the SIFT Method" p.380 (13)
|
| 44 |
+
"""
|
| 45 |
+
p0 = positions[..., 0]
|
| 46 |
+
p1 = positions[..., 1]
|
| 47 |
+
p2 = positions[..., 2]
|
| 48 |
+
two_d0 = 2 * d[p0, p1, p2]
|
| 49 |
+
# 0 = row, 1 = col, 2 = octave
|
| 50 |
+
h00 = d[p0 - 1, p1, p2] + d[p0 + 1, p1, p2] - two_d0
|
| 51 |
+
h11 = d[p0, p1 - 1, p2] + d[p0, p1 + 1, p2] - two_d0
|
| 52 |
+
h22 = d[p0, p1, p2 - 1] + d[p0, p1, p2 + 1] - two_d0
|
| 53 |
+
h01 = 0.25 * (
|
| 54 |
+
d[p0 + 1, p1 + 1, p2]
|
| 55 |
+
- d[p0 - 1, p1 + 1, p2]
|
| 56 |
+
- d[p0 + 1, p1 - 1, p2]
|
| 57 |
+
+ d[p0 - 1, p1 - 1, p2]
|
| 58 |
+
)
|
| 59 |
+
h02 = 0.25 * (
|
| 60 |
+
d[p0 + 1, p1, p2 + 1]
|
| 61 |
+
- d[p0 + 1, p1, p2 - 1]
|
| 62 |
+
+ d[p0 - 1, p1, p2 - 1]
|
| 63 |
+
- d[p0 - 1, p1, p2 + 1]
|
| 64 |
+
)
|
| 65 |
+
h12 = 0.25 * (
|
| 66 |
+
d[p0, p1 + 1, p2 + 1]
|
| 67 |
+
- d[p0, p1 + 1, p2 - 1]
|
| 68 |
+
+ d[p0, p1 - 1, p2 - 1]
|
| 69 |
+
- d[p0, p1 - 1, p2 + 1]
|
| 70 |
+
)
|
| 71 |
+
return (h00, h11, h22, h01, h02, h12)
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def _offsets(grad, hess):
|
| 75 |
+
"""Compute position refinement offsets from gradient and Hessian.
|
| 76 |
+
|
| 77 |
+
This is equivalent to np.linalg.solve(-H, J) where H is the Hessian
|
| 78 |
+
matrix and J is the gradient (Jacobian).
|
| 79 |
+
|
| 80 |
+
This analytical solution is adapted from (BSD-licensed) C code by
|
| 81 |
+
Otero et. al (see SIFT docstring References).
|
| 82 |
+
"""
|
| 83 |
+
h00, h11, h22, h01, h02, h12 = hess
|
| 84 |
+
g0, g1, g2 = grad
|
| 85 |
+
det = h00 * h11 * h22
|
| 86 |
+
det -= h00 * h12 * h12
|
| 87 |
+
det -= h01 * h01 * h22
|
| 88 |
+
det += 2 * h01 * h02 * h12
|
| 89 |
+
det -= h02 * h02 * h11
|
| 90 |
+
aa = (h11 * h22 - h12 * h12) / det
|
| 91 |
+
ab = (h02 * h12 - h01 * h22) / det
|
| 92 |
+
ac = (h01 * h12 - h02 * h11) / det
|
| 93 |
+
bb = (h00 * h22 - h02 * h02) / det
|
| 94 |
+
bc = (h01 * h02 - h00 * h12) / det
|
| 95 |
+
cc = (h00 * h11 - h01 * h01) / det
|
| 96 |
+
offset0 = -aa * g0 - ab * g1 - ac * g2
|
| 97 |
+
offset1 = -ab * g0 - bb * g1 - bc * g2
|
| 98 |
+
offset2 = -ac * g0 - bc * g1 - cc * g2
|
| 99 |
+
return np.stack((offset0, offset1, offset2), axis=-1)
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
class SIFT(FeatureDetector, DescriptorExtractor):
|
| 103 |
+
"""SIFT feature detection and descriptor extraction.
|
| 104 |
+
|
| 105 |
+
Parameters
|
| 106 |
+
----------
|
| 107 |
+
upsampling : int, optional
|
| 108 |
+
Prior to the feature detection the image is upscaled by a factor
|
| 109 |
+
of 1 (no upscaling), 2 or 4. Method: Bi-cubic interpolation.
|
| 110 |
+
n_octaves : int, optional
|
| 111 |
+
Maximum number of octaves. With every octave the image size is
|
| 112 |
+
halved and the sigma doubled. The number of octaves will be
|
| 113 |
+
reduced as needed to keep at least 12 pixels along each dimension
|
| 114 |
+
at the smallest scale.
|
| 115 |
+
n_scales : int, optional
|
| 116 |
+
Maximum number of scales in every octave.
|
| 117 |
+
sigma_min : float, optional
|
| 118 |
+
The blur level of the seed image. If upsampling is enabled
|
| 119 |
+
sigma_min is scaled by factor 1/upsampling
|
| 120 |
+
sigma_in : float, optional
|
| 121 |
+
The assumed blur level of the input image.
|
| 122 |
+
c_dog : float, optional
|
| 123 |
+
Threshold to discard low contrast extrema in the DoG. It's final
|
| 124 |
+
value is dependent on n_scales by the relation:
|
| 125 |
+
final_c_dog = (2^(1/n_scales)-1) / (2^(1/3)-1) * c_dog
|
| 126 |
+
c_edge : float, optional
|
| 127 |
+
Threshold to discard extrema that lie in edges. If H is the
|
| 128 |
+
Hessian of an extremum, its "edgeness" is described by
|
| 129 |
+
tr(H)²/det(H). If the edgeness is higher than
|
| 130 |
+
(c_edge + 1)²/c_edge, the extremum is discarded.
|
| 131 |
+
n_bins : int, optional
|
| 132 |
+
Number of bins in the histogram that describes the gradient
|
| 133 |
+
orientations around keypoint.
|
| 134 |
+
lambda_ori : float, optional
|
| 135 |
+
The window used to find the reference orientation of a keypoint
|
| 136 |
+
has a width of 6 * lambda_ori * sigma and is weighted by a
|
| 137 |
+
standard deviation of 2 * lambda_ori * sigma.
|
| 138 |
+
c_max : float, optional
|
| 139 |
+
The threshold at which a secondary peak in the orientation
|
| 140 |
+
histogram is accepted as orientation
|
| 141 |
+
lambda_descr : float, optional
|
| 142 |
+
The window used to define the descriptor of a keypoint has a width
|
| 143 |
+
of 2 * lambda_descr * sigma * (n_hist+1)/n_hist and is weighted by
|
| 144 |
+
a standard deviation of lambda_descr * sigma.
|
| 145 |
+
n_hist : int, optional
|
| 146 |
+
The window used to define the descriptor of a keypoint consists of
|
| 147 |
+
n_hist * n_hist histograms.
|
| 148 |
+
n_ori : int, optional
|
| 149 |
+
The number of bins in the histograms of the descriptor patch.
|
| 150 |
+
|
| 151 |
+
Attributes
|
| 152 |
+
----------
|
| 153 |
+
delta_min : float
|
| 154 |
+
The sampling distance of the first octave. It's final value is
|
| 155 |
+
1/upsampling.
|
| 156 |
+
float_dtype : type
|
| 157 |
+
The datatype of the image.
|
| 158 |
+
scalespace_sigmas : (n_octaves, n_scales + 3) array
|
| 159 |
+
The sigma value of all scales in all octaves.
|
| 160 |
+
keypoints : (N, 2) array
|
| 161 |
+
Keypoint coordinates as ``(row, col)``.
|
| 162 |
+
positions : (N, 2) array
|
| 163 |
+
Subpixel-precision keypoint coordinates as ``(row, col)``.
|
| 164 |
+
sigmas : (N,) array
|
| 165 |
+
The corresponding sigma (blur) value of a keypoint.
|
| 166 |
+
scales : (N,) array
|
| 167 |
+
The corresponding scale of a keypoint.
|
| 168 |
+
orientations : (N,) array
|
| 169 |
+
The orientations of the gradient around every keypoint.
|
| 170 |
+
octaves : (N,) array
|
| 171 |
+
The corresponding octave of a keypoint.
|
| 172 |
+
descriptors : (N, n_hist*n_hist*n_ori) array
|
| 173 |
+
The descriptors of a keypoint.
|
| 174 |
+
|
| 175 |
+
Notes
|
| 176 |
+
-----
|
| 177 |
+
The SIFT algorithm was developed by David Lowe [1]_, [2]_ and later
|
| 178 |
+
patented by the University of British Columbia. Since the patent expired in
|
| 179 |
+
2020 it's free to use. The implementation here closely follows the
|
| 180 |
+
detailed description in [3]_, including use of the same default parameters.
|
| 181 |
+
|
| 182 |
+
References
|
| 183 |
+
----------
|
| 184 |
+
.. [1] D.G. Lowe. "Object recognition from local scale-invariant
|
| 185 |
+
features", Proceedings of the Seventh IEEE International
|
| 186 |
+
Conference on Computer Vision, 1999, vol.2, pp. 1150-1157.
|
| 187 |
+
:DOI:`10.1109/ICCV.1999.790410`
|
| 188 |
+
|
| 189 |
+
.. [2] D.G. Lowe. "Distinctive Image Features from Scale-Invariant
|
| 190 |
+
Keypoints", International Journal of Computer Vision, 2004,
|
| 191 |
+
vol. 60, pp. 91–110.
|
| 192 |
+
:DOI:`10.1023/B:VISI.0000029664.99615.94`
|
| 193 |
+
|
| 194 |
+
.. [3] I. R. Otero and M. Delbracio. "Anatomy of the SIFT Method",
|
| 195 |
+
Image Processing On Line, 4 (2014), pp. 370–396.
|
| 196 |
+
:DOI:`10.5201/ipol.2014.82`
|
| 197 |
+
|
| 198 |
+
Examples
|
| 199 |
+
--------
|
| 200 |
+
>>> from skimage.feature import SIFT, match_descriptors
|
| 201 |
+
>>> from skimage.data import camera
|
| 202 |
+
>>> from skimage.transform import rotate
|
| 203 |
+
>>> img1 = camera()
|
| 204 |
+
>>> img2 = rotate(camera(), 90)
|
| 205 |
+
>>> detector_extractor1 = SIFT()
|
| 206 |
+
>>> detector_extractor2 = SIFT()
|
| 207 |
+
>>> detector_extractor1.detect_and_extract(img1)
|
| 208 |
+
>>> detector_extractor2.detect_and_extract(img2)
|
| 209 |
+
>>> matches = match_descriptors(detector_extractor1.descriptors,
|
| 210 |
+
... detector_extractor2.descriptors,
|
| 211 |
+
... max_ratio=0.6)
|
| 212 |
+
>>> matches[10:15]
|
| 213 |
+
array([[ 10, 412],
|
| 214 |
+
[ 11, 417],
|
| 215 |
+
[ 12, 407],
|
| 216 |
+
[ 13, 411],
|
| 217 |
+
[ 14, 406]])
|
| 218 |
+
>>> detector_extractor1.keypoints[matches[10:15, 0]]
|
| 219 |
+
array([[ 95, 214],
|
| 220 |
+
[ 97, 211],
|
| 221 |
+
[ 97, 218],
|
| 222 |
+
[102, 215],
|
| 223 |
+
[104, 218]])
|
| 224 |
+
>>> detector_extractor2.keypoints[matches[10:15, 1]]
|
| 225 |
+
array([[297, 95],
|
| 226 |
+
[301, 97],
|
| 227 |
+
[294, 97],
|
| 228 |
+
[297, 102],
|
| 229 |
+
[293, 104]])
|
| 230 |
+
|
| 231 |
+
"""
|
| 232 |
+
|
| 233 |
+
def __init__(
|
| 234 |
+
self,
|
| 235 |
+
upsampling=2,
|
| 236 |
+
n_octaves=8,
|
| 237 |
+
n_scales=3,
|
| 238 |
+
sigma_min=1.6,
|
| 239 |
+
sigma_in=0.5,
|
| 240 |
+
c_dog=0.04 / 3,
|
| 241 |
+
c_edge=10,
|
| 242 |
+
n_bins=36,
|
| 243 |
+
lambda_ori=1.5,
|
| 244 |
+
c_max=0.8,
|
| 245 |
+
lambda_descr=6,
|
| 246 |
+
n_hist=4,
|
| 247 |
+
n_ori=8,
|
| 248 |
+
):
|
| 249 |
+
if upsampling in [1, 2, 4]:
|
| 250 |
+
self.upsampling = upsampling
|
| 251 |
+
else:
|
| 252 |
+
raise ValueError("upsampling must be 1, 2 or 4")
|
| 253 |
+
self.n_octaves = n_octaves
|
| 254 |
+
self.n_scales = n_scales
|
| 255 |
+
self.sigma_min = sigma_min / upsampling
|
| 256 |
+
self.sigma_in = sigma_in
|
| 257 |
+
self.c_dog = (2 ** (1 / n_scales) - 1) / (2 ** (1 / 3) - 1) * c_dog
|
| 258 |
+
self.c_edge = c_edge
|
| 259 |
+
self.n_bins = n_bins
|
| 260 |
+
self.lambda_ori = lambda_ori
|
| 261 |
+
self.c_max = c_max
|
| 262 |
+
self.lambda_descr = lambda_descr
|
| 263 |
+
self.n_hist = n_hist
|
| 264 |
+
self.n_ori = n_ori
|
| 265 |
+
self.delta_min = 1 / upsampling
|
| 266 |
+
self.float_dtype = None
|
| 267 |
+
self.scalespace_sigmas = None
|
| 268 |
+
self.keypoints = None
|
| 269 |
+
self.positions = None
|
| 270 |
+
self.sigmas = None
|
| 271 |
+
self.scales = None
|
| 272 |
+
self.orientations = None
|
| 273 |
+
self.octaves = None
|
| 274 |
+
self.descriptors = None
|
| 275 |
+
|
| 276 |
+
@property
|
| 277 |
+
def deltas(self):
|
| 278 |
+
"""The sampling distances of all octaves"""
|
| 279 |
+
deltas = self.delta_min * np.power(
|
| 280 |
+
2, np.arange(self.n_octaves), dtype=self.float_dtype
|
| 281 |
+
)
|
| 282 |
+
return deltas
|
| 283 |
+
|
| 284 |
+
def _set_number_of_octaves(self, image_shape):
|
| 285 |
+
size_min = 12 # minimum size of last octave
|
| 286 |
+
s0 = min(image_shape) * self.upsampling
|
| 287 |
+
max_octaves = int(math.log2(s0 / size_min) + 1)
|
| 288 |
+
if max_octaves < self.n_octaves:
|
| 289 |
+
self.n_octaves = max_octaves
|
| 290 |
+
|
| 291 |
+
def _create_scalespace(self, image):
|
| 292 |
+
"""Source: "Anatomy of the SIFT Method" Alg. 1
|
| 293 |
+
Construction of the scalespace by gradually blurring (scales) and
|
| 294 |
+
downscaling (octaves) the image.
|
| 295 |
+
"""
|
| 296 |
+
scalespace = []
|
| 297 |
+
if self.upsampling > 1:
|
| 298 |
+
image = rescale(image, self.upsampling, order=1)
|
| 299 |
+
|
| 300 |
+
# smooth to sigma_min, assuming sigma_in
|
| 301 |
+
image = gaussian(
|
| 302 |
+
image,
|
| 303 |
+
sigma=self.upsampling * math.sqrt(self.sigma_min**2 - self.sigma_in**2),
|
| 304 |
+
mode='reflect',
|
| 305 |
+
)
|
| 306 |
+
|
| 307 |
+
# Eq. 10: sigmas.shape = (n_octaves, n_scales + 3).
|
| 308 |
+
# The three extra scales are:
|
| 309 |
+
# One for the differences needed for DoG and two auxiliary
|
| 310 |
+
# images (one at either end) for peak_local_max with exclude
|
| 311 |
+
# border = True (see Fig. 5)
|
| 312 |
+
# The smoothing doubles after n_scales steps.
|
| 313 |
+
tmp = np.power(2, np.arange(self.n_scales + 3) / self.n_scales)
|
| 314 |
+
tmp *= self.sigma_min
|
| 315 |
+
# all sigmas for the gaussian scalespace
|
| 316 |
+
sigmas = self.deltas[:, np.newaxis] / self.deltas[0] * tmp[np.newaxis, :]
|
| 317 |
+
self.scalespace_sigmas = sigmas
|
| 318 |
+
|
| 319 |
+
# Eq. 7: Gaussian smoothing depends on difference with previous sigma
|
| 320 |
+
# gaussian_sigmas.shape = (n_octaves, n_scales + 2)
|
| 321 |
+
var_diff = np.diff(sigmas * sigmas, axis=1)
|
| 322 |
+
gaussian_sigmas = np.sqrt(var_diff) / self.deltas[:, np.newaxis]
|
| 323 |
+
|
| 324 |
+
# one octave is represented by a 3D image with depth (n_scales+x)
|
| 325 |
+
for o in range(self.n_octaves):
|
| 326 |
+
# Temporarily put scales axis first so octave[i] is C-contiguous
|
| 327 |
+
# (this makes Gaussian filtering faster).
|
| 328 |
+
octave = np.empty(
|
| 329 |
+
(self.n_scales + 3,) + image.shape, dtype=self.float_dtype, order='C'
|
| 330 |
+
)
|
| 331 |
+
octave[0] = image
|
| 332 |
+
for s in range(1, self.n_scales + 3):
|
| 333 |
+
# blur new scale assuming sigma of the last one
|
| 334 |
+
gaussian(
|
| 335 |
+
octave[s - 1],
|
| 336 |
+
sigma=gaussian_sigmas[o, s - 1],
|
| 337 |
+
mode='reflect',
|
| 338 |
+
out=octave[s],
|
| 339 |
+
)
|
| 340 |
+
# move scales to last axis as expected by other methods
|
| 341 |
+
scalespace.append(np.moveaxis(octave, 0, -1))
|
| 342 |
+
if o < self.n_octaves - 1:
|
| 343 |
+
# downscale the image by taking every second pixel
|
| 344 |
+
image = octave[self.n_scales][::2, ::2]
|
| 345 |
+
return scalespace
|
| 346 |
+
|
| 347 |
+
def _inrange(self, a, dim):
|
| 348 |
+
return (
|
| 349 |
+
(a[:, 0] > 0)
|
| 350 |
+
& (a[:, 0] < dim[0] - 1)
|
| 351 |
+
& (a[:, 1] > 0)
|
| 352 |
+
& (a[:, 1] < dim[1] - 1)
|
| 353 |
+
)
|
| 354 |
+
|
| 355 |
+
def _find_localize_evaluate(self, dogspace, img_shape):
|
| 356 |
+
"""Source: "Anatomy of the SIFT Method" Alg. 4-9
|
| 357 |
+
1) first find all extrema of a (3, 3, 3) neighborhood
|
| 358 |
+
2) use second order Taylor development to refine the positions to
|
| 359 |
+
sub-pixel precision
|
| 360 |
+
3) filter out extrema that have low contrast and lie on edges or close
|
| 361 |
+
to the image borders
|
| 362 |
+
"""
|
| 363 |
+
extrema_pos = []
|
| 364 |
+
extrema_scales = []
|
| 365 |
+
extrema_sigmas = []
|
| 366 |
+
threshold = self.c_dog * 0.8
|
| 367 |
+
for o, (octave, delta) in enumerate(zip(dogspace, self.deltas)):
|
| 368 |
+
# find extrema
|
| 369 |
+
keys = _local_max(np.ascontiguousarray(octave), threshold)
|
| 370 |
+
if keys.size == 0:
|
| 371 |
+
extrema_pos.append(np.empty((0, 2)))
|
| 372 |
+
continue
|
| 373 |
+
|
| 374 |
+
# localize extrema
|
| 375 |
+
oshape = octave.shape
|
| 376 |
+
refinement_iterations = 5
|
| 377 |
+
offset_max = 0.6
|
| 378 |
+
for i in range(refinement_iterations):
|
| 379 |
+
if i > 0:
|
| 380 |
+
# exclude any keys that have moved out of bounds
|
| 381 |
+
keys = keys[self._inrange(keys, oshape), :]
|
| 382 |
+
|
| 383 |
+
# Jacobian and Hessian of all extrema
|
| 384 |
+
grad = _sparse_gradient(octave, keys)
|
| 385 |
+
hess = _hessian(octave, keys)
|
| 386 |
+
|
| 387 |
+
# solve for offset of the extremum
|
| 388 |
+
off = _offsets(grad, hess)
|
| 389 |
+
if i == refinement_iterations - 1:
|
| 390 |
+
break
|
| 391 |
+
# offset is too big and an increase would not bring us out of
|
| 392 |
+
# bounds
|
| 393 |
+
wrong_position_pos = np.logical_and(
|
| 394 |
+
off > offset_max, keys + 1 < tuple([a - 1 for a in oshape])
|
| 395 |
+
)
|
| 396 |
+
wrong_position_neg = np.logical_and(off < -offset_max, keys - 1 > 0)
|
| 397 |
+
if not np.any(np.logical_or(wrong_position_neg, wrong_position_pos)):
|
| 398 |
+
break
|
| 399 |
+
keys[wrong_position_pos] += 1
|
| 400 |
+
keys[wrong_position_neg] -= 1
|
| 401 |
+
|
| 402 |
+
# mask for all extrema that have been localized successfully
|
| 403 |
+
finished = np.all(np.abs(off) < offset_max, axis=1)
|
| 404 |
+
keys = keys[finished]
|
| 405 |
+
off = off[finished]
|
| 406 |
+
grad = [g[finished] for g in grad]
|
| 407 |
+
|
| 408 |
+
# value of extremum in octave
|
| 409 |
+
vals = octave[keys[:, 0], keys[:, 1], keys[:, 2]]
|
| 410 |
+
# values at interpolated point
|
| 411 |
+
w = vals
|
| 412 |
+
for i in range(3):
|
| 413 |
+
w += 0.5 * grad[i] * off[:, i]
|
| 414 |
+
|
| 415 |
+
h00, h11, h01 = hess[0][finished], hess[1][finished], hess[3][finished]
|
| 416 |
+
|
| 417 |
+
sigmaratio = self.scalespace_sigmas[0, 1] / self.scalespace_sigmas[0, 0]
|
| 418 |
+
|
| 419 |
+
# filter for contrast, edgeness and borders
|
| 420 |
+
contrast_threshold = self.c_dog
|
| 421 |
+
contrast_filter = np.abs(w) > contrast_threshold
|
| 422 |
+
|
| 423 |
+
edge_threshold = np.square(self.c_edge + 1) / self.c_edge
|
| 424 |
+
edge_response = _edgeness(
|
| 425 |
+
h00[contrast_filter], h11[contrast_filter], h01[contrast_filter]
|
| 426 |
+
)
|
| 427 |
+
edge_filter = np.abs(edge_response) <= edge_threshold
|
| 428 |
+
|
| 429 |
+
keys = keys[contrast_filter][edge_filter]
|
| 430 |
+
off = off[contrast_filter][edge_filter]
|
| 431 |
+
yx = ((keys[:, :2] + off[:, :2]) * delta).astype(self.float_dtype)
|
| 432 |
+
|
| 433 |
+
sigmas = self.scalespace_sigmas[o, keys[:, 2]] * np.power(
|
| 434 |
+
sigmaratio, off[:, 2]
|
| 435 |
+
)
|
| 436 |
+
border_filter = np.all(
|
| 437 |
+
np.logical_and(
|
| 438 |
+
(yx - sigmas[:, np.newaxis]) > 0.0,
|
| 439 |
+
(yx + sigmas[:, np.newaxis]) < img_shape,
|
| 440 |
+
),
|
| 441 |
+
axis=1,
|
| 442 |
+
)
|
| 443 |
+
extrema_pos.append(yx[border_filter])
|
| 444 |
+
extrema_scales.append(keys[border_filter, 2])
|
| 445 |
+
extrema_sigmas.append(sigmas[border_filter])
|
| 446 |
+
|
| 447 |
+
octave_indices = np.concatenate(
|
| 448 |
+
[np.full(len(p), i) for i, p in enumerate(extrema_pos)]
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
if len(octave_indices) == 0:
|
| 452 |
+
raise RuntimeError(
|
| 453 |
+
"SIFT found no features. Try passing in an image containing "
|
| 454 |
+
"greater intensity contrasts between adjacent pixels."
|
| 455 |
+
)
|
| 456 |
+
|
| 457 |
+
extrema_pos = np.concatenate(extrema_pos)
|
| 458 |
+
extrema_scales = np.concatenate(extrema_scales)
|
| 459 |
+
extrema_sigmas = np.concatenate(extrema_sigmas)
|
| 460 |
+
return extrema_pos, extrema_scales, extrema_sigmas, octave_indices
|
| 461 |
+
|
| 462 |
+
def _fit(self, h):
|
| 463 |
+
"""Refine the position of the peak by fitting it to a parabola"""
|
| 464 |
+
return (h[0] - h[2]) / (2 * (h[0] + h[2] - 2 * h[1]))
|
| 465 |
+
|
| 466 |
+
def _compute_orientation(
|
| 467 |
+
self, positions_oct, scales_oct, sigmas_oct, octaves, gaussian_scalespace
|
| 468 |
+
):
|
| 469 |
+
"""Source: "Anatomy of the SIFT Method" Alg. 11
|
| 470 |
+
Calculates the orientation of the gradient around every keypoint
|
| 471 |
+
"""
|
| 472 |
+
gradient_space = []
|
| 473 |
+
# list for keypoints that have more than one reference orientation
|
| 474 |
+
keypoint_indices = []
|
| 475 |
+
keypoint_angles = []
|
| 476 |
+
keypoint_octave = []
|
| 477 |
+
orientations = np.zeros_like(sigmas_oct, dtype=self.float_dtype)
|
| 478 |
+
key_count = 0
|
| 479 |
+
for o, (octave, delta) in enumerate(zip(gaussian_scalespace, self.deltas)):
|
| 480 |
+
gradient_space.append(np.gradient(octave))
|
| 481 |
+
|
| 482 |
+
in_oct = octaves == o
|
| 483 |
+
if not np.any(in_oct):
|
| 484 |
+
continue
|
| 485 |
+
positions = positions_oct[in_oct]
|
| 486 |
+
scales = scales_oct[in_oct]
|
| 487 |
+
sigmas = sigmas_oct[in_oct]
|
| 488 |
+
|
| 489 |
+
oshape = octave.shape[:2]
|
| 490 |
+
# convert to octave's dimensions
|
| 491 |
+
yx = positions / delta
|
| 492 |
+
sigma = sigmas / delta
|
| 493 |
+
|
| 494 |
+
# dimensions of the patch
|
| 495 |
+
radius = 3 * self.lambda_ori * sigma
|
| 496 |
+
p_min = np.maximum(0, yx - radius[:, np.newaxis] + 0.5).astype(int)
|
| 497 |
+
p_max = np.minimum(
|
| 498 |
+
yx + radius[:, np.newaxis] + 0.5, (oshape[0] - 1, oshape[1] - 1)
|
| 499 |
+
).astype(int)
|
| 500 |
+
# orientation histogram
|
| 501 |
+
hist = np.empty(self.n_bins, dtype=self.float_dtype)
|
| 502 |
+
avg_kernel = np.full((3,), 1 / 3, dtype=self.float_dtype)
|
| 503 |
+
for k in range(len(yx)):
|
| 504 |
+
hist[:] = 0
|
| 505 |
+
|
| 506 |
+
# use the patch coordinates to get the gradient and then
|
| 507 |
+
# normalize them
|
| 508 |
+
r, c = np.meshgrid(
|
| 509 |
+
np.arange(p_min[k, 0], p_max[k, 0] + 1),
|
| 510 |
+
np.arange(p_min[k, 1], p_max[k, 1] + 1),
|
| 511 |
+
indexing='ij',
|
| 512 |
+
sparse=True,
|
| 513 |
+
)
|
| 514 |
+
gradient_row = gradient_space[o][0][r, c, scales[k]]
|
| 515 |
+
gradient_col = gradient_space[o][1][r, c, scales[k]]
|
| 516 |
+
r = r.astype(self.float_dtype, copy=False)
|
| 517 |
+
c = c.astype(self.float_dtype, copy=False)
|
| 518 |
+
r -= yx[k, 0]
|
| 519 |
+
c -= yx[k, 1]
|
| 520 |
+
|
| 521 |
+
# gradient magnitude and angles
|
| 522 |
+
magnitude = np.sqrt(np.square(gradient_row) + np.square(gradient_col))
|
| 523 |
+
theta = np.mod(np.arctan2(gradient_col, gradient_row), 2 * np.pi)
|
| 524 |
+
|
| 525 |
+
# more weight to center values
|
| 526 |
+
kernel = np.exp(
|
| 527 |
+
np.divide(r * r + c * c, -2 * (self.lambda_ori * sigma[k]) ** 2)
|
| 528 |
+
)
|
| 529 |
+
|
| 530 |
+
# fill the histogram
|
| 531 |
+
bins = np.floor(
|
| 532 |
+
(theta / (2 * np.pi) * self.n_bins + 0.5) % self.n_bins
|
| 533 |
+
).astype(int)
|
| 534 |
+
np.add.at(hist, bins, kernel * magnitude)
|
| 535 |
+
|
| 536 |
+
# smooth the histogram and find the maximum
|
| 537 |
+
hist = np.concatenate((hist[-6:], hist, hist[:6]))
|
| 538 |
+
for _ in range(6): # number of smoothings
|
| 539 |
+
hist = np.convolve(hist, avg_kernel, mode='same')
|
| 540 |
+
hist = hist[6:-6]
|
| 541 |
+
max_filter = ndi.maximum_filter(hist, [3], mode='wrap')
|
| 542 |
+
|
| 543 |
+
# if an angle is in 80% percent range of the maximum, a
|
| 544 |
+
# new keypoint is created for it
|
| 545 |
+
maxima = np.nonzero(
|
| 546 |
+
np.logical_and(
|
| 547 |
+
hist >= (self.c_max * np.max(hist)), max_filter == hist
|
| 548 |
+
)
|
| 549 |
+
)
|
| 550 |
+
|
| 551 |
+
# save the angles
|
| 552 |
+
for c, m in enumerate(maxima[0]):
|
| 553 |
+
neigh = np.arange(m - 1, m + 2) % len(hist)
|
| 554 |
+
# use neighbors to fit a parabola, to get more accurate
|
| 555 |
+
# result
|
| 556 |
+
ori = (m + self._fit(hist[neigh]) + 0.5) * 2 * np.pi / self.n_bins
|
| 557 |
+
if ori > np.pi:
|
| 558 |
+
ori -= 2 * np.pi
|
| 559 |
+
if c == 0:
|
| 560 |
+
orientations[key_count] = ori
|
| 561 |
+
else:
|
| 562 |
+
keypoint_indices.append(key_count)
|
| 563 |
+
keypoint_angles.append(ori)
|
| 564 |
+
keypoint_octave.append(o)
|
| 565 |
+
key_count += 1
|
| 566 |
+
self.positions = np.concatenate(
|
| 567 |
+
(positions_oct, positions_oct[keypoint_indices])
|
| 568 |
+
)
|
| 569 |
+
self.scales = np.concatenate((scales_oct, scales_oct[keypoint_indices]))
|
| 570 |
+
self.sigmas = np.concatenate((sigmas_oct, sigmas_oct[keypoint_indices]))
|
| 571 |
+
self.orientations = np.concatenate((orientations, keypoint_angles))
|
| 572 |
+
self.octaves = np.concatenate((octaves, keypoint_octave))
|
| 573 |
+
# return the gradient_space to reuse it to find the descriptor
|
| 574 |
+
return gradient_space
|
| 575 |
+
|
| 576 |
+
def _rotate(self, row, col, angle):
|
| 577 |
+
c = math.cos(angle)
|
| 578 |
+
s = math.sin(angle)
|
| 579 |
+
rot_row = c * row + s * col
|
| 580 |
+
rot_col = -s * row + c * col
|
| 581 |
+
return rot_row, rot_col
|
| 582 |
+
|
| 583 |
+
def _compute_descriptor(self, gradient_space):
|
| 584 |
+
"""Source: "Anatomy of the SIFT Method" Alg. 12
|
| 585 |
+
Calculates the descriptor for every keypoint
|
| 586 |
+
"""
|
| 587 |
+
n_key = len(self.scales)
|
| 588 |
+
self.descriptors = np.empty(
|
| 589 |
+
(n_key, self.n_hist**2 * self.n_ori), dtype=np.uint8
|
| 590 |
+
)
|
| 591 |
+
|
| 592 |
+
# indices of the histograms
|
| 593 |
+
hists = np.arange(1, self.n_hist + 1, dtype=self.float_dtype)
|
| 594 |
+
# indices of the bins
|
| 595 |
+
bins = np.arange(1, self.n_ori + 1, dtype=self.float_dtype)
|
| 596 |
+
|
| 597 |
+
key_numbers = np.arange(n_key)
|
| 598 |
+
for o, (gradient, delta) in enumerate(zip(gradient_space, self.deltas)):
|
| 599 |
+
in_oct = self.octaves == o
|
| 600 |
+
if not np.any(in_oct):
|
| 601 |
+
continue
|
| 602 |
+
positions = self.positions[in_oct]
|
| 603 |
+
scales = self.scales[in_oct]
|
| 604 |
+
sigmas = self.sigmas[in_oct]
|
| 605 |
+
orientations = self.orientations[in_oct]
|
| 606 |
+
numbers = key_numbers[in_oct]
|
| 607 |
+
|
| 608 |
+
dim = gradient[0].shape[:2]
|
| 609 |
+
center_pos = positions / delta
|
| 610 |
+
sigma = sigmas / delta
|
| 611 |
+
|
| 612 |
+
# dimensions of the patch
|
| 613 |
+
radius = self.lambda_descr * (1 + 1 / self.n_hist) * sigma
|
| 614 |
+
radius_patch = math.sqrt(2) * radius
|
| 615 |
+
p_min = np.asarray(
|
| 616 |
+
np.maximum(0, center_pos - radius_patch[:, np.newaxis] + 0.5), dtype=int
|
| 617 |
+
)
|
| 618 |
+
p_max = np.asarray(
|
| 619 |
+
np.minimum(
|
| 620 |
+
center_pos + radius_patch[:, np.newaxis] + 0.5,
|
| 621 |
+
(dim[0] - 1, dim[1] - 1),
|
| 622 |
+
),
|
| 623 |
+
dtype=int,
|
| 624 |
+
)
|
| 625 |
+
|
| 626 |
+
for k in range(len(p_max)):
|
| 627 |
+
rad_k = float(radius[k])
|
| 628 |
+
ori = float(orientations[k])
|
| 629 |
+
histograms = np.zeros(
|
| 630 |
+
(self.n_hist, self.n_hist, self.n_ori), dtype=self.float_dtype
|
| 631 |
+
)
|
| 632 |
+
# the patch
|
| 633 |
+
r, c = np.meshgrid(
|
| 634 |
+
np.arange(p_min[k, 0], p_max[k, 0]),
|
| 635 |
+
np.arange(p_min[k, 1], p_max[k, 1]),
|
| 636 |
+
indexing='ij',
|
| 637 |
+
sparse=True,
|
| 638 |
+
)
|
| 639 |
+
# normalized coordinates
|
| 640 |
+
r_norm = np.subtract(r, center_pos[k, 0], dtype=self.float_dtype)
|
| 641 |
+
c_norm = np.subtract(c, center_pos[k, 1], dtype=self.float_dtype)
|
| 642 |
+
r_norm, c_norm = self._rotate(r_norm, c_norm, ori)
|
| 643 |
+
|
| 644 |
+
# select coordinates and gradient values within the patch
|
| 645 |
+
inside = np.maximum(np.abs(r_norm), np.abs(c_norm)) < rad_k
|
| 646 |
+
r_norm, c_norm = r_norm[inside], c_norm[inside]
|
| 647 |
+
r_idx, c_idx = np.nonzero(inside)
|
| 648 |
+
r = r[r_idx, 0]
|
| 649 |
+
c = c[0, c_idx]
|
| 650 |
+
gradient_row = gradient[0][r, c, scales[k]]
|
| 651 |
+
gradient_col = gradient[1][r, c, scales[k]]
|
| 652 |
+
# compute the (relative) gradient orientation
|
| 653 |
+
theta = np.arctan2(gradient_col, gradient_row) - ori
|
| 654 |
+
lam_sig = self.lambda_descr * float(sigma[k])
|
| 655 |
+
# Gaussian weighted kernel magnitude
|
| 656 |
+
kernel = np.exp((r_norm * r_norm + c_norm * c_norm) / (-2 * lam_sig**2))
|
| 657 |
+
magnitude = (
|
| 658 |
+
np.sqrt(gradient_row * gradient_row + gradient_col * gradient_col)
|
| 659 |
+
* kernel
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
lam_sig_ratio = 2 * lam_sig / self.n_hist
|
| 663 |
+
rc_bins = (hists - (1 + self.n_hist) / 2) * lam_sig_ratio
|
| 664 |
+
rc_bin_spacing = lam_sig_ratio
|
| 665 |
+
ori_bins = (2 * np.pi * bins) / self.n_ori
|
| 666 |
+
|
| 667 |
+
# distances to the histograms and bins
|
| 668 |
+
dist_r = np.abs(np.subtract.outer(rc_bins, r_norm))
|
| 669 |
+
dist_c = np.abs(np.subtract.outer(rc_bins, c_norm))
|
| 670 |
+
|
| 671 |
+
# the orientation histograms/bins that get the contribution
|
| 672 |
+
near_t, near_t_val = _ori_distances(ori_bins, theta)
|
| 673 |
+
|
| 674 |
+
# create the histogram
|
| 675 |
+
_update_histogram(
|
| 676 |
+
histograms,
|
| 677 |
+
near_t,
|
| 678 |
+
near_t_val,
|
| 679 |
+
magnitude,
|
| 680 |
+
dist_r,
|
| 681 |
+
dist_c,
|
| 682 |
+
rc_bin_spacing,
|
| 683 |
+
)
|
| 684 |
+
|
| 685 |
+
# convert the histograms to a 1d descriptor
|
| 686 |
+
histograms = histograms.reshape(-1)
|
| 687 |
+
# saturate the descriptor
|
| 688 |
+
histograms = np.minimum(histograms, 0.2 * np.linalg.norm(histograms))
|
| 689 |
+
# normalize the descriptor
|
| 690 |
+
descriptor = (512 * histograms) / np.linalg.norm(histograms)
|
| 691 |
+
# quantize the descriptor
|
| 692 |
+
descriptor = np.minimum(np.floor(descriptor), 255)
|
| 693 |
+
self.descriptors[numbers[k], :] = descriptor
|
| 694 |
+
|
| 695 |
+
def _preprocess(self, image):
|
| 696 |
+
check_nD(image, 2)
|
| 697 |
+
image = img_as_float(image)
|
| 698 |
+
self.float_dtype = _supported_float_type(image.dtype)
|
| 699 |
+
image = image.astype(self.float_dtype, copy=False)
|
| 700 |
+
|
| 701 |
+
self._set_number_of_octaves(image.shape)
|
| 702 |
+
return image
|
| 703 |
+
|
| 704 |
+
def detect(self, image):
|
| 705 |
+
"""Detect the keypoints.
|
| 706 |
+
|
| 707 |
+
Parameters
|
| 708 |
+
----------
|
| 709 |
+
image : 2D array
|
| 710 |
+
Input image.
|
| 711 |
+
|
| 712 |
+
"""
|
| 713 |
+
image = self._preprocess(image)
|
| 714 |
+
|
| 715 |
+
gaussian_scalespace = self._create_scalespace(image)
|
| 716 |
+
|
| 717 |
+
dog_scalespace = [np.diff(layer, axis=2) for layer in gaussian_scalespace]
|
| 718 |
+
|
| 719 |
+
positions, scales, sigmas, octaves = self._find_localize_evaluate(
|
| 720 |
+
dog_scalespace, image.shape
|
| 721 |
+
)
|
| 722 |
+
|
| 723 |
+
self._compute_orientation(
|
| 724 |
+
positions, scales, sigmas, octaves, gaussian_scalespace
|
| 725 |
+
)
|
| 726 |
+
|
| 727 |
+
self.keypoints = self.positions.round().astype(int)
|
| 728 |
+
|
| 729 |
+
def extract(self, image):
|
| 730 |
+
"""Extract the descriptors for all keypoints in the image.
|
| 731 |
+
|
| 732 |
+
Parameters
|
| 733 |
+
----------
|
| 734 |
+
image : 2D array
|
| 735 |
+
Input image.
|
| 736 |
+
|
| 737 |
+
"""
|
| 738 |
+
image = self._preprocess(image)
|
| 739 |
+
|
| 740 |
+
gaussian_scalespace = self._create_scalespace(image)
|
| 741 |
+
|
| 742 |
+
gradient_space = [np.gradient(octave) for octave in gaussian_scalespace]
|
| 743 |
+
|
| 744 |
+
self._compute_descriptor(gradient_space)
|
| 745 |
+
|
| 746 |
+
def detect_and_extract(self, image):
|
| 747 |
+
"""Detect the keypoints and extract their descriptors.
|
| 748 |
+
|
| 749 |
+
Parameters
|
| 750 |
+
----------
|
| 751 |
+
image : 2D array
|
| 752 |
+
Input image.
|
| 753 |
+
|
| 754 |
+
"""
|
| 755 |
+
image = self._preprocess(image)
|
| 756 |
+
|
| 757 |
+
gaussian_scalespace = self._create_scalespace(image)
|
| 758 |
+
|
| 759 |
+
dog_scalespace = [np.diff(layer, axis=2) for layer in gaussian_scalespace]
|
| 760 |
+
|
| 761 |
+
positions, scales, sigmas, octaves = self._find_localize_evaluate(
|
| 762 |
+
dog_scalespace, image.shape
|
| 763 |
+
)
|
| 764 |
+
|
| 765 |
+
gradient_space = self._compute_orientation(
|
| 766 |
+
positions, scales, sigmas, octaves, gaussian_scalespace
|
| 767 |
+
)
|
| 768 |
+
|
| 769 |
+
self._compute_descriptor(gradient_space)
|
| 770 |
+
|
| 771 |
+
self.keypoints = self.positions.round().astype(int)
|
envs/kitoverlay/skimage/feature/template.py
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import math
|
| 2 |
+
|
| 3 |
+
import numpy as np
|
| 4 |
+
from scipy.signal import fftconvolve
|
| 5 |
+
|
| 6 |
+
from .._shared.utils import check_nD, _supported_float_type
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _window_sum_2d(image, window_shape):
|
| 10 |
+
window_sum = np.cumsum(image, axis=0)
|
| 11 |
+
window_sum = window_sum[window_shape[0] : -1] - window_sum[: -window_shape[0] - 1]
|
| 12 |
+
|
| 13 |
+
window_sum = np.cumsum(window_sum, axis=1)
|
| 14 |
+
window_sum = (
|
| 15 |
+
window_sum[:, window_shape[1] : -1] - window_sum[:, : -window_shape[1] - 1]
|
| 16 |
+
)
|
| 17 |
+
|
| 18 |
+
return window_sum
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _window_sum_3d(image, window_shape):
|
| 22 |
+
window_sum = _window_sum_2d(image, window_shape)
|
| 23 |
+
|
| 24 |
+
window_sum = np.cumsum(window_sum, axis=2)
|
| 25 |
+
window_sum = (
|
| 26 |
+
window_sum[:, :, window_shape[2] : -1]
|
| 27 |
+
- window_sum[:, :, : -window_shape[2] - 1]
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
return window_sum
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def match_template(
|
| 34 |
+
image, template, pad_input=False, mode='constant', constant_values=0
|
| 35 |
+
):
|
| 36 |
+
"""Match a template to a 2-D or 3-D image using normalized correlation.
|
| 37 |
+
|
| 38 |
+
The output is an array with values between -1.0 and 1.0. The value at a
|
| 39 |
+
given position corresponds to the correlation coefficient between the image
|
| 40 |
+
and the template.
|
| 41 |
+
|
| 42 |
+
For `pad_input=True` matches correspond to the center and otherwise to the
|
| 43 |
+
top-left corner of the template. To find the best match you must search for
|
| 44 |
+
peaks in the response (output) image.
|
| 45 |
+
|
| 46 |
+
Parameters
|
| 47 |
+
----------
|
| 48 |
+
image : (M, N[, P]) array
|
| 49 |
+
2-D or 3-D input image.
|
| 50 |
+
template : (m, n[, p]) array
|
| 51 |
+
Template to locate. It must be `(m <= M, n <= N[, p <= P])`.
|
| 52 |
+
pad_input : bool
|
| 53 |
+
If True, pad `image` so that output is the same size as the image, and
|
| 54 |
+
output values correspond to the template center. Otherwise, the output
|
| 55 |
+
is an array with shape `(M - m + 1, N - n + 1)` for an `(M, N)` image
|
| 56 |
+
and an `(m, n)` template, and matches correspond to origin
|
| 57 |
+
(top-left corner) of the template.
|
| 58 |
+
mode : see `numpy.pad`, optional
|
| 59 |
+
Padding mode.
|
| 60 |
+
constant_values : see `numpy.pad`, optional
|
| 61 |
+
Constant values used in conjunction with ``mode='constant'``.
|
| 62 |
+
|
| 63 |
+
Returns
|
| 64 |
+
-------
|
| 65 |
+
output : array
|
| 66 |
+
Response image with correlation coefficients.
|
| 67 |
+
|
| 68 |
+
Notes
|
| 69 |
+
-----
|
| 70 |
+
Details on the cross-correlation are presented in [1]_. This implementation
|
| 71 |
+
uses FFT convolutions of the image and the template. Reference [2]_
|
| 72 |
+
presents similar derivations but the approximation presented in this
|
| 73 |
+
reference is not used in our implementation.
|
| 74 |
+
|
| 75 |
+
References
|
| 76 |
+
----------
|
| 77 |
+
.. [1] J. P. Lewis, "Fast Normalized Cross-Correlation", Industrial Light
|
| 78 |
+
and Magic.
|
| 79 |
+
.. [2] Briechle and Hanebeck, "Template Matching using Fast Normalized
|
| 80 |
+
Cross Correlation", Proceedings of the SPIE (2001).
|
| 81 |
+
:DOI:`10.1117/12.421129`
|
| 82 |
+
|
| 83 |
+
Examples
|
| 84 |
+
--------
|
| 85 |
+
>>> template = np.zeros((3, 3))
|
| 86 |
+
>>> template[1, 1] = 1
|
| 87 |
+
>>> template
|
| 88 |
+
array([[0., 0., 0.],
|
| 89 |
+
[0., 1., 0.],
|
| 90 |
+
[0., 0., 0.]])
|
| 91 |
+
>>> image = np.zeros((6, 6))
|
| 92 |
+
>>> image[1, 1] = 1
|
| 93 |
+
>>> image[4, 4] = -1
|
| 94 |
+
>>> image
|
| 95 |
+
array([[ 0., 0., 0., 0., 0., 0.],
|
| 96 |
+
[ 0., 1., 0., 0., 0., 0.],
|
| 97 |
+
[ 0., 0., 0., 0., 0., 0.],
|
| 98 |
+
[ 0., 0., 0., 0., 0., 0.],
|
| 99 |
+
[ 0., 0., 0., 0., -1., 0.],
|
| 100 |
+
[ 0., 0., 0., 0., 0., 0.]])
|
| 101 |
+
>>> result = match_template(image, template)
|
| 102 |
+
>>> np.round(result, 3)
|
| 103 |
+
array([[ 1. , -0.125, 0. , 0. ],
|
| 104 |
+
[-0.125, -0.125, 0. , 0. ],
|
| 105 |
+
[ 0. , 0. , 0.125, 0.125],
|
| 106 |
+
[ 0. , 0. , 0.125, -1. ]])
|
| 107 |
+
>>> result = match_template(image, template, pad_input=True)
|
| 108 |
+
>>> np.round(result, 3)
|
| 109 |
+
array([[-0.125, -0.125, -0.125, 0. , 0. , 0. ],
|
| 110 |
+
[-0.125, 1. , -0.125, 0. , 0. , 0. ],
|
| 111 |
+
[-0.125, -0.125, -0.125, 0. , 0. , 0. ],
|
| 112 |
+
[ 0. , 0. , 0. , 0.125, 0.125, 0.125],
|
| 113 |
+
[ 0. , 0. , 0. , 0.125, -1. , 0.125],
|
| 114 |
+
[ 0. , 0. , 0. , 0.125, 0.125, 0.125]])
|
| 115 |
+
"""
|
| 116 |
+
check_nD(image, (2, 3))
|
| 117 |
+
|
| 118 |
+
if image.ndim < template.ndim:
|
| 119 |
+
raise ValueError(
|
| 120 |
+
"Dimensionality of template must be less than or "
|
| 121 |
+
"equal to the dimensionality of image."
|
| 122 |
+
)
|
| 123 |
+
if np.any(np.less(image.shape, template.shape)):
|
| 124 |
+
raise ValueError("Image must be larger than template.")
|
| 125 |
+
|
| 126 |
+
image_shape = image.shape
|
| 127 |
+
|
| 128 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 129 |
+
image = image.astype(float_dtype, copy=False)
|
| 130 |
+
|
| 131 |
+
pad_width = tuple((width, width) for width in template.shape)
|
| 132 |
+
if mode == 'constant':
|
| 133 |
+
image = np.pad(
|
| 134 |
+
image, pad_width=pad_width, mode=mode, constant_values=constant_values
|
| 135 |
+
)
|
| 136 |
+
else:
|
| 137 |
+
image = np.pad(image, pad_width=pad_width, mode=mode)
|
| 138 |
+
|
| 139 |
+
# Use special case for 2-D images for much better performance in
|
| 140 |
+
# computation of integral images
|
| 141 |
+
if image.ndim == 2:
|
| 142 |
+
image_window_sum = _window_sum_2d(image, template.shape)
|
| 143 |
+
image_window_sum2 = _window_sum_2d(image**2, template.shape)
|
| 144 |
+
elif image.ndim == 3:
|
| 145 |
+
image_window_sum = _window_sum_3d(image, template.shape)
|
| 146 |
+
image_window_sum2 = _window_sum_3d(image**2, template.shape)
|
| 147 |
+
|
| 148 |
+
template_mean = template.mean()
|
| 149 |
+
template_volume = math.prod(template.shape)
|
| 150 |
+
template_ssd = np.sum((template - template_mean) ** 2)
|
| 151 |
+
|
| 152 |
+
if image.ndim == 2:
|
| 153 |
+
xcorr = fftconvolve(image, template[::-1, ::-1], mode="valid")[1:-1, 1:-1]
|
| 154 |
+
elif image.ndim == 3:
|
| 155 |
+
xcorr = fftconvolve(image, template[::-1, ::-1, ::-1], mode="valid")[
|
| 156 |
+
1:-1, 1:-1, 1:-1
|
| 157 |
+
]
|
| 158 |
+
|
| 159 |
+
numerator = xcorr - image_window_sum * template_mean
|
| 160 |
+
|
| 161 |
+
denominator = image_window_sum2
|
| 162 |
+
np.multiply(image_window_sum, image_window_sum, out=image_window_sum)
|
| 163 |
+
np.divide(image_window_sum, template_volume, out=image_window_sum)
|
| 164 |
+
denominator -= image_window_sum
|
| 165 |
+
denominator *= template_ssd
|
| 166 |
+
np.maximum(denominator, 0, out=denominator) # sqrt of negative number not allowed
|
| 167 |
+
np.sqrt(denominator, out=denominator)
|
| 168 |
+
|
| 169 |
+
response = np.zeros_like(xcorr, dtype=float_dtype)
|
| 170 |
+
|
| 171 |
+
# avoid zero-division
|
| 172 |
+
mask = denominator > np.finfo(float_dtype).eps
|
| 173 |
+
|
| 174 |
+
response[mask] = numerator[mask] / denominator[mask]
|
| 175 |
+
|
| 176 |
+
slices = []
|
| 177 |
+
for i in range(template.ndim):
|
| 178 |
+
if pad_input:
|
| 179 |
+
d0 = (template.shape[i] - 1) // 2
|
| 180 |
+
d1 = d0 + image_shape[i]
|
| 181 |
+
else:
|
| 182 |
+
d0 = template.shape[i] - 1
|
| 183 |
+
d1 = d0 + image_shape[i] - template.shape[i] + 1
|
| 184 |
+
slices.append(slice(d0, d1))
|
| 185 |
+
|
| 186 |
+
return response[tuple(slices)]
|
envs/kitoverlay/skimage/feature/texture.py
ADDED
|
@@ -0,0 +1,562 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Methods to characterize image textures.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
import warnings
|
| 6 |
+
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
from .._shared.utils import check_nD
|
| 10 |
+
from ..color import gray2rgb
|
| 11 |
+
from ..util import img_as_float
|
| 12 |
+
from ._texture import _glcm_loop, _local_binary_pattern, _multiblock_lbp
|
| 13 |
+
|
| 14 |
+
|
| 15 |
+
def graycomatrix(image, distances, angles, levels=None, symmetric=False, normed=False):
|
| 16 |
+
"""Calculate the gray-level co-occurrence matrix.
|
| 17 |
+
|
| 18 |
+
A gray level co-occurrence matrix is a histogram of co-occurring
|
| 19 |
+
grayscale values at a given offset over an image.
|
| 20 |
+
|
| 21 |
+
.. versionchanged:: 0.19
|
| 22 |
+
`greymatrix` was renamed to `graymatrix` in 0.19.
|
| 23 |
+
|
| 24 |
+
Parameters
|
| 25 |
+
----------
|
| 26 |
+
image : array_like
|
| 27 |
+
Integer typed input image. Only positive valued images are supported.
|
| 28 |
+
If type is other than uint8, the argument `levels` needs to be set.
|
| 29 |
+
distances : array_like
|
| 30 |
+
List of pixel pair distance offsets.
|
| 31 |
+
angles : array_like
|
| 32 |
+
List of pixel pair angles in radians.
|
| 33 |
+
levels : int, optional
|
| 34 |
+
The input image should contain integers in [0, `levels`-1],
|
| 35 |
+
where levels indicate the number of gray-levels counted
|
| 36 |
+
(typically 256 for an 8-bit image). This argument is required for
|
| 37 |
+
16-bit images or higher and is typically the maximum of the image.
|
| 38 |
+
As the output matrix is at least `levels` x `levels`, it might
|
| 39 |
+
be preferable to use binning of the input image rather than
|
| 40 |
+
large values for `levels`.
|
| 41 |
+
symmetric : bool, optional
|
| 42 |
+
If True, the output matrix `P[:, :, d, theta]` is symmetric. This
|
| 43 |
+
is accomplished by ignoring the order of value pairs, so both
|
| 44 |
+
(i, j) and (j, i) are accumulated when (i, j) is encountered
|
| 45 |
+
for a given offset. The default is False.
|
| 46 |
+
normed : bool, optional
|
| 47 |
+
If True, normalize each matrix `P[:, :, d, theta]` by dividing
|
| 48 |
+
by the total number of accumulated co-occurrences for the given
|
| 49 |
+
offset. The elements of the resulting matrix sum to 1. The
|
| 50 |
+
default is False.
|
| 51 |
+
|
| 52 |
+
Returns
|
| 53 |
+
-------
|
| 54 |
+
P : 4-D ndarray
|
| 55 |
+
The gray-level co-occurrence histogram. The value
|
| 56 |
+
`P[i,j,d,theta]` is the number of times that gray-level `j`
|
| 57 |
+
occurs at a distance `d` and at an angle `theta` from
|
| 58 |
+
gray-level `i`. If `normed` is `False`, the output is of
|
| 59 |
+
type uint32, otherwise it is float64. The dimensions are:
|
| 60 |
+
levels x levels x number of distances x number of angles.
|
| 61 |
+
|
| 62 |
+
References
|
| 63 |
+
----------
|
| 64 |
+
.. [1] M. Hall-Beyer, 2007. GLCM Texture: A Tutorial
|
| 65 |
+
https://prism.ucalgary.ca/handle/1880/51900
|
| 66 |
+
DOI:`10.11575/PRISM/33280`
|
| 67 |
+
.. [2] R.M. Haralick, K. Shanmugam, and I. Dinstein, "Textural features for
|
| 68 |
+
image classification", IEEE Transactions on Systems, Man, and
|
| 69 |
+
Cybernetics, vol. SMC-3, no. 6, pp. 610-621, Nov. 1973.
|
| 70 |
+
:DOI:`10.1109/TSMC.1973.4309314`
|
| 71 |
+
.. [3] M. Nadler and E.P. Smith, Pattern Recognition Engineering,
|
| 72 |
+
Wiley-Interscience, 1993.
|
| 73 |
+
.. [4] Wikipedia, https://en.wikipedia.org/wiki/Co-occurrence_matrix
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
Examples
|
| 77 |
+
--------
|
| 78 |
+
Compute 4 GLCMs using 1-pixel distance and 4 different angles. For example,
|
| 79 |
+
an angle of 0 radians refers to the neighboring pixel to the right;
|
| 80 |
+
pi/4 radians to the top-right diagonal neighbor; pi/2 radians to the pixel
|
| 81 |
+
above, and so forth.
|
| 82 |
+
|
| 83 |
+
>>> image = np.array([[0, 0, 1, 1],
|
| 84 |
+
... [0, 0, 1, 1],
|
| 85 |
+
... [0, 2, 2, 2],
|
| 86 |
+
... [2, 2, 3, 3]], dtype=np.uint8)
|
| 87 |
+
>>> result = graycomatrix(image, [1], [0, np.pi/4, np.pi/2, 3*np.pi/4],
|
| 88 |
+
... levels=4)
|
| 89 |
+
>>> result[:, :, 0, 0]
|
| 90 |
+
array([[2, 2, 1, 0],
|
| 91 |
+
[0, 2, 0, 0],
|
| 92 |
+
[0, 0, 3, 1],
|
| 93 |
+
[0, 0, 0, 1]], dtype=uint32)
|
| 94 |
+
>>> result[:, :, 0, 1]
|
| 95 |
+
array([[1, 1, 3, 0],
|
| 96 |
+
[0, 1, 1, 0],
|
| 97 |
+
[0, 0, 0, 2],
|
| 98 |
+
[0, 0, 0, 0]], dtype=uint32)
|
| 99 |
+
>>> result[:, :, 0, 2]
|
| 100 |
+
array([[3, 0, 2, 0],
|
| 101 |
+
[0, 2, 2, 0],
|
| 102 |
+
[0, 0, 1, 2],
|
| 103 |
+
[0, 0, 0, 0]], dtype=uint32)
|
| 104 |
+
>>> result[:, :, 0, 3]
|
| 105 |
+
array([[2, 0, 0, 0],
|
| 106 |
+
[1, 1, 2, 0],
|
| 107 |
+
[0, 0, 2, 1],
|
| 108 |
+
[0, 0, 0, 0]], dtype=uint32)
|
| 109 |
+
|
| 110 |
+
"""
|
| 111 |
+
check_nD(image, 2)
|
| 112 |
+
check_nD(distances, 1, 'distances')
|
| 113 |
+
check_nD(angles, 1, 'angles')
|
| 114 |
+
|
| 115 |
+
image = np.ascontiguousarray(image)
|
| 116 |
+
|
| 117 |
+
image_max = image.max()
|
| 118 |
+
|
| 119 |
+
if np.issubdtype(image.dtype, np.floating):
|
| 120 |
+
raise ValueError(
|
| 121 |
+
"Float images are not supported by graycomatrix. "
|
| 122 |
+
"Convert the image to an unsigned integer type."
|
| 123 |
+
)
|
| 124 |
+
|
| 125 |
+
# for image type > 8bit, levels must be set.
|
| 126 |
+
if image.dtype not in (np.uint8, np.int8) and levels is None:
|
| 127 |
+
raise ValueError(
|
| 128 |
+
"The levels argument is required for data types "
|
| 129 |
+
"other than uint8. The resulting matrix will be at "
|
| 130 |
+
"least levels ** 2 in size."
|
| 131 |
+
)
|
| 132 |
+
|
| 133 |
+
if np.issubdtype(image.dtype, np.signedinteger) and np.any(image < 0):
|
| 134 |
+
raise ValueError("Negative-valued images are not supported.")
|
| 135 |
+
|
| 136 |
+
if levels is None:
|
| 137 |
+
levels = 256
|
| 138 |
+
|
| 139 |
+
if image_max >= levels:
|
| 140 |
+
raise ValueError(
|
| 141 |
+
"The maximum grayscale value in the image should be "
|
| 142 |
+
"smaller than the number of levels."
|
| 143 |
+
)
|
| 144 |
+
|
| 145 |
+
distances = np.ascontiguousarray(distances, dtype=np.float64)
|
| 146 |
+
angles = np.ascontiguousarray(angles, dtype=np.float64)
|
| 147 |
+
|
| 148 |
+
P = np.zeros(
|
| 149 |
+
(levels, levels, len(distances), len(angles)), dtype=np.uint32, order='C'
|
| 150 |
+
)
|
| 151 |
+
|
| 152 |
+
# count co-occurences
|
| 153 |
+
_glcm_loop(image, distances, angles, levels, P)
|
| 154 |
+
|
| 155 |
+
# make each GLMC symmetric
|
| 156 |
+
if symmetric:
|
| 157 |
+
Pt = np.transpose(P, (1, 0, 2, 3))
|
| 158 |
+
P = P + Pt
|
| 159 |
+
|
| 160 |
+
# normalize each GLCM
|
| 161 |
+
if normed:
|
| 162 |
+
P = P.astype(np.float64)
|
| 163 |
+
glcm_sums = np.sum(P, axis=(0, 1), keepdims=True)
|
| 164 |
+
glcm_sums[glcm_sums == 0] = 1
|
| 165 |
+
P /= glcm_sums
|
| 166 |
+
|
| 167 |
+
return P
|
| 168 |
+
|
| 169 |
+
|
| 170 |
+
def graycoprops(P, prop='contrast'):
|
| 171 |
+
"""Calculate texture properties of a GLCM.
|
| 172 |
+
|
| 173 |
+
Compute a feature of a gray level co-occurrence matrix to serve as
|
| 174 |
+
a compact summary of the matrix. The properties are computed as
|
| 175 |
+
follows:
|
| 176 |
+
|
| 177 |
+
- 'contrast': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}(i-j)^2`
|
| 178 |
+
- 'dissimilarity': :math:`\\sum_{i,j=0}^{levels-1}P_{i,j}|i-j|`
|
| 179 |
+
- 'homogeneity': :math:`\\sum_{i,j=0}^{levels-1}\\frac{P_{i,j}}{1+(i-j)^2}`
|
| 180 |
+
- 'ASM': :math:`\\sum_{i,j=0}^{levels-1} P_{i,j}^2`
|
| 181 |
+
- 'energy': :math:`\\sqrt{ASM}`
|
| 182 |
+
- 'correlation':
|
| 183 |
+
.. math:: \\sum_{i,j=0}^{levels-1} P_{i,j}\\left[\\frac{(i-\\mu_i) \\
|
| 184 |
+
(j-\\mu_j)}{\\sqrt{(\\sigma_i^2)(\\sigma_j^2)}}\\right]
|
| 185 |
+
- 'mean': :math:`\\sum_{i=0}^{levels-1} i*P_{i}`
|
| 186 |
+
- 'variance': :math:`\\sum_{i=0}^{levels-1} P_{i}*(i-mean)^2`
|
| 187 |
+
- 'std': :math:`\\sqrt{variance}`
|
| 188 |
+
- 'entropy': :math:`\\sum_{i,j=0}^{levels-1} -P_{i,j}*log(P_{i,j})`
|
| 189 |
+
|
| 190 |
+
Each GLCM is normalized to have a sum of 1 before the computation of
|
| 191 |
+
texture properties.
|
| 192 |
+
|
| 193 |
+
.. versionchanged:: 0.19
|
| 194 |
+
`greycoprops` was renamed to `graycoprops` in 0.19.
|
| 195 |
+
|
| 196 |
+
Parameters
|
| 197 |
+
----------
|
| 198 |
+
P : ndarray
|
| 199 |
+
Input array. `P` is the gray-level co-occurrence histogram
|
| 200 |
+
for which to compute the specified property. The value
|
| 201 |
+
`P[i,j,d,theta]` is the number of times that gray-level j
|
| 202 |
+
occurs at a distance d and at an angle theta from
|
| 203 |
+
gray-level i.
|
| 204 |
+
prop : {'contrast', 'dissimilarity', 'homogeneity', 'energy', \
|
| 205 |
+
'correlation', 'ASM', 'mean', 'variance', 'std', 'entropy'}, optional
|
| 206 |
+
The property of the GLCM to compute. The default is 'contrast'.
|
| 207 |
+
|
| 208 |
+
Returns
|
| 209 |
+
-------
|
| 210 |
+
results : 2-D ndarray
|
| 211 |
+
2-dimensional array. `results[d, a]` is the property 'prop' for
|
| 212 |
+
the d'th distance and the a'th angle.
|
| 213 |
+
|
| 214 |
+
References
|
| 215 |
+
----------
|
| 216 |
+
.. [1] M. Hall-Beyer, 2007. GLCM Texture: A Tutorial v. 1.0 through 3.0.
|
| 217 |
+
The GLCM Tutorial Home Page,
|
| 218 |
+
https://prism.ucalgary.ca/handle/1880/51900
|
| 219 |
+
DOI:`10.11575/PRISM/33280`
|
| 220 |
+
|
| 221 |
+
Examples
|
| 222 |
+
--------
|
| 223 |
+
Compute the contrast for GLCMs with distances [1, 2] and angles
|
| 224 |
+
[0 degrees, 90 degrees]
|
| 225 |
+
|
| 226 |
+
>>> image = np.array([[0, 0, 1, 1],
|
| 227 |
+
... [0, 0, 1, 1],
|
| 228 |
+
... [0, 2, 2, 2],
|
| 229 |
+
... [2, 2, 3, 3]], dtype=np.uint8)
|
| 230 |
+
>>> g = graycomatrix(image, [1, 2], [0, np.pi/2], levels=4,
|
| 231 |
+
... normed=True, symmetric=True)
|
| 232 |
+
>>> contrast = graycoprops(g, 'contrast')
|
| 233 |
+
>>> contrast
|
| 234 |
+
array([[0.58333333, 1. ],
|
| 235 |
+
[1.25 , 2.75 ]])
|
| 236 |
+
|
| 237 |
+
"""
|
| 238 |
+
|
| 239 |
+
def glcm_mean():
|
| 240 |
+
I = np.arange(num_level).reshape((num_level, 1, 1, 1))
|
| 241 |
+
mean = np.sum(I * P, axis=(0, 1))
|
| 242 |
+
return I, mean
|
| 243 |
+
|
| 244 |
+
check_nD(P, 4, 'P')
|
| 245 |
+
|
| 246 |
+
(num_level, num_level2, num_dist, num_angle) = P.shape
|
| 247 |
+
if num_level != num_level2:
|
| 248 |
+
raise ValueError('num_level and num_level2 must be equal.')
|
| 249 |
+
if num_dist <= 0:
|
| 250 |
+
raise ValueError('num_dist must be positive.')
|
| 251 |
+
if num_angle <= 0:
|
| 252 |
+
raise ValueError('num_angle must be positive.')
|
| 253 |
+
|
| 254 |
+
# normalize each GLCM
|
| 255 |
+
P = P.astype(np.float64)
|
| 256 |
+
glcm_sums = np.sum(P, axis=(0, 1), keepdims=True)
|
| 257 |
+
glcm_sums[glcm_sums == 0] = 1
|
| 258 |
+
P /= glcm_sums
|
| 259 |
+
|
| 260 |
+
# create weights for specified property
|
| 261 |
+
I, J = np.ogrid[0:num_level, 0:num_level]
|
| 262 |
+
if prop == 'contrast':
|
| 263 |
+
weights = (I - J) ** 2
|
| 264 |
+
elif prop == 'dissimilarity':
|
| 265 |
+
weights = np.abs(I - J)
|
| 266 |
+
elif prop == 'homogeneity':
|
| 267 |
+
weights = 1.0 / (1.0 + (I - J) ** 2)
|
| 268 |
+
elif prop in ['ASM', 'energy', 'correlation', 'entropy', 'variance', 'mean', 'std']:
|
| 269 |
+
pass
|
| 270 |
+
else:
|
| 271 |
+
raise ValueError(f'{prop} is an invalid property')
|
| 272 |
+
|
| 273 |
+
# compute property for each GLCM
|
| 274 |
+
if prop == 'energy':
|
| 275 |
+
asm = np.sum(P**2, axis=(0, 1))
|
| 276 |
+
results = np.sqrt(asm)
|
| 277 |
+
elif prop == 'ASM':
|
| 278 |
+
results = np.sum(P**2, axis=(0, 1))
|
| 279 |
+
elif prop == 'mean':
|
| 280 |
+
_, results = glcm_mean()
|
| 281 |
+
elif prop == 'variance':
|
| 282 |
+
I, mean = glcm_mean()
|
| 283 |
+
results = np.sum(P * ((I - mean) ** 2), axis=(0, 1))
|
| 284 |
+
elif prop == 'std':
|
| 285 |
+
I, mean = glcm_mean()
|
| 286 |
+
var = np.sum(P * ((I - mean) ** 2), axis=(0, 1))
|
| 287 |
+
results = np.sqrt(var)
|
| 288 |
+
elif prop == 'entropy':
|
| 289 |
+
ln = -np.log(P, where=(P != 0), out=np.zeros_like(P))
|
| 290 |
+
results = np.sum(P * ln, axis=(0, 1))
|
| 291 |
+
|
| 292 |
+
elif prop == 'correlation':
|
| 293 |
+
results = np.zeros((num_dist, num_angle), dtype=np.float64)
|
| 294 |
+
I = np.array(range(num_level)).reshape((num_level, 1, 1, 1))
|
| 295 |
+
J = np.array(range(num_level)).reshape((1, num_level, 1, 1))
|
| 296 |
+
diff_i = I - np.sum(I * P, axis=(0, 1))
|
| 297 |
+
diff_j = J - np.sum(J * P, axis=(0, 1))
|
| 298 |
+
|
| 299 |
+
std_i = np.sqrt(np.sum(P * (diff_i) ** 2, axis=(0, 1)))
|
| 300 |
+
std_j = np.sqrt(np.sum(P * (diff_j) ** 2, axis=(0, 1)))
|
| 301 |
+
cov = np.sum(P * (diff_i * diff_j), axis=(0, 1))
|
| 302 |
+
|
| 303 |
+
# handle the special case of standard deviations near zero
|
| 304 |
+
mask_0 = std_i < 1e-15
|
| 305 |
+
mask_0[std_j < 1e-15] = True
|
| 306 |
+
results[mask_0] = 1
|
| 307 |
+
|
| 308 |
+
# handle the standard case
|
| 309 |
+
mask_1 = ~mask_0
|
| 310 |
+
results[mask_1] = cov[mask_1] / (std_i[mask_1] * std_j[mask_1])
|
| 311 |
+
elif prop in ['contrast', 'dissimilarity', 'homogeneity']:
|
| 312 |
+
weights = weights.reshape((num_level, num_level, 1, 1))
|
| 313 |
+
results = np.sum(P * weights, axis=(0, 1))
|
| 314 |
+
|
| 315 |
+
return results
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def local_binary_pattern(image, P, R, method='default'):
|
| 319 |
+
"""Compute the local binary patterns (LBP) of an image.
|
| 320 |
+
|
| 321 |
+
LBP is a visual descriptor often used in texture classification.
|
| 322 |
+
|
| 323 |
+
Parameters
|
| 324 |
+
----------
|
| 325 |
+
image : (M, N) array
|
| 326 |
+
2D grayscale image.
|
| 327 |
+
P : int
|
| 328 |
+
Number of circularly symmetric neighbor set points (quantization of
|
| 329 |
+
the angular space).
|
| 330 |
+
R : float
|
| 331 |
+
Radius of circle (spatial resolution of the operator).
|
| 332 |
+
method : str {'default', 'ror', 'uniform', 'nri_uniform', 'var'}, optional
|
| 333 |
+
Method to determine the pattern:
|
| 334 |
+
|
| 335 |
+
``default``
|
| 336 |
+
Original local binary pattern which is grayscale invariant but not
|
| 337 |
+
rotation invariant.
|
| 338 |
+
``ror``
|
| 339 |
+
Extension of default pattern which is grayscale invariant and
|
| 340 |
+
rotation invariant.
|
| 341 |
+
``uniform``
|
| 342 |
+
Uniform pattern which is grayscale invariant and rotation
|
| 343 |
+
invariant, offering finer quantization of the angular space.
|
| 344 |
+
For details, see [1]_.
|
| 345 |
+
``nri_uniform``
|
| 346 |
+
Variant of uniform pattern which is grayscale invariant but not
|
| 347 |
+
rotation invariant. For details, see [2]_ and [3]_.
|
| 348 |
+
``var``
|
| 349 |
+
Variance of local image texture (related to contrast)
|
| 350 |
+
which is rotation invariant but not grayscale invariant.
|
| 351 |
+
|
| 352 |
+
Returns
|
| 353 |
+
-------
|
| 354 |
+
output : (M, N) array
|
| 355 |
+
LBP image.
|
| 356 |
+
|
| 357 |
+
References
|
| 358 |
+
----------
|
| 359 |
+
.. [1] T. Ojala, M. Pietikainen, T. Maenpaa, "Multiresolution gray-scale
|
| 360 |
+
and rotation invariant texture classification with local binary
|
| 361 |
+
patterns", IEEE Transactions on Pattern Analysis and Machine
|
| 362 |
+
Intelligence, vol. 24, no. 7, pp. 971-987, July 2002
|
| 363 |
+
:DOI:`10.1109/TPAMI.2002.1017623`
|
| 364 |
+
.. [2] T. Ahonen, A. Hadid and M. Pietikainen. "Face recognition with
|
| 365 |
+
local binary patterns", in Proc. Eighth European Conf. Computer
|
| 366 |
+
Vision, Prague, Czech Republic, May 11-14, 2004, pp. 469-481, 2004.
|
| 367 |
+
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.214.6851
|
| 368 |
+
:DOI:`10.1007/978-3-540-24670-1_36`
|
| 369 |
+
.. [3] T. Ahonen, A. Hadid and M. Pietikainen, "Face Description with
|
| 370 |
+
Local Binary Patterns: Application to Face Recognition",
|
| 371 |
+
IEEE Transactions on Pattern Analysis and Machine Intelligence,
|
| 372 |
+
vol. 28, no. 12, pp. 2037-2041, Dec. 2006
|
| 373 |
+
:DOI:`10.1109/TPAMI.2006.244`
|
| 374 |
+
"""
|
| 375 |
+
check_nD(image, 2)
|
| 376 |
+
|
| 377 |
+
methods = {
|
| 378 |
+
'default': ord('D'),
|
| 379 |
+
'ror': ord('R'),
|
| 380 |
+
'uniform': ord('U'),
|
| 381 |
+
'nri_uniform': ord('N'),
|
| 382 |
+
'var': ord('V'),
|
| 383 |
+
}
|
| 384 |
+
if np.issubdtype(image.dtype, np.floating):
|
| 385 |
+
warnings.warn(
|
| 386 |
+
"Applying `local_binary_pattern` to floating-point images may "
|
| 387 |
+
"give unexpected results when small numerical differences between "
|
| 388 |
+
"adjacent pixels are present. It is recommended to use this "
|
| 389 |
+
"function with images of integer dtype."
|
| 390 |
+
)
|
| 391 |
+
image = np.ascontiguousarray(image, dtype=np.float64)
|
| 392 |
+
output = _local_binary_pattern(image, P, R, methods[method.lower()])
|
| 393 |
+
return output
|
| 394 |
+
|
| 395 |
+
|
| 396 |
+
def multiblock_lbp(int_image, r, c, width, height):
|
| 397 |
+
"""Multi-block local binary pattern (MB-LBP).
|
| 398 |
+
|
| 399 |
+
The features are calculated similarly to local binary patterns (LBPs),
|
| 400 |
+
(See :py:meth:`local_binary_pattern`) except that summed blocks are
|
| 401 |
+
used instead of individual pixel values.
|
| 402 |
+
|
| 403 |
+
MB-LBP is an extension of LBP that can be computed on multiple scales
|
| 404 |
+
in constant time using the integral image. Nine equally-sized rectangles
|
| 405 |
+
are used to compute a feature. For each rectangle, the sum of the pixel
|
| 406 |
+
intensities is computed. Comparisons of these sums to that of the central
|
| 407 |
+
rectangle determine the feature, similarly to LBP.
|
| 408 |
+
|
| 409 |
+
Parameters
|
| 410 |
+
----------
|
| 411 |
+
int_image : (N, M) array
|
| 412 |
+
Integral image.
|
| 413 |
+
r : int
|
| 414 |
+
Row-coordinate of top left corner of a rectangle containing feature.
|
| 415 |
+
c : int
|
| 416 |
+
Column-coordinate of top left corner of a rectangle containing feature.
|
| 417 |
+
width : int
|
| 418 |
+
Width of one of the 9 equal rectangles that will be used to compute
|
| 419 |
+
a feature.
|
| 420 |
+
height : int
|
| 421 |
+
Height of one of the 9 equal rectangles that will be used to compute
|
| 422 |
+
a feature.
|
| 423 |
+
|
| 424 |
+
Returns
|
| 425 |
+
-------
|
| 426 |
+
output : int
|
| 427 |
+
8-bit MB-LBP feature descriptor.
|
| 428 |
+
|
| 429 |
+
References
|
| 430 |
+
----------
|
| 431 |
+
.. [1] L. Zhang, R. Chu, S. Xiang, S. Liao, S.Z. Li. "Face Detection Based
|
| 432 |
+
on Multi-Block LBP Representation", In Proceedings: Advances in
|
| 433 |
+
Biometrics, International Conference, ICB 2007, Seoul, Korea.
|
| 434 |
+
http://www.cbsr.ia.ac.cn/users/scliao/papers/Zhang-ICB07-MBLBP.pdf
|
| 435 |
+
:DOI:`10.1007/978-3-540-74549-5_2`
|
| 436 |
+
"""
|
| 437 |
+
|
| 438 |
+
int_image = np.ascontiguousarray(int_image, dtype=np.float32)
|
| 439 |
+
lbp_code = _multiblock_lbp(int_image, r, c, width, height)
|
| 440 |
+
return lbp_code
|
| 441 |
+
|
| 442 |
+
|
| 443 |
+
def draw_multiblock_lbp(
|
| 444 |
+
image,
|
| 445 |
+
r,
|
| 446 |
+
c,
|
| 447 |
+
width,
|
| 448 |
+
height,
|
| 449 |
+
lbp_code=0,
|
| 450 |
+
color_greater_block=(1, 1, 1),
|
| 451 |
+
color_less_block=(0, 0.69, 0.96),
|
| 452 |
+
alpha=0.5,
|
| 453 |
+
):
|
| 454 |
+
"""Multi-block local binary pattern visualization.
|
| 455 |
+
|
| 456 |
+
Blocks with higher sums are colored with alpha-blended white rectangles,
|
| 457 |
+
whereas blocks with lower sums are colored alpha-blended cyan. Colors
|
| 458 |
+
and the `alpha` parameter can be changed.
|
| 459 |
+
|
| 460 |
+
Parameters
|
| 461 |
+
----------
|
| 462 |
+
image : ndarray of float or uint
|
| 463 |
+
Image on which to visualize the pattern.
|
| 464 |
+
r : int
|
| 465 |
+
Row-coordinate of top left corner of a rectangle containing feature.
|
| 466 |
+
c : int
|
| 467 |
+
Column-coordinate of top left corner of a rectangle containing feature.
|
| 468 |
+
width : int
|
| 469 |
+
Width of one of 9 equal rectangles that will be used to compute
|
| 470 |
+
a feature.
|
| 471 |
+
height : int
|
| 472 |
+
Height of one of 9 equal rectangles that will be used to compute
|
| 473 |
+
a feature.
|
| 474 |
+
lbp_code : int
|
| 475 |
+
The descriptor of feature to visualize. If not provided, the
|
| 476 |
+
descriptor with 0 value will be used.
|
| 477 |
+
color_greater_block : tuple of 3 floats
|
| 478 |
+
Floats specifying the color for the block that has greater
|
| 479 |
+
intensity value. They should be in the range [0, 1].
|
| 480 |
+
Corresponding values define (R, G, B) values. Default value
|
| 481 |
+
is white (1, 1, 1).
|
| 482 |
+
color_greater_block : tuple of 3 floats
|
| 483 |
+
Floats specifying the color for the block that has greater intensity
|
| 484 |
+
value. They should be in the range [0, 1]. Corresponding values define
|
| 485 |
+
(R, G, B) values. Default value is cyan (0, 0.69, 0.96).
|
| 486 |
+
alpha : float
|
| 487 |
+
Value in the range [0, 1] that specifies opacity of visualization.
|
| 488 |
+
1 - fully transparent, 0 - opaque.
|
| 489 |
+
|
| 490 |
+
Returns
|
| 491 |
+
-------
|
| 492 |
+
output : ndarray of float
|
| 493 |
+
Image with MB-LBP visualization.
|
| 494 |
+
|
| 495 |
+
References
|
| 496 |
+
----------
|
| 497 |
+
.. [1] L. Zhang, R. Chu, S. Xiang, S. Liao, S.Z. Li. "Face Detection Based
|
| 498 |
+
on Multi-Block LBP Representation", In Proceedings: Advances in
|
| 499 |
+
Biometrics, International Conference, ICB 2007, Seoul, Korea.
|
| 500 |
+
http://www.cbsr.ia.ac.cn/users/scliao/papers/Zhang-ICB07-MBLBP.pdf
|
| 501 |
+
:DOI:`10.1007/978-3-540-74549-5_2`
|
| 502 |
+
"""
|
| 503 |
+
|
| 504 |
+
# Default colors for regions.
|
| 505 |
+
# White is for the blocks that are brighter.
|
| 506 |
+
# Cyan is for the blocks that has less intensity.
|
| 507 |
+
color_greater_block = np.asarray(color_greater_block, dtype=np.float64)
|
| 508 |
+
color_less_block = np.asarray(color_less_block, dtype=np.float64)
|
| 509 |
+
|
| 510 |
+
# Copy array to avoid the changes to the original one.
|
| 511 |
+
output = np.copy(image)
|
| 512 |
+
|
| 513 |
+
# As the visualization uses RGB color we need 3 bands.
|
| 514 |
+
if len(image.shape) < 3:
|
| 515 |
+
output = gray2rgb(image)
|
| 516 |
+
|
| 517 |
+
# Colors are specified in floats.
|
| 518 |
+
output = img_as_float(output)
|
| 519 |
+
|
| 520 |
+
# Offsets of neighbor rectangles relative to central one.
|
| 521 |
+
# It has order starting from top left and going clockwise.
|
| 522 |
+
neighbor_rect_offsets = (
|
| 523 |
+
(-1, -1),
|
| 524 |
+
(-1, 0),
|
| 525 |
+
(-1, 1),
|
| 526 |
+
(0, 1),
|
| 527 |
+
(1, 1),
|
| 528 |
+
(1, 0),
|
| 529 |
+
(1, -1),
|
| 530 |
+
(0, -1),
|
| 531 |
+
)
|
| 532 |
+
|
| 533 |
+
# Pre-multiply the offsets with width and height.
|
| 534 |
+
neighbor_rect_offsets = np.array(neighbor_rect_offsets)
|
| 535 |
+
neighbor_rect_offsets[:, 0] *= height
|
| 536 |
+
neighbor_rect_offsets[:, 1] *= width
|
| 537 |
+
|
| 538 |
+
# Top-left coordinates of central rectangle.
|
| 539 |
+
central_rect_r = r + height
|
| 540 |
+
central_rect_c = c + width
|
| 541 |
+
|
| 542 |
+
for element_num, offset in enumerate(neighbor_rect_offsets):
|
| 543 |
+
offset_r, offset_c = offset
|
| 544 |
+
|
| 545 |
+
curr_r = central_rect_r + offset_r
|
| 546 |
+
curr_c = central_rect_c + offset_c
|
| 547 |
+
|
| 548 |
+
has_greater_value = lbp_code & (1 << (7 - element_num))
|
| 549 |
+
|
| 550 |
+
# Mix-in the visualization colors.
|
| 551 |
+
if has_greater_value:
|
| 552 |
+
new_value = (1 - alpha) * output[
|
| 553 |
+
curr_r : curr_r + height, curr_c : curr_c + width
|
| 554 |
+
] + alpha * color_greater_block
|
| 555 |
+
output[curr_r : curr_r + height, curr_c : curr_c + width] = new_value
|
| 556 |
+
else:
|
| 557 |
+
new_value = (1 - alpha) * output[
|
| 558 |
+
curr_r : curr_r + height, curr_c : curr_c + width
|
| 559 |
+
] + alpha * color_less_block
|
| 560 |
+
output[curr_r : curr_r + height, curr_c : curr_c + width] = new_value
|
| 561 |
+
|
| 562 |
+
return output
|
envs/kitoverlay/skimage/feature/util.py
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
+
self.keypoints_ = np.array([])
|
| 13 |
+
|
| 14 |
+
def detect(self, image):
|
| 15 |
+
"""Detect keypoints in image.
|
| 16 |
+
|
| 17 |
+
Parameters
|
| 18 |
+
----------
|
| 19 |
+
image : 2D array
|
| 20 |
+
Input image.
|
| 21 |
+
|
| 22 |
+
"""
|
| 23 |
+
raise NotImplementedError()
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class DescriptorExtractor:
|
| 27 |
+
def __init__(self):
|
| 28 |
+
self.descriptors_ = np.array([])
|
| 29 |
+
|
| 30 |
+
def extract(self, image, keypoints):
|
| 31 |
+
"""Extract feature descriptors in image for given keypoints.
|
| 32 |
+
|
| 33 |
+
Parameters
|
| 34 |
+
----------
|
| 35 |
+
image : 2D array
|
| 36 |
+
Input image.
|
| 37 |
+
keypoints : (N, 2) array
|
| 38 |
+
Keypoint locations as ``(row, col)``.
|
| 39 |
+
|
| 40 |
+
"""
|
| 41 |
+
raise NotImplementedError()
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def plot_matched_features(
|
| 45 |
+
image0,
|
| 46 |
+
image1,
|
| 47 |
+
*,
|
| 48 |
+
keypoints0,
|
| 49 |
+
keypoints1,
|
| 50 |
+
matches,
|
| 51 |
+
ax,
|
| 52 |
+
keypoints_color='k',
|
| 53 |
+
matches_color=None,
|
| 54 |
+
only_matches=False,
|
| 55 |
+
alignment='horizontal',
|
| 56 |
+
):
|
| 57 |
+
"""Plot matched features between two images.
|
| 58 |
+
|
| 59 |
+
.. versionadded:: 0.23
|
| 60 |
+
|
| 61 |
+
Parameters
|
| 62 |
+
----------
|
| 63 |
+
image0 : (N, M [, 3]) array
|
| 64 |
+
First image.
|
| 65 |
+
image1 : (N, M [, 3]) array
|
| 66 |
+
Second image.
|
| 67 |
+
keypoints0 : (K1, 2) array
|
| 68 |
+
First keypoint coordinates as ``(row, col)``.
|
| 69 |
+
keypoints1 : (K2, 2) array
|
| 70 |
+
Second keypoint coordinates as ``(row, col)``.
|
| 71 |
+
matches : (Q, 2) array
|
| 72 |
+
Indices of corresponding matches in first and second sets of
|
| 73 |
+
descriptors, where `matches[:, 0]` (resp. `matches[:, 1]`) contains
|
| 74 |
+
the indices in the first (resp. second) set of descriptors.
|
| 75 |
+
ax : matplotlib.axes.Axes
|
| 76 |
+
The Axes object where the images and their matched features are drawn.
|
| 77 |
+
keypoints_color : matplotlib color, optional
|
| 78 |
+
Color for keypoint locations.
|
| 79 |
+
matches_color : matplotlib color or sequence thereof, optional
|
| 80 |
+
Single color or sequence of colors for each line defined by `matches`,
|
| 81 |
+
which connect keypoint matches. See [1]_ for an overview of supported
|
| 82 |
+
color formats. By default, colors are picked randomly.
|
| 83 |
+
only_matches : bool, optional
|
| 84 |
+
Set to True to plot matches only and not the keypoint locations.
|
| 85 |
+
alignment : {'horizontal', 'vertical'}, optional
|
| 86 |
+
Whether to show the two images side by side (`'horizontal'`), or one above
|
| 87 |
+
the other (`'vertical'`).
|
| 88 |
+
|
| 89 |
+
References
|
| 90 |
+
----------
|
| 91 |
+
.. [1] https://matplotlib.org/stable/users/explain/colors/colors.html#specifying-colors
|
| 92 |
+
|
| 93 |
+
Notes
|
| 94 |
+
-----
|
| 95 |
+
To make a sequence of colors passed to `matches_color` work for any number of
|
| 96 |
+
`matches`, you can wrap that sequence in :func:`itertools.cycle`.
|
| 97 |
+
"""
|
| 98 |
+
image0 = img_as_float(image0)
|
| 99 |
+
image1 = img_as_float(image1)
|
| 100 |
+
|
| 101 |
+
new_shape0 = list(image0.shape)
|
| 102 |
+
new_shape1 = list(image1.shape)
|
| 103 |
+
|
| 104 |
+
if image0.shape[0] < image1.shape[0]:
|
| 105 |
+
new_shape0[0] = image1.shape[0]
|
| 106 |
+
elif image0.shape[0] > image1.shape[0]:
|
| 107 |
+
new_shape1[0] = image0.shape[0]
|
| 108 |
+
|
| 109 |
+
if image0.shape[1] < image1.shape[1]:
|
| 110 |
+
new_shape0[1] = image1.shape[1]
|
| 111 |
+
elif image0.shape[1] > image1.shape[1]:
|
| 112 |
+
new_shape1[1] = image0.shape[1]
|
| 113 |
+
|
| 114 |
+
if new_shape0 != image0.shape:
|
| 115 |
+
new_image0 = np.zeros(new_shape0, dtype=image0.dtype)
|
| 116 |
+
new_image0[: image0.shape[0], : image0.shape[1]] = image0
|
| 117 |
+
image0 = new_image0
|
| 118 |
+
|
| 119 |
+
if new_shape1 != image1.shape:
|
| 120 |
+
new_image1 = np.zeros(new_shape1, dtype=image1.dtype)
|
| 121 |
+
new_image1[: image1.shape[0], : image1.shape[1]] = image1
|
| 122 |
+
image1 = new_image1
|
| 123 |
+
|
| 124 |
+
offset = np.array(image0.shape)
|
| 125 |
+
if alignment == 'horizontal':
|
| 126 |
+
image = np.concatenate([image0, image1], axis=1)
|
| 127 |
+
offset[0] = 0
|
| 128 |
+
elif alignment == 'vertical':
|
| 129 |
+
image = np.concatenate([image0, image1], axis=0)
|
| 130 |
+
offset[1] = 0
|
| 131 |
+
else:
|
| 132 |
+
mesg = (
|
| 133 |
+
f"`plot_matched_features` accepts either 'horizontal' or 'vertical' for "
|
| 134 |
+
f"alignment, but '{alignment}' was given. See "
|
| 135 |
+
f"https://scikit-image.org/docs/dev/api/skimage.feature.html#skimage.feature.plot_matched_features "
|
| 136 |
+
f"for details."
|
| 137 |
+
)
|
| 138 |
+
raise ValueError(mesg)
|
| 139 |
+
|
| 140 |
+
if not only_matches:
|
| 141 |
+
ax.scatter(
|
| 142 |
+
keypoints0[:, 1],
|
| 143 |
+
keypoints0[:, 0],
|
| 144 |
+
facecolors='none',
|
| 145 |
+
edgecolors=keypoints_color,
|
| 146 |
+
)
|
| 147 |
+
ax.scatter(
|
| 148 |
+
keypoints1[:, 1] + offset[1],
|
| 149 |
+
keypoints1[:, 0] + offset[0],
|
| 150 |
+
facecolors='none',
|
| 151 |
+
edgecolors=keypoints_color,
|
| 152 |
+
)
|
| 153 |
+
|
| 154 |
+
ax.imshow(image, cmap='gray')
|
| 155 |
+
ax.axis((0, image0.shape[1] + offset[1], image0.shape[0] + offset[0], 0))
|
| 156 |
+
|
| 157 |
+
number_of_matches = matches.shape[0]
|
| 158 |
+
|
| 159 |
+
from matplotlib.colors import is_color_like
|
| 160 |
+
|
| 161 |
+
if matches_color is None:
|
| 162 |
+
rng = np.random.default_rng(seed=0)
|
| 163 |
+
colors = [rng.random(3) for _ in range(number_of_matches)]
|
| 164 |
+
elif is_color_like(matches_color):
|
| 165 |
+
colors = [matches_color for _ in range(number_of_matches)]
|
| 166 |
+
elif hasattr(matches_color, "__len__") and len(matches_color) == number_of_matches:
|
| 167 |
+
# No need to check each color, matplotlib does so for us
|
| 168 |
+
colors = matches_color
|
| 169 |
+
else:
|
| 170 |
+
error_message = (
|
| 171 |
+
'`matches_color` needs to be a single color '
|
| 172 |
+
'or a sequence of length equal to the number of matches.'
|
| 173 |
+
)
|
| 174 |
+
raise ValueError(error_message)
|
| 175 |
+
|
| 176 |
+
for i, match in enumerate(matches):
|
| 177 |
+
idx0, idx1 = match
|
| 178 |
+
ax.plot(
|
| 179 |
+
(keypoints0[idx0, 1], keypoints1[idx1, 1] + offset[1]),
|
| 180 |
+
(keypoints0[idx0, 0], keypoints1[idx1, 0] + offset[0]),
|
| 181 |
+
'-',
|
| 182 |
+
color=colors[i],
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
|
| 186 |
+
def _prepare_grayscale_input_2D(image):
|
| 187 |
+
image = np.squeeze(image)
|
| 188 |
+
check_nD(image, 2)
|
| 189 |
+
image = img_as_float(image)
|
| 190 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 191 |
+
return image.astype(float_dtype, copy=False)
|
| 192 |
+
|
| 193 |
+
|
| 194 |
+
def _prepare_grayscale_input_nD(image):
|
| 195 |
+
image = np.squeeze(image)
|
| 196 |
+
check_nD(image, range(2, 6))
|
| 197 |
+
image = img_as_float(image)
|
| 198 |
+
float_dtype = _supported_float_type(image.dtype)
|
| 199 |
+
return image.astype(float_dtype, copy=False)
|
| 200 |
+
|
| 201 |
+
|
| 202 |
+
def _mask_border_keypoints(image_shape, keypoints, distance):
|
| 203 |
+
"""Mask coordinates that are within certain distance from the image border.
|
| 204 |
+
|
| 205 |
+
Parameters
|
| 206 |
+
----------
|
| 207 |
+
image_shape : (2,) array_like
|
| 208 |
+
Shape of the image as ``(rows, cols)``.
|
| 209 |
+
keypoints : (N, 2) array
|
| 210 |
+
Keypoint coordinates as ``(rows, cols)``.
|
| 211 |
+
distance : int
|
| 212 |
+
Image border distance.
|
| 213 |
+
|
| 214 |
+
Returns
|
| 215 |
+
-------
|
| 216 |
+
mask : (N,) bool array
|
| 217 |
+
Mask indicating if pixels are within the image (``True``) or in the
|
| 218 |
+
border region of the image (``False``).
|
| 219 |
+
|
| 220 |
+
"""
|
| 221 |
+
|
| 222 |
+
rows = image_shape[0]
|
| 223 |
+
cols = image_shape[1]
|
| 224 |
+
|
| 225 |
+
mask = (
|
| 226 |
+
((distance - 1) < keypoints[:, 0])
|
| 227 |
+
& (keypoints[:, 0] < (rows - distance + 1))
|
| 228 |
+
& ((distance - 1) < keypoints[:, 1])
|
| 229 |
+
& (keypoints[:, 1] < (cols - distance + 1))
|
| 230 |
+
)
|
| 231 |
+
|
| 232 |
+
return mask
|
envs/kitoverlay/skimage/metrics/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Metrics corresponding to images, e.g., distance metrics, similarity, etc."""
|
| 2 |
+
|
| 3 |
+
import lazy_loader as _lazy
|
| 4 |
+
|
| 5 |
+
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|
envs/kitoverlay/skimage/metrics/__init__.pyi
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Explicitly setting `__all__` is necessary for type inference engines
|
| 2 |
+
# to know which symbols are exported. See
|
| 3 |
+
# https://peps.python.org/pep-0484/#stub-files
|
| 4 |
+
|
| 5 |
+
__all__ = [
|
| 6 |
+
"adapted_rand_error",
|
| 7 |
+
"variation_of_information",
|
| 8 |
+
"contingency_table",
|
| 9 |
+
"mean_squared_error",
|
| 10 |
+
"normalized_mutual_information",
|
| 11 |
+
"normalized_root_mse",
|
| 12 |
+
"peak_signal_noise_ratio",
|
| 13 |
+
"structural_similarity",
|
| 14 |
+
"hausdorff_distance",
|
| 15 |
+
"hausdorff_pair",
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
from ._adapted_rand_error import adapted_rand_error
|
| 19 |
+
from ._contingency_table import contingency_table
|
| 20 |
+
from ._structural_similarity import structural_similarity
|
| 21 |
+
from ._variation_of_information import variation_of_information
|
| 22 |
+
from .set_metrics import hausdorff_distance, hausdorff_pair
|
| 23 |
+
from .simple_metrics import (
|
| 24 |
+
mean_squared_error,
|
| 25 |
+
normalized_mutual_information,
|
| 26 |
+
normalized_root_mse,
|
| 27 |
+
peak_signal_noise_ratio,
|
| 28 |
+
)
|
envs/kitoverlay/skimage/metrics/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (435 Bytes). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/_adapted_rand_error.cpython-311.pyc
ADDED
|
Binary file (4.01 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/_contingency_table.cpython-311.pyc
ADDED
|
Binary file (2.32 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/_structural_similarity.cpython-311.pyc
ADDED
|
Binary file (11 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/_variation_of_information.cpython-311.pyc
ADDED
|
Binary file (5.65 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/set_metrics.cpython-311.pyc
ADDED
|
Binary file (5.95 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/__pycache__/simple_metrics.cpython-311.pyc
ADDED
|
Binary file (10.7 kB). View file
|
|
|
envs/kitoverlay/skimage/metrics/_adapted_rand_error.py
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .._shared.utils import check_shape_equality
|
| 2 |
+
from ._contingency_table import contingency_table
|
| 3 |
+
|
| 4 |
+
__all__ = ['adapted_rand_error']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def adapted_rand_error(
|
| 8 |
+
image_true=None, image_test=None, *, table=None, ignore_labels=(0,), alpha=0.5
|
| 9 |
+
):
|
| 10 |
+
r"""Compute Adapted Rand error as defined by the SNEMI3D contest. [1]_
|
| 11 |
+
|
| 12 |
+
Parameters
|
| 13 |
+
----------
|
| 14 |
+
image_true : ndarray of int
|
| 15 |
+
Ground-truth label image, same shape as im_test.
|
| 16 |
+
image_test : ndarray of int
|
| 17 |
+
Test image.
|
| 18 |
+
table : scipy.sparse array in crs format, optional
|
| 19 |
+
A contingency table built with skimage.evaluate.contingency_table.
|
| 20 |
+
If None, it will be computed on the fly.
|
| 21 |
+
ignore_labels : sequence of int, optional
|
| 22 |
+
Labels to ignore. Any part of the true image labeled with any of these
|
| 23 |
+
values will not be counted in the score.
|
| 24 |
+
alpha : float, optional
|
| 25 |
+
Relative weight given to precision and recall in the adapted Rand error
|
| 26 |
+
calculation.
|
| 27 |
+
|
| 28 |
+
Returns
|
| 29 |
+
-------
|
| 30 |
+
are : float
|
| 31 |
+
The adapted Rand error.
|
| 32 |
+
prec : float
|
| 33 |
+
The adapted Rand precision: this is the number of pairs of pixels that
|
| 34 |
+
have the same label in the test label image *and* in the true image,
|
| 35 |
+
divided by the number in the test image.
|
| 36 |
+
rec : float
|
| 37 |
+
The adapted Rand recall: this is the number of pairs of pixels that
|
| 38 |
+
have the same label in the test label image *and* in the true image,
|
| 39 |
+
divided by the number in the true image.
|
| 40 |
+
|
| 41 |
+
Notes
|
| 42 |
+
-----
|
| 43 |
+
Pixels with label 0 in the true segmentation are ignored in the score.
|
| 44 |
+
|
| 45 |
+
The adapted Rand error is calculated as follows:
|
| 46 |
+
|
| 47 |
+
:math:`1 - \frac{\sum_{ij} p_{ij}^{2}}{\alpha \sum_{k} s_{k}^{2} +
|
| 48 |
+
(1-\alpha)\sum_{k} t_{k}^{2}}`,
|
| 49 |
+
where :math:`p_{ij}` is the probability that a pixel has the same label
|
| 50 |
+
in the test image *and* in the true image, :math:`t_{k}` is the
|
| 51 |
+
probability that a pixel has label :math:`k` in the true image,
|
| 52 |
+
and :math:`s_{k}` is the probability that a pixel has label :math:`k`
|
| 53 |
+
in the test image.
|
| 54 |
+
|
| 55 |
+
Default behavior is to weight precision and recall equally in the
|
| 56 |
+
adapted Rand error calculation.
|
| 57 |
+
When alpha = 0, adapted Rand error = recall.
|
| 58 |
+
When alpha = 1, adapted Rand error = precision.
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
References
|
| 62 |
+
----------
|
| 63 |
+
.. [1] Arganda-Carreras I, Turaga SC, Berger DR, et al. (2015)
|
| 64 |
+
Crowdsourcing the creation of image segmentation algorithms
|
| 65 |
+
for connectomics. Front. Neuroanat. 9:142.
|
| 66 |
+
:DOI:`10.3389/fnana.2015.00142`
|
| 67 |
+
"""
|
| 68 |
+
if image_test is not None and image_true is not None:
|
| 69 |
+
check_shape_equality(image_true, image_test)
|
| 70 |
+
|
| 71 |
+
if table is None:
|
| 72 |
+
p_ij = contingency_table(
|
| 73 |
+
image_true,
|
| 74 |
+
image_test,
|
| 75 |
+
ignore_labels=ignore_labels,
|
| 76 |
+
normalize=False,
|
| 77 |
+
sparse_type="array",
|
| 78 |
+
)
|
| 79 |
+
else:
|
| 80 |
+
p_ij = table
|
| 81 |
+
|
| 82 |
+
if alpha < 0.0 or alpha > 1.0:
|
| 83 |
+
raise ValueError('alpha must be between 0 and 1')
|
| 84 |
+
|
| 85 |
+
# Sum of the joint distribution squared
|
| 86 |
+
sum_p_ij2 = p_ij.data @ p_ij.data - p_ij.sum()
|
| 87 |
+
|
| 88 |
+
a_i = p_ij.sum(axis=1).ravel()
|
| 89 |
+
b_i = p_ij.sum(axis=0).ravel()
|
| 90 |
+
|
| 91 |
+
# Sum of squares of the test segment sizes (this is 2x the number of pairs
|
| 92 |
+
# of pixels with the same label in im_test)
|
| 93 |
+
sum_a2 = a_i @ a_i - a_i.sum()
|
| 94 |
+
# Same for im_true
|
| 95 |
+
sum_b2 = b_i @ b_i - b_i.sum()
|
| 96 |
+
|
| 97 |
+
precision = sum_p_ij2 / sum_a2
|
| 98 |
+
recall = sum_p_ij2 / sum_b2
|
| 99 |
+
|
| 100 |
+
fscore = sum_p_ij2 / (alpha * sum_a2 + (1 - alpha) * sum_b2)
|
| 101 |
+
are = 1.0 - fscore
|
| 102 |
+
|
| 103 |
+
return are, precision, recall
|
envs/kitoverlay/skimage/metrics/_contingency_table.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import scipy.sparse as sparse
|
| 2 |
+
import numpy as np
|
| 3 |
+
|
| 4 |
+
__all__ = ['contingency_table']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def contingency_table(
|
| 8 |
+
im_true, im_test, *, ignore_labels=None, normalize=False, sparse_type="matrix"
|
| 9 |
+
):
|
| 10 |
+
"""
|
| 11 |
+
Return the contingency table for all regions in matched segmentations.
|
| 12 |
+
|
| 13 |
+
Parameters
|
| 14 |
+
----------
|
| 15 |
+
im_true : ndarray of int
|
| 16 |
+
Ground-truth label image, same shape as im_test.
|
| 17 |
+
im_test : ndarray of int
|
| 18 |
+
Test image.
|
| 19 |
+
ignore_labels : sequence of int, optional
|
| 20 |
+
Labels to ignore. Any part of the true image labeled with any of these
|
| 21 |
+
values will not be counted in the score.
|
| 22 |
+
normalize : bool
|
| 23 |
+
Determines if the contingency table is normalized by pixel count.
|
| 24 |
+
sparse_type : {"matrix", "array"}, optional
|
| 25 |
+
The return type of `cont`, either `scipy.sparse.csr_array` or
|
| 26 |
+
`scipy.sparse.csr_matrix` (default).
|
| 27 |
+
|
| 28 |
+
Returns
|
| 29 |
+
-------
|
| 30 |
+
cont : scipy.sparse.csr_matrix or scipy.sparse.csr_array
|
| 31 |
+
A contingency table. `cont[i, j]` will equal the number of voxels
|
| 32 |
+
labeled `i` in `im_true` and `j` in `im_test`. Depending on `sparse_type`,
|
| 33 |
+
this can be returned as a `scipy.sparse.csr_array`.
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
if ignore_labels is None:
|
| 37 |
+
ignore_labels = []
|
| 38 |
+
im_test_r = im_test.reshape(-1)
|
| 39 |
+
im_true_r = im_true.reshape(-1)
|
| 40 |
+
data = np.isin(im_true_r, ignore_labels, invert=True).astype(float)
|
| 41 |
+
if normalize:
|
| 42 |
+
data /= np.count_nonzero(data)
|
| 43 |
+
cont = sparse.csr_array((data, (im_true_r, im_test_r)))
|
| 44 |
+
|
| 45 |
+
if sparse_type == "matrix":
|
| 46 |
+
cont = sparse.csr_matrix(cont)
|
| 47 |
+
elif sparse_type != "array":
|
| 48 |
+
msg = f"`sparse_type` must be 'array' or 'matrix', got {sparse_type}"
|
| 49 |
+
raise ValueError(msg)
|
| 50 |
+
|
| 51 |
+
return cont
|