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/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/__pycache__/conftest.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/_vendored/__init__.py +0 -0
- envs/kitoverlay/skimage/_vendored/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/_vendored/__pycache__/numpy_lookfor.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/_vendored/numpy_lookfor.py +298 -0
- envs/kitoverlay/skimage/draw/__init__.py +5 -0
- envs/kitoverlay/skimage/draw/__init__.pyi +45 -0
- envs/kitoverlay/skimage/draw/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/__pycache__/_polygon2mask.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/__pycache__/_random_shapes.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/__pycache__/draw.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/__pycache__/draw3d.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/__pycache__/draw_nd.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/draw/_polygon2mask.py +74 -0
- envs/kitoverlay/skimage/draw/_random_shapes.py +459 -0
- envs/kitoverlay/skimage/draw/draw.py +970 -0
- envs/kitoverlay/skimage/draw/draw3d.py +107 -0
- envs/kitoverlay/skimage/draw/draw_nd.py +108 -0
- envs/kitoverlay/skimage/feature/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/_basic_features.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/_canny.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/_fisher_vector.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/_orb_descriptor_positions.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/blob.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/corner.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/haar.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/match.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/sift.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/texture.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/feature/__pycache__/util.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__init__.py +43 -0
- envs/kitoverlay/skimage/io/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/_image_stack.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/_io.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/collection.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/manage_plugins.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/sift.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/__pycache__/util.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_image_stack.py +35 -0
- envs/kitoverlay/skimage/io/_io.py +286 -0
- envs/kitoverlay/skimage/io/_plugins/__init__.py +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/__init__.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/fits_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/gdal_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/imageio_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/imread_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/matplotlib_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/pil_plugin.cpython-311.pyc +0 -0
- envs/kitoverlay/skimage/io/_plugins/__pycache__/simpleitk_plugin.cpython-311.pyc +0 -0
envs/kitoverlay/skimage/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (4.85 kB). View file
|
|
|
envs/kitoverlay/skimage/__pycache__/conftest.cpython-311.pyc
ADDED
|
Binary file (751 Bytes). View file
|
|
|
envs/kitoverlay/skimage/_vendored/__init__.py
ADDED
|
File without changes
|
envs/kitoverlay/skimage/_vendored/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (174 Bytes). View file
|
|
|
envs/kitoverlay/skimage/_vendored/__pycache__/numpy_lookfor.cpython-311.pyc
ADDED
|
Binary file (12.5 kB). View file
|
|
|
envs/kitoverlay/skimage/_vendored/numpy_lookfor.py
ADDED
|
@@ -0,0 +1,298 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Vendored subset of numpy/lib/utils.py in 1.26.3
|
| 2 |
+
# https://github.com/numpy/numpy/blob/b4bf93b936802618ebb49ee43e382b576b29a0a6/numpy/lib/utils.py
|
| 3 |
+
#
|
| 4 |
+
# Can be removed after deprecation of `skimage.lookfor` is completed.
|
| 5 |
+
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
import re
|
| 9 |
+
|
| 10 |
+
from numpy import ufunc
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
# Cache for lookfor: {id(module): {name: (docstring, kind, index), ...}...}
|
| 14 |
+
# where kind: "func", "class", "module", "object"
|
| 15 |
+
# and index: index in breadth-first namespace traversal
|
| 16 |
+
_lookfor_caches = {}
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
# regexp whose match indicates that the string may contain a function
|
| 20 |
+
# signature
|
| 21 |
+
_function_signature_re = re.compile(r"[a-z0-9_]+\(.*[,=].*\)", re.I)
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _getmembers(item):
|
| 25 |
+
import inspect
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
members = inspect.getmembers(item)
|
| 29 |
+
except Exception:
|
| 30 |
+
members = [(x, getattr(item, x)) for x in dir(item) if hasattr(item, x)]
|
| 31 |
+
return members
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def _lookfor_generate_cache(module, import_modules, regenerate):
|
| 35 |
+
"""
|
| 36 |
+
Generate docstring cache for given module.
|
| 37 |
+
|
| 38 |
+
Parameters
|
| 39 |
+
----------
|
| 40 |
+
module : str, None, module
|
| 41 |
+
Module for which to generate docstring cache
|
| 42 |
+
import_modules : bool
|
| 43 |
+
Whether to import sub-modules in packages.
|
| 44 |
+
regenerate : bool
|
| 45 |
+
Re-generate the docstring cache
|
| 46 |
+
|
| 47 |
+
Returns
|
| 48 |
+
-------
|
| 49 |
+
cache : dict {obj_full_name: (docstring, kind, index), ...}
|
| 50 |
+
Docstring cache for the module, either cached one (regenerate=False)
|
| 51 |
+
or newly generated.
|
| 52 |
+
|
| 53 |
+
"""
|
| 54 |
+
# Local import to speed up numpy's import time.
|
| 55 |
+
import inspect
|
| 56 |
+
|
| 57 |
+
from io import StringIO
|
| 58 |
+
|
| 59 |
+
if module is None:
|
| 60 |
+
module = "skimage"
|
| 61 |
+
|
| 62 |
+
if isinstance(module, str):
|
| 63 |
+
try:
|
| 64 |
+
__import__(module)
|
| 65 |
+
except ImportError:
|
| 66 |
+
return {}
|
| 67 |
+
module = sys.modules[module]
|
| 68 |
+
elif isinstance(module, list) or isinstance(module, tuple):
|
| 69 |
+
cache = {}
|
| 70 |
+
for mod in module:
|
| 71 |
+
cache.update(_lookfor_generate_cache(mod, import_modules, regenerate))
|
| 72 |
+
return cache
|
| 73 |
+
|
| 74 |
+
if id(module) in _lookfor_caches and not regenerate:
|
| 75 |
+
return _lookfor_caches[id(module)]
|
| 76 |
+
|
| 77 |
+
# walk items and collect docstrings
|
| 78 |
+
cache = {}
|
| 79 |
+
_lookfor_caches[id(module)] = cache
|
| 80 |
+
seen = {}
|
| 81 |
+
index = 0
|
| 82 |
+
stack = [(module.__name__, module)]
|
| 83 |
+
while stack:
|
| 84 |
+
name, item = stack.pop(0)
|
| 85 |
+
if id(item) in seen:
|
| 86 |
+
continue
|
| 87 |
+
seen[id(item)] = True
|
| 88 |
+
|
| 89 |
+
index += 1
|
| 90 |
+
kind = "object"
|
| 91 |
+
|
| 92 |
+
if inspect.ismodule(item):
|
| 93 |
+
kind = "module"
|
| 94 |
+
try:
|
| 95 |
+
_all = item.__all__
|
| 96 |
+
except AttributeError:
|
| 97 |
+
_all = None
|
| 98 |
+
|
| 99 |
+
# import sub-packages
|
| 100 |
+
if import_modules and hasattr(item, '__path__'):
|
| 101 |
+
for pth in item.__path__:
|
| 102 |
+
if os.path.isfile(pth) or not os.path.exists(pth):
|
| 103 |
+
continue
|
| 104 |
+
for mod_path in os.listdir(pth):
|
| 105 |
+
this_py = os.path.join(pth, mod_path)
|
| 106 |
+
init_py = os.path.join(pth, mod_path, '__init__.py')
|
| 107 |
+
if os.path.isfile(this_py) and mod_path.endswith('.py'):
|
| 108 |
+
to_import = mod_path[:-3]
|
| 109 |
+
elif os.path.isfile(init_py):
|
| 110 |
+
to_import = mod_path
|
| 111 |
+
else:
|
| 112 |
+
continue
|
| 113 |
+
if to_import == '__init__':
|
| 114 |
+
continue
|
| 115 |
+
|
| 116 |
+
try:
|
| 117 |
+
old_stdout = sys.stdout
|
| 118 |
+
old_stderr = sys.stderr
|
| 119 |
+
try:
|
| 120 |
+
sys.stdout = StringIO()
|
| 121 |
+
sys.stderr = StringIO()
|
| 122 |
+
__import__(f"{name}.{to_import}")
|
| 123 |
+
finally:
|
| 124 |
+
sys.stdout = old_stdout
|
| 125 |
+
sys.stderr = old_stderr
|
| 126 |
+
except KeyboardInterrupt:
|
| 127 |
+
# Assume keyboard interrupt came from a user
|
| 128 |
+
raise
|
| 129 |
+
except BaseException:
|
| 130 |
+
# Ignore also SystemExit and pytests.importorskip
|
| 131 |
+
# `Skipped` (these are BaseExceptions; gh-22345)
|
| 132 |
+
continue
|
| 133 |
+
|
| 134 |
+
for n, v in _getmembers(item):
|
| 135 |
+
try:
|
| 136 |
+
item_name = getattr(
|
| 137 |
+
v,
|
| 138 |
+
'__name__',
|
| 139 |
+
f"{name}.{n}",
|
| 140 |
+
)
|
| 141 |
+
mod_name = getattr(v, '__module__', None)
|
| 142 |
+
except NameError:
|
| 143 |
+
# ref. SWIG's global cvars
|
| 144 |
+
# NameError: Unknown C global variable
|
| 145 |
+
item_name = f"{name}.{n}"
|
| 146 |
+
mod_name = None
|
| 147 |
+
if '.' not in item_name and mod_name:
|
| 148 |
+
item_name = f"{mod_name}.{item_name}"
|
| 149 |
+
|
| 150 |
+
if not item_name.startswith(name + '.'):
|
| 151 |
+
# don't crawl "foreign" objects
|
| 152 |
+
if isinstance(v, ufunc):
|
| 153 |
+
# ... unless they are ufuncs
|
| 154 |
+
pass
|
| 155 |
+
else:
|
| 156 |
+
continue
|
| 157 |
+
elif not (inspect.ismodule(v) or _all is None or n in _all):
|
| 158 |
+
continue
|
| 159 |
+
|
| 160 |
+
stack.append((f"{name}.{n}", v))
|
| 161 |
+
elif inspect.isclass(item):
|
| 162 |
+
kind = "class"
|
| 163 |
+
for n, v in _getmembers(item):
|
| 164 |
+
stack.append((f"{name}.{n}", v))
|
| 165 |
+
elif hasattr(item, "__call__"):
|
| 166 |
+
kind = "func"
|
| 167 |
+
|
| 168 |
+
try:
|
| 169 |
+
doc = inspect.getdoc(item)
|
| 170 |
+
except NameError:
|
| 171 |
+
# ref SWIG's NameError: Unknown C global variable
|
| 172 |
+
doc = None
|
| 173 |
+
if doc is not None:
|
| 174 |
+
cache[name] = (doc, kind, index)
|
| 175 |
+
|
| 176 |
+
return cache
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def lookfor(what, module=None, import_modules=True, regenerate=False, output=None):
|
| 180 |
+
"""
|
| 181 |
+
Do a keyword search on docstrings.
|
| 182 |
+
|
| 183 |
+
A list of objects that matched the search is displayed,
|
| 184 |
+
sorted by relevance. All given keywords need to be found in the
|
| 185 |
+
docstring for it to be returned as a result, but the order does
|
| 186 |
+
not matter.
|
| 187 |
+
|
| 188 |
+
Parameters
|
| 189 |
+
----------
|
| 190 |
+
what : str
|
| 191 |
+
String containing words to look for.
|
| 192 |
+
module : str or list, optional
|
| 193 |
+
Name of module(s) whose docstrings to go through.
|
| 194 |
+
import_modules : bool, optional
|
| 195 |
+
Whether to import sub-modules in packages. Default is True.
|
| 196 |
+
regenerate : bool, optional
|
| 197 |
+
Whether to re-generate the docstring cache. Default is False.
|
| 198 |
+
output : file-like, optional
|
| 199 |
+
File-like object to write the output to. If omitted, use a pager.
|
| 200 |
+
|
| 201 |
+
See Also
|
| 202 |
+
--------
|
| 203 |
+
source, info
|
| 204 |
+
|
| 205 |
+
Notes
|
| 206 |
+
-----
|
| 207 |
+
Relevance is determined only roughly, by checking if the keywords occur
|
| 208 |
+
in the function name, at the start of a docstring, etc.
|
| 209 |
+
|
| 210 |
+
Examples
|
| 211 |
+
--------
|
| 212 |
+
>>> np.lookfor('binary representation') # doctest: +SKIP
|
| 213 |
+
Search results for 'binary representation'
|
| 214 |
+
------------------------------------------
|
| 215 |
+
numpy.binary_repr
|
| 216 |
+
Return the binary representation of the input number as a string.
|
| 217 |
+
numpy.core.setup_common.long_double_representation
|
| 218 |
+
Given a binary dump as given by GNU od -b, look for long double
|
| 219 |
+
numpy.base_repr
|
| 220 |
+
Return a string representation of a number in the given base system.
|
| 221 |
+
...
|
| 222 |
+
|
| 223 |
+
"""
|
| 224 |
+
import pydoc
|
| 225 |
+
|
| 226 |
+
# Cache
|
| 227 |
+
cache = _lookfor_generate_cache(module, import_modules, regenerate)
|
| 228 |
+
|
| 229 |
+
# Search
|
| 230 |
+
# XXX: maybe using a real stemming search engine would be better?
|
| 231 |
+
found = []
|
| 232 |
+
whats = str(what).lower().split()
|
| 233 |
+
if not whats:
|
| 234 |
+
return
|
| 235 |
+
|
| 236 |
+
for name, (docstring, kind, index) in cache.items():
|
| 237 |
+
if kind in ('module', 'object'):
|
| 238 |
+
# don't show modules or objects
|
| 239 |
+
continue
|
| 240 |
+
doc = docstring.lower()
|
| 241 |
+
if all(w in doc for w in whats):
|
| 242 |
+
found.append(name)
|
| 243 |
+
|
| 244 |
+
# Relevance sort
|
| 245 |
+
# XXX: this is full Harrison-Stetson heuristics now,
|
| 246 |
+
# XXX: it probably could be improved
|
| 247 |
+
|
| 248 |
+
kind_relevance = {'func': 1000, 'class': 1000, 'module': -1000, 'object': -1000}
|
| 249 |
+
|
| 250 |
+
def relevance(name, docstr, kind, index):
|
| 251 |
+
r = 0
|
| 252 |
+
# do the keywords occur within the start of the docstring?
|
| 253 |
+
first_doc = "\n".join(docstr.lower().strip().split("\n")[:3])
|
| 254 |
+
r += sum([200 for w in whats if w in first_doc])
|
| 255 |
+
# do the keywords occur in the function name?
|
| 256 |
+
r += sum([30 for w in whats if w in name])
|
| 257 |
+
# is the full name long?
|
| 258 |
+
r += -len(name) * 5
|
| 259 |
+
# is the object of bad type?
|
| 260 |
+
r += kind_relevance.get(kind, -1000)
|
| 261 |
+
# is the object deep in namespace hierarchy?
|
| 262 |
+
r += -name.count('.') * 10
|
| 263 |
+
r += max(-index / 100, -100)
|
| 264 |
+
return r
|
| 265 |
+
|
| 266 |
+
def relevance_value(a):
|
| 267 |
+
return relevance(a, *cache[a])
|
| 268 |
+
|
| 269 |
+
found.sort(key=relevance_value)
|
| 270 |
+
|
| 271 |
+
# Pretty-print
|
| 272 |
+
s = f"Search results for '{' '.join(whats)}'"
|
| 273 |
+
help_text = [s, "-" * len(s)]
|
| 274 |
+
for name in found[::-1]:
|
| 275 |
+
doc, kind, ix = cache[name]
|
| 276 |
+
|
| 277 |
+
doclines = [line.strip() for line in doc.strip().split("\n") if line.strip()]
|
| 278 |
+
|
| 279 |
+
# find a suitable short description
|
| 280 |
+
try:
|
| 281 |
+
first_doc = doclines[0].strip()
|
| 282 |
+
if _function_signature_re.search(first_doc):
|
| 283 |
+
first_doc = doclines[1].strip()
|
| 284 |
+
except IndexError:
|
| 285 |
+
first_doc = ""
|
| 286 |
+
help_text.append(f"{name}\n {first_doc}")
|
| 287 |
+
|
| 288 |
+
if not found:
|
| 289 |
+
help_text.append("Nothing found.")
|
| 290 |
+
|
| 291 |
+
# Output
|
| 292 |
+
if output is not None:
|
| 293 |
+
output.write("\n".join(help_text))
|
| 294 |
+
elif len(help_text) > 10:
|
| 295 |
+
pager = pydoc.getpager()
|
| 296 |
+
pager("\n".join(help_text))
|
| 297 |
+
else:
|
| 298 |
+
print("\n".join(help_text))
|
envs/kitoverlay/skimage/draw/__init__.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Drawing primitives, such as lines, circles, text, etc."""
|
| 2 |
+
|
| 3 |
+
import lazy_loader as _lazy
|
| 4 |
+
|
| 5 |
+
__getattr__, __dir__, __all__ = _lazy.attach_stub(__name__, __file__)
|
envs/kitoverlay/skimage/draw/__init__.pyi
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
'line',
|
| 7 |
+
'line_aa',
|
| 8 |
+
'line_nd',
|
| 9 |
+
'bezier_curve',
|
| 10 |
+
'polygon',
|
| 11 |
+
'polygon_perimeter',
|
| 12 |
+
'ellipse',
|
| 13 |
+
'ellipse_perimeter',
|
| 14 |
+
'ellipsoid',
|
| 15 |
+
'ellipsoid_stats',
|
| 16 |
+
'circle_perimeter',
|
| 17 |
+
'circle_perimeter_aa',
|
| 18 |
+
'disk',
|
| 19 |
+
'set_color',
|
| 20 |
+
'random_shapes',
|
| 21 |
+
'rectangle',
|
| 22 |
+
'rectangle_perimeter',
|
| 23 |
+
'polygon2mask',
|
| 24 |
+
]
|
| 25 |
+
|
| 26 |
+
from .draw3d import ellipsoid, ellipsoid_stats
|
| 27 |
+
from ._draw import _bezier_segment
|
| 28 |
+
from ._random_shapes import random_shapes
|
| 29 |
+
from ._polygon2mask import polygon2mask
|
| 30 |
+
from .draw_nd import line_nd
|
| 31 |
+
from .draw import (
|
| 32 |
+
ellipse,
|
| 33 |
+
set_color,
|
| 34 |
+
polygon_perimeter,
|
| 35 |
+
line,
|
| 36 |
+
line_aa,
|
| 37 |
+
polygon,
|
| 38 |
+
ellipse_perimeter,
|
| 39 |
+
circle_perimeter,
|
| 40 |
+
circle_perimeter_aa,
|
| 41 |
+
disk,
|
| 42 |
+
bezier_curve,
|
| 43 |
+
rectangle,
|
| 44 |
+
rectangle_perimeter,
|
| 45 |
+
)
|
envs/kitoverlay/skimage/draw/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (413 Bytes). View file
|
|
|
envs/kitoverlay/skimage/draw/__pycache__/_polygon2mask.cpython-311.pyc
ADDED
|
Binary file (2.88 kB). View file
|
|
|
envs/kitoverlay/skimage/draw/__pycache__/_random_shapes.cpython-311.pyc
ADDED
|
Binary file (18.4 kB). View file
|
|
|
envs/kitoverlay/skimage/draw/__pycache__/draw.cpython-311.pyc
ADDED
|
Binary file (38.1 kB). View file
|
|
|
envs/kitoverlay/skimage/draw/__pycache__/draw3d.cpython-311.pyc
ADDED
|
Binary file (4.67 kB). View file
|
|
|
envs/kitoverlay/skimage/draw/__pycache__/draw_nd.cpython-311.pyc
ADDED
|
Binary file (4.72 kB). View file
|
|
|
envs/kitoverlay/skimage/draw/_polygon2mask.py
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from . import draw
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def polygon2mask(image_shape, polygon):
|
| 7 |
+
"""Create a binary mask from a polygon.
|
| 8 |
+
|
| 9 |
+
Parameters
|
| 10 |
+
----------
|
| 11 |
+
image_shape : tuple of size 2
|
| 12 |
+
The shape of the mask.
|
| 13 |
+
polygon : (N, 2) array_like
|
| 14 |
+
The polygon coordinates of shape (N, 2) where N is
|
| 15 |
+
the number of points. The coordinates are (row, column).
|
| 16 |
+
|
| 17 |
+
Returns
|
| 18 |
+
-------
|
| 19 |
+
mask : 2-D ndarray of type 'bool'
|
| 20 |
+
The binary mask that corresponds to the input polygon.
|
| 21 |
+
|
| 22 |
+
See Also
|
| 23 |
+
--------
|
| 24 |
+
polygon:
|
| 25 |
+
Generate coordinates of pixels inside a polygon.
|
| 26 |
+
|
| 27 |
+
Notes
|
| 28 |
+
-----
|
| 29 |
+
This function does not do any border checking. Parts of the polygon that
|
| 30 |
+
are outside the coordinate space defined by `image_shape` are not drawn.
|
| 31 |
+
|
| 32 |
+
Examples
|
| 33 |
+
--------
|
| 34 |
+
>>> import skimage as ski
|
| 35 |
+
>>> image_shape = (10, 10)
|
| 36 |
+
>>> polygon = np.array([[1, 1], [2, 7], [8, 4]])
|
| 37 |
+
>>> mask = ski.draw.polygon2mask(image_shape, polygon)
|
| 38 |
+
>>> mask.astype(int)
|
| 39 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 40 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 41 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 42 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 43 |
+
[0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
|
| 44 |
+
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
|
| 45 |
+
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
|
| 46 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 47 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 48 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 49 |
+
|
| 50 |
+
If vertices / points of the `polygon` are outside the coordinate space
|
| 51 |
+
defined by `image_shape`, only a part (or none at all) of the polygon is
|
| 52 |
+
drawn in the mask.
|
| 53 |
+
|
| 54 |
+
>>> offset = np.array([[2, -4]])
|
| 55 |
+
>>> ski.draw.polygon2mask(image_shape, polygon - offset).astype(int)
|
| 56 |
+
array([[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
|
| 57 |
+
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
|
| 58 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
|
| 59 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
|
| 60 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
|
| 61 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 62 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 63 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 64 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 65 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 66 |
+
"""
|
| 67 |
+
polygon = np.asarray(polygon)
|
| 68 |
+
vertex_row_coords, vertex_col_coords = polygon.T
|
| 69 |
+
fill_row_coords, fill_col_coords = draw.polygon(
|
| 70 |
+
vertex_row_coords, vertex_col_coords, image_shape
|
| 71 |
+
)
|
| 72 |
+
mask = np.zeros(image_shape, dtype=bool)
|
| 73 |
+
mask[fill_row_coords, fill_col_coords] = True
|
| 74 |
+
return mask
|
envs/kitoverlay/skimage/draw/_random_shapes.py
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
| 6 |
+
from .._shared.utils import warn
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def _generate_rectangle_mask(point, image, shape, random):
|
| 10 |
+
"""Generate a mask for a filled rectangle shape.
|
| 11 |
+
|
| 12 |
+
The height and width of the rectangle are generated randomly.
|
| 13 |
+
|
| 14 |
+
Parameters
|
| 15 |
+
----------
|
| 16 |
+
point : tuple
|
| 17 |
+
The row and column of the top left corner of the rectangle.
|
| 18 |
+
image : tuple
|
| 19 |
+
The height, width and depth of the image into which the shape
|
| 20 |
+
is placed.
|
| 21 |
+
shape : tuple
|
| 22 |
+
The minimum and maximum size of the shape to fit.
|
| 23 |
+
random : `numpy.random.Generator`
|
| 24 |
+
|
| 25 |
+
The random state to use for random sampling.
|
| 26 |
+
|
| 27 |
+
Raises
|
| 28 |
+
------
|
| 29 |
+
ArithmeticError
|
| 30 |
+
When a shape cannot be fit into the image with the given starting
|
| 31 |
+
coordinates. This usually means the image dimensions are too small or
|
| 32 |
+
shape dimensions too large.
|
| 33 |
+
|
| 34 |
+
Returns
|
| 35 |
+
-------
|
| 36 |
+
label : tuple
|
| 37 |
+
A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
|
| 38 |
+
bounding box coordinates of the shape.
|
| 39 |
+
indices : 2-D array
|
| 40 |
+
A mask of indices that the shape fills.
|
| 41 |
+
|
| 42 |
+
"""
|
| 43 |
+
available_width = min(image[1] - point[1], shape[1]) - shape[0]
|
| 44 |
+
available_height = min(image[0] - point[0], shape[1]) - shape[0]
|
| 45 |
+
|
| 46 |
+
# Pick random widths and heights.
|
| 47 |
+
r = shape[0] + random.integers(max(1, available_height)) - 1
|
| 48 |
+
c = shape[0] + random.integers(max(1, available_width)) - 1
|
| 49 |
+
rectangle = draw_polygon(
|
| 50 |
+
[
|
| 51 |
+
point[0],
|
| 52 |
+
point[0] + r,
|
| 53 |
+
point[0] + r,
|
| 54 |
+
point[0],
|
| 55 |
+
],
|
| 56 |
+
[
|
| 57 |
+
point[1],
|
| 58 |
+
point[1],
|
| 59 |
+
point[1] + c,
|
| 60 |
+
point[1] + c,
|
| 61 |
+
],
|
| 62 |
+
)
|
| 63 |
+
label = ('rectangle', ((point[0], point[0] + r + 1), (point[1], point[1] + c + 1)))
|
| 64 |
+
|
| 65 |
+
return rectangle, label
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
def _generate_circle_mask(point, image, shape, random):
|
| 69 |
+
"""Generate a mask for a filled circle shape.
|
| 70 |
+
|
| 71 |
+
The radius of the circle is generated randomly.
|
| 72 |
+
|
| 73 |
+
Parameters
|
| 74 |
+
----------
|
| 75 |
+
point : tuple
|
| 76 |
+
The row and column of the top left corner of the rectangle.
|
| 77 |
+
image : tuple
|
| 78 |
+
The height, width and depth of the image into which the shape is placed.
|
| 79 |
+
shape : tuple
|
| 80 |
+
The minimum and maximum size and color of the shape to fit.
|
| 81 |
+
random : `numpy.random.Generator`
|
| 82 |
+
The random state to use for random sampling.
|
| 83 |
+
|
| 84 |
+
Raises
|
| 85 |
+
------
|
| 86 |
+
ArithmeticError
|
| 87 |
+
When a shape cannot be fit into the image with the given starting
|
| 88 |
+
coordinates. This usually means the image dimensions are too small or
|
| 89 |
+
shape dimensions too large.
|
| 90 |
+
|
| 91 |
+
Returns
|
| 92 |
+
-------
|
| 93 |
+
label : tuple
|
| 94 |
+
A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
|
| 95 |
+
bounding box coordinates of the shape.
|
| 96 |
+
indices : 2-D array
|
| 97 |
+
A mask of indices that the shape fills.
|
| 98 |
+
"""
|
| 99 |
+
if shape[0] == 1 or shape[1] == 1:
|
| 100 |
+
raise ValueError('size must be > 1 for circles')
|
| 101 |
+
min_radius = shape[0] // 2.0
|
| 102 |
+
max_radius = shape[1] // 2.0
|
| 103 |
+
left = point[1]
|
| 104 |
+
right = image[1] - point[1]
|
| 105 |
+
top = point[0]
|
| 106 |
+
bottom = image[0] - point[0]
|
| 107 |
+
available_radius = min(left, right, top, bottom, max_radius) - min_radius
|
| 108 |
+
if available_radius < 0:
|
| 109 |
+
raise ArithmeticError('cannot fit shape to image')
|
| 110 |
+
radius = int(min_radius + random.integers(max(1, available_radius)))
|
| 111 |
+
# TODO: think about how to deprecate this
|
| 112 |
+
# while draw_circle was deprecated in favor of draw_disk
|
| 113 |
+
# switching to a label of 'disk' here
|
| 114 |
+
# would be a breaking change for downstream libraries
|
| 115 |
+
# See discussion on naming convention here
|
| 116 |
+
# https://github.com/scikit-image/scikit-image/pull/4428
|
| 117 |
+
disk = draw_disk((point[0], point[1]), radius)
|
| 118 |
+
# Until a deprecation path is decided, always return `'circle'`
|
| 119 |
+
label = (
|
| 120 |
+
'circle',
|
| 121 |
+
(
|
| 122 |
+
(point[0] - radius + 1, point[0] + radius),
|
| 123 |
+
(point[1] - radius + 1, point[1] + radius),
|
| 124 |
+
),
|
| 125 |
+
)
|
| 126 |
+
|
| 127 |
+
return disk, label
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
def _generate_triangle_mask(point, image, shape, random):
|
| 131 |
+
"""Generate a mask for a filled equilateral triangle shape.
|
| 132 |
+
|
| 133 |
+
The length of the sides of the triangle is generated randomly.
|
| 134 |
+
|
| 135 |
+
Parameters
|
| 136 |
+
----------
|
| 137 |
+
point : tuple
|
| 138 |
+
The row and column of the top left corner of a up-pointing triangle.
|
| 139 |
+
image : tuple
|
| 140 |
+
The height, width and depth of the image into which the shape
|
| 141 |
+
is placed.
|
| 142 |
+
shape : tuple
|
| 143 |
+
The minimum and maximum size and color of the shape to fit.
|
| 144 |
+
random : `numpy.random.Generator`
|
| 145 |
+
The random state to use for random sampling.
|
| 146 |
+
|
| 147 |
+
Raises
|
| 148 |
+
------
|
| 149 |
+
ArithmeticError
|
| 150 |
+
When a shape cannot be fit into the image with the given starting
|
| 151 |
+
coordinates. This usually means the image dimensions are too small or
|
| 152 |
+
shape dimensions too large.
|
| 153 |
+
|
| 154 |
+
Returns
|
| 155 |
+
-------
|
| 156 |
+
label : tuple
|
| 157 |
+
A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
|
| 158 |
+
bounding box coordinates of the shape.
|
| 159 |
+
indices : 2-D array
|
| 160 |
+
A mask of indices that the shape fills.
|
| 161 |
+
|
| 162 |
+
"""
|
| 163 |
+
if shape[0] == 1 or shape[1] == 1:
|
| 164 |
+
raise ValueError('dimension must be > 1 for triangles')
|
| 165 |
+
available_side = min(image[1] - point[1], point[0], shape[1]) - shape[0]
|
| 166 |
+
side = shape[0] + random.integers(max(1, available_side)) - 1
|
| 167 |
+
triangle_height = int(np.ceil(np.sqrt(3 / 4.0) * side))
|
| 168 |
+
triangle = draw_polygon(
|
| 169 |
+
[
|
| 170 |
+
point[0],
|
| 171 |
+
point[0] - triangle_height,
|
| 172 |
+
point[0],
|
| 173 |
+
],
|
| 174 |
+
[
|
| 175 |
+
point[1],
|
| 176 |
+
point[1] + side // 2,
|
| 177 |
+
point[1] + side,
|
| 178 |
+
],
|
| 179 |
+
)
|
| 180 |
+
label = (
|
| 181 |
+
'triangle',
|
| 182 |
+
((point[0] - triangle_height, point[0] + 1), (point[1], point[1] + side + 1)),
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
return triangle, label
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
def _generate_ellipse_mask(point, image, shape, random):
|
| 189 |
+
"""Generate a mask for a filled ellipse shape.
|
| 190 |
+
|
| 191 |
+
The rotation, major and minor semi-axes of the ellipse are generated
|
| 192 |
+
randomly.
|
| 193 |
+
|
| 194 |
+
Parameters
|
| 195 |
+
----------
|
| 196 |
+
point : tuple
|
| 197 |
+
The row and column of the top left corner of the rectangle.
|
| 198 |
+
image : tuple
|
| 199 |
+
The height, width and depth of the image into which the shape is
|
| 200 |
+
placed.
|
| 201 |
+
shape : tuple
|
| 202 |
+
The minimum and maximum size and color of the shape to fit.
|
| 203 |
+
random : `numpy.random.Generator`
|
| 204 |
+
The random state to use for random sampling.
|
| 205 |
+
|
| 206 |
+
Raises
|
| 207 |
+
------
|
| 208 |
+
ArithmeticError
|
| 209 |
+
When a shape cannot be fit into the image with the given starting
|
| 210 |
+
coordinates. This usually means the image dimensions are too small or
|
| 211 |
+
shape dimensions too large.
|
| 212 |
+
|
| 213 |
+
Returns
|
| 214 |
+
-------
|
| 215 |
+
label : tuple
|
| 216 |
+
A (category, ((r0, r1), (c0, c1))) tuple specifying the category and
|
| 217 |
+
bounding box coordinates of the shape.
|
| 218 |
+
indices : 2-D array
|
| 219 |
+
A mask of indices that the shape fills.
|
| 220 |
+
"""
|
| 221 |
+
if shape[0] == 1 or shape[1] == 1:
|
| 222 |
+
raise ValueError('size must be > 1 for ellipses')
|
| 223 |
+
min_radius = shape[0] / 2.0
|
| 224 |
+
max_radius = shape[1] / 2.0
|
| 225 |
+
left = point[1]
|
| 226 |
+
right = image[1] - point[1]
|
| 227 |
+
top = point[0]
|
| 228 |
+
bottom = image[0] - point[0]
|
| 229 |
+
available_radius = min(left, right, top, bottom, max_radius)
|
| 230 |
+
if available_radius < min_radius:
|
| 231 |
+
raise ArithmeticError('cannot fit shape to image')
|
| 232 |
+
# NOTE: very conservative because we could take into account the fact that
|
| 233 |
+
# we have 2 different radii, but this is a good first approximation.
|
| 234 |
+
# Also, we can afford to have a uniform sampling because the ellipse will
|
| 235 |
+
# be rotated.
|
| 236 |
+
r_radius = random.uniform(min_radius, available_radius + 1)
|
| 237 |
+
c_radius = random.uniform(min_radius, available_radius + 1)
|
| 238 |
+
rotation = random.uniform(-np.pi, np.pi)
|
| 239 |
+
ellipse = draw_ellipse(
|
| 240 |
+
point[0],
|
| 241 |
+
point[1],
|
| 242 |
+
r_radius,
|
| 243 |
+
c_radius,
|
| 244 |
+
shape=image[:2],
|
| 245 |
+
rotation=rotation,
|
| 246 |
+
)
|
| 247 |
+
max_radius = math.ceil(max(r_radius, c_radius))
|
| 248 |
+
min_x = np.min(ellipse[0])
|
| 249 |
+
max_x = np.max(ellipse[0]) + 1
|
| 250 |
+
min_y = np.min(ellipse[1])
|
| 251 |
+
max_y = np.max(ellipse[1]) + 1
|
| 252 |
+
label = ('ellipse', ((min_x, max_x), (min_y, max_y)))
|
| 253 |
+
|
| 254 |
+
return ellipse, label
|
| 255 |
+
|
| 256 |
+
|
| 257 |
+
# Allows lookup by key as well as random selection.
|
| 258 |
+
SHAPE_GENERATORS = dict(
|
| 259 |
+
rectangle=_generate_rectangle_mask,
|
| 260 |
+
circle=_generate_circle_mask,
|
| 261 |
+
triangle=_generate_triangle_mask,
|
| 262 |
+
ellipse=_generate_ellipse_mask,
|
| 263 |
+
)
|
| 264 |
+
SHAPE_CHOICES = list(SHAPE_GENERATORS.values())
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
def _generate_random_colors(num_colors, num_channels, intensity_range, random):
|
| 268 |
+
"""Generate an array of random colors.
|
| 269 |
+
|
| 270 |
+
Parameters
|
| 271 |
+
----------
|
| 272 |
+
num_colors : int
|
| 273 |
+
Number of colors to generate.
|
| 274 |
+
num_channels : int
|
| 275 |
+
Number of elements representing color.
|
| 276 |
+
intensity_range : {tuple of tuples of ints, tuple of ints}, optional
|
| 277 |
+
The range of values to sample pixel values from. For grayscale images
|
| 278 |
+
the format is (min, max). For multichannel - ((min, max),) if the
|
| 279 |
+
ranges are equal across the channels, and
|
| 280 |
+
((min_0, max_0), ... (min_N, max_N)) if they differ.
|
| 281 |
+
random : `numpy.random.Generator`
|
| 282 |
+
The random state to use for random sampling.
|
| 283 |
+
|
| 284 |
+
Raises
|
| 285 |
+
------
|
| 286 |
+
ValueError
|
| 287 |
+
When the `intensity_range` is not in the interval (0, 255).
|
| 288 |
+
|
| 289 |
+
Returns
|
| 290 |
+
-------
|
| 291 |
+
colors : array
|
| 292 |
+
An array of shape (num_colors, num_channels), where the values for
|
| 293 |
+
each channel are drawn from the corresponding `intensity_range`.
|
| 294 |
+
|
| 295 |
+
"""
|
| 296 |
+
if num_channels == 1:
|
| 297 |
+
intensity_range = (intensity_range,)
|
| 298 |
+
elif len(intensity_range) == 1:
|
| 299 |
+
intensity_range = intensity_range * num_channels
|
| 300 |
+
colors = [random.integers(r[0], r[1] + 1, size=num_colors) for r in intensity_range]
|
| 301 |
+
return np.transpose(colors)
|
| 302 |
+
|
| 303 |
+
|
| 304 |
+
def random_shapes(
|
| 305 |
+
image_shape,
|
| 306 |
+
max_shapes,
|
| 307 |
+
min_shapes=1,
|
| 308 |
+
min_size=2,
|
| 309 |
+
max_size=None,
|
| 310 |
+
num_channels=3,
|
| 311 |
+
shape=None,
|
| 312 |
+
intensity_range=None,
|
| 313 |
+
allow_overlap=False,
|
| 314 |
+
num_trials=100,
|
| 315 |
+
rng=None,
|
| 316 |
+
*,
|
| 317 |
+
channel_axis=-1,
|
| 318 |
+
):
|
| 319 |
+
"""Generate an image with random shapes, labeled with bounding boxes.
|
| 320 |
+
|
| 321 |
+
The image is populated with random shapes with random sizes, random
|
| 322 |
+
locations, and random colors, with or without overlap.
|
| 323 |
+
|
| 324 |
+
Shapes have random (row, col) starting coordinates and random sizes bounded
|
| 325 |
+
by `min_size` and `max_size`. It can occur that a randomly generated shape
|
| 326 |
+
will not fit the image at all. In that case, the algorithm will try again
|
| 327 |
+
with new starting coordinates a certain number of times. However, it also
|
| 328 |
+
means that some shapes may be skipped altogether. In that case, this
|
| 329 |
+
function will generate fewer shapes than requested.
|
| 330 |
+
|
| 331 |
+
Parameters
|
| 332 |
+
----------
|
| 333 |
+
image_shape : tuple
|
| 334 |
+
The number of rows and columns of the image to generate.
|
| 335 |
+
max_shapes : int
|
| 336 |
+
The maximum number of shapes to (attempt to) fit into the shape.
|
| 337 |
+
min_shapes : int, optional
|
| 338 |
+
The minimum number of shapes to (attempt to) fit into the shape.
|
| 339 |
+
min_size : int, optional
|
| 340 |
+
The minimum dimension of each shape to fit into the image.
|
| 341 |
+
max_size : int, optional
|
| 342 |
+
The maximum dimension of each shape to fit into the image.
|
| 343 |
+
num_channels : int, optional
|
| 344 |
+
Number of channels in the generated image. If 1, generate monochrome
|
| 345 |
+
images, else color images with multiple channels. Ignored if
|
| 346 |
+
``multichannel`` is set to False.
|
| 347 |
+
shape : {rectangle, circle, triangle, ellipse, None} str, optional
|
| 348 |
+
The name of the shape to generate or `None` to pick random ones.
|
| 349 |
+
intensity_range : {tuple of tuples of uint8, tuple of uint8}, optional
|
| 350 |
+
The range of values to sample pixel values from. For grayscale
|
| 351 |
+
images the format is (min, max). For multichannel - ((min, max),)
|
| 352 |
+
if the ranges are equal across the channels, and
|
| 353 |
+
((min_0, max_0), ... (min_N, max_N)) if they differ. As the
|
| 354 |
+
function supports generation of uint8 arrays only, the maximum
|
| 355 |
+
range is (0, 255). If None, set to (0, 254) for each channel
|
| 356 |
+
reserving color of intensity = 255 for background.
|
| 357 |
+
allow_overlap : bool, optional
|
| 358 |
+
If `True`, allow shapes to overlap.
|
| 359 |
+
num_trials : int, optional
|
| 360 |
+
How often to attempt to fit a shape into the image before skipping it.
|
| 361 |
+
rng : {`numpy.random.Generator`, int}, optional
|
| 362 |
+
Pseudo-random number generator.
|
| 363 |
+
By default, a PCG64 generator is used (see :func:`numpy.random.default_rng`).
|
| 364 |
+
If `rng` is an int, it is used to seed the generator.
|
| 365 |
+
channel_axis : int or None, optional
|
| 366 |
+
If None, the image is assumed to be a grayscale (single channel) image.
|
| 367 |
+
Otherwise, this parameter indicates which axis of the array corresponds
|
| 368 |
+
to channels.
|
| 369 |
+
|
| 370 |
+
.. versionadded:: 0.19
|
| 371 |
+
``channel_axis`` was added in 0.19.
|
| 372 |
+
|
| 373 |
+
Returns
|
| 374 |
+
-------
|
| 375 |
+
image : uint8 array
|
| 376 |
+
An image with the fitted shapes.
|
| 377 |
+
labels : list
|
| 378 |
+
A list of labels, one per shape in the image. Each label is a
|
| 379 |
+
(category, ((r0, r1), (c0, c1))) tuple specifying the category and
|
| 380 |
+
bounding box coordinates of the shape.
|
| 381 |
+
|
| 382 |
+
Examples
|
| 383 |
+
--------
|
| 384 |
+
>>> import skimage.draw
|
| 385 |
+
>>> image, labels = skimage.draw.random_shapes((32, 32), max_shapes=3)
|
| 386 |
+
>>> image # doctest: +SKIP
|
| 387 |
+
array([
|
| 388 |
+
[[255, 255, 255],
|
| 389 |
+
[255, 255, 255],
|
| 390 |
+
[255, 255, 255],
|
| 391 |
+
...,
|
| 392 |
+
[255, 255, 255],
|
| 393 |
+
[255, 255, 255],
|
| 394 |
+
[255, 255, 255]]], dtype=uint8)
|
| 395 |
+
>>> labels # doctest: +SKIP
|
| 396 |
+
[('circle', ((22, 18), (25, 21))),
|
| 397 |
+
('triangle', ((5, 6), (13, 13)))]
|
| 398 |
+
"""
|
| 399 |
+
if min_size > image_shape[0] or min_size > image_shape[1]:
|
| 400 |
+
raise ValueError('Minimum dimension must be less than ncols and nrows')
|
| 401 |
+
max_size = max_size or max(image_shape[0], image_shape[1])
|
| 402 |
+
|
| 403 |
+
if channel_axis is None:
|
| 404 |
+
num_channels = 1
|
| 405 |
+
|
| 406 |
+
if intensity_range is None:
|
| 407 |
+
intensity_range = (0, 254) if num_channels == 1 else ((0, 254),)
|
| 408 |
+
else:
|
| 409 |
+
tmp = (intensity_range,) if num_channels == 1 else intensity_range
|
| 410 |
+
for intensity_pair in tmp:
|
| 411 |
+
for intensity in intensity_pair:
|
| 412 |
+
if not (0 <= intensity <= 255):
|
| 413 |
+
msg = 'Intensity range must lie within (0, 255) interval'
|
| 414 |
+
raise ValueError(msg)
|
| 415 |
+
|
| 416 |
+
rng = np.random.default_rng(rng)
|
| 417 |
+
user_shape = shape
|
| 418 |
+
image_shape = (image_shape[0], image_shape[1], num_channels)
|
| 419 |
+
image = np.full(image_shape, 255, dtype=np.uint8)
|
| 420 |
+
filled = np.zeros(image_shape, dtype=bool)
|
| 421 |
+
labels = []
|
| 422 |
+
|
| 423 |
+
num_shapes = rng.integers(min_shapes, max_shapes + 1)
|
| 424 |
+
colors = _generate_random_colors(num_shapes, num_channels, intensity_range, rng)
|
| 425 |
+
shape = (min_size, max_size)
|
| 426 |
+
for shape_idx in range(num_shapes):
|
| 427 |
+
if user_shape is None:
|
| 428 |
+
shape_generator = rng.choice(SHAPE_CHOICES)
|
| 429 |
+
else:
|
| 430 |
+
shape_generator = SHAPE_GENERATORS[user_shape]
|
| 431 |
+
for _ in range(num_trials):
|
| 432 |
+
# Pick start coordinates.
|
| 433 |
+
column = rng.integers(max(1, image_shape[1] - min_size))
|
| 434 |
+
row = rng.integers(max(1, image_shape[0] - min_size))
|
| 435 |
+
point = (row, column)
|
| 436 |
+
try:
|
| 437 |
+
indices, label = shape_generator(point, image_shape, shape, rng)
|
| 438 |
+
except ArithmeticError:
|
| 439 |
+
# Couldn't fit the shape, skip it.
|
| 440 |
+
indices = []
|
| 441 |
+
continue
|
| 442 |
+
# Check if there is an overlap where the mask is nonzero.
|
| 443 |
+
if allow_overlap or not filled[indices].any():
|
| 444 |
+
image[indices] = colors[shape_idx]
|
| 445 |
+
filled[indices] = True
|
| 446 |
+
labels.append(label)
|
| 447 |
+
break
|
| 448 |
+
else:
|
| 449 |
+
warn(
|
| 450 |
+
'Could not fit any shapes to image, '
|
| 451 |
+
'consider reducing the minimum dimension'
|
| 452 |
+
)
|
| 453 |
+
|
| 454 |
+
if channel_axis is None:
|
| 455 |
+
image = np.squeeze(image, axis=2)
|
| 456 |
+
else:
|
| 457 |
+
image = np.moveaxis(image, -1, channel_axis)
|
| 458 |
+
|
| 459 |
+
return image, labels
|
envs/kitoverlay/skimage/draw/draw.py
ADDED
|
@@ -0,0 +1,970 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
from .._shared._geometry import polygon_clip
|
| 4 |
+
from .._shared.version_requirements import require
|
| 5 |
+
from .._shared.compat import NP_COPY_IF_NEEDED
|
| 6 |
+
from ._draw import (
|
| 7 |
+
_coords_inside_image,
|
| 8 |
+
_line,
|
| 9 |
+
_line_aa,
|
| 10 |
+
_polygon,
|
| 11 |
+
_ellipse_perimeter,
|
| 12 |
+
_circle_perimeter,
|
| 13 |
+
_circle_perimeter_aa,
|
| 14 |
+
_bezier_curve,
|
| 15 |
+
)
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
__doctest_requires__ = {("polygon_perimeter", "rectangle_perimeter"): ["matplotlib"]}
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def _ellipse_in_shape(shape, center, radii, rotation=0.0):
|
| 22 |
+
"""Generate coordinates of points within ellipse bounded by shape.
|
| 23 |
+
|
| 24 |
+
Parameters
|
| 25 |
+
----------
|
| 26 |
+
shape : iterable of ints
|
| 27 |
+
Shape of the input image. Must be at least length 2. Only the first
|
| 28 |
+
two values are used to determine the extent of the input image.
|
| 29 |
+
center : iterable of floats
|
| 30 |
+
(row, column) position of center inside the given shape.
|
| 31 |
+
radii : iterable of floats
|
| 32 |
+
Size of two half axes (for row and column)
|
| 33 |
+
rotation : float, optional
|
| 34 |
+
Rotation of the ellipse defined by the above, in radians
|
| 35 |
+
in range (-PI, PI), in contra clockwise direction,
|
| 36 |
+
with respect to the column-axis.
|
| 37 |
+
|
| 38 |
+
Returns
|
| 39 |
+
-------
|
| 40 |
+
rows : iterable of ints
|
| 41 |
+
Row coordinates representing values within the ellipse.
|
| 42 |
+
cols : iterable of ints
|
| 43 |
+
Corresponding column coordinates representing values within the ellipse.
|
| 44 |
+
"""
|
| 45 |
+
r_lim, c_lim = np.ogrid[0 : float(shape[0]), 0 : float(shape[1])]
|
| 46 |
+
r_org, c_org = center
|
| 47 |
+
r_rad, c_rad = radii
|
| 48 |
+
rotation %= np.pi
|
| 49 |
+
sin_alpha, cos_alpha = np.sin(rotation), np.cos(rotation)
|
| 50 |
+
r, c = (r_lim - r_org), (c_lim - c_org)
|
| 51 |
+
distances = ((r * cos_alpha + c * sin_alpha) / r_rad) ** 2 + (
|
| 52 |
+
(r * sin_alpha - c * cos_alpha) / c_rad
|
| 53 |
+
) ** 2
|
| 54 |
+
return np.nonzero(distances < 1)
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def ellipse(r, c, r_radius, c_radius, shape=None, rotation=0.0):
|
| 58 |
+
"""Generate coordinates of pixels within ellipse.
|
| 59 |
+
|
| 60 |
+
Parameters
|
| 61 |
+
----------
|
| 62 |
+
r, c : double
|
| 63 |
+
Centre coordinate of ellipse.
|
| 64 |
+
r_radius, c_radius : double
|
| 65 |
+
Minor and major semi-axes. ``(r/r_radius)**2 + (c/c_radius)**2 = 1``.
|
| 66 |
+
shape : tuple, optional
|
| 67 |
+
Image shape which is used to determine the maximum extent of output pixel
|
| 68 |
+
coordinates. This is useful for ellipses which exceed the image size.
|
| 69 |
+
By default the full extent of the ellipse are used. Must be at least
|
| 70 |
+
length 2. Only the first two values are used to determine the extent.
|
| 71 |
+
rotation : float, optional (default 0.)
|
| 72 |
+
Set the ellipse rotation (rotation) in range (-PI, PI)
|
| 73 |
+
in contra clock wise direction, so PI/2 degree means swap ellipse axis
|
| 74 |
+
|
| 75 |
+
Returns
|
| 76 |
+
-------
|
| 77 |
+
rr, cc : ndarray of int
|
| 78 |
+
Pixel coordinates of ellipse.
|
| 79 |
+
May be used to directly index into an array, e.g.
|
| 80 |
+
``img[rr, cc] = 1``.
|
| 81 |
+
|
| 82 |
+
Examples
|
| 83 |
+
--------
|
| 84 |
+
>>> from skimage.draw import ellipse
|
| 85 |
+
>>> img = np.zeros((10, 12), dtype=np.uint8)
|
| 86 |
+
>>> rr, cc = ellipse(5, 6, 3, 5, rotation=np.deg2rad(30))
|
| 87 |
+
>>> img[rr, cc] = 1
|
| 88 |
+
>>> img
|
| 89 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 90 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 91 |
+
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0],
|
| 92 |
+
[0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 93 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 94 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 95 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 96 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 97 |
+
[0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
|
| 98 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 99 |
+
|
| 100 |
+
Notes
|
| 101 |
+
-----
|
| 102 |
+
The ellipse equation::
|
| 103 |
+
|
| 104 |
+
((x * cos(alpha) + y * sin(alpha)) / x_radius) ** 2 +
|
| 105 |
+
((x * sin(alpha) - y * cos(alpha)) / y_radius) ** 2 = 1
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
Note that the positions of `ellipse` without specified `shape` can have
|
| 109 |
+
also, negative values, as this is correct on the plane. On the other hand
|
| 110 |
+
using these ellipse positions for an image afterwards may lead to appearing
|
| 111 |
+
on the other side of image, because ``image[-1, -1] = image[end-1, end-1]``
|
| 112 |
+
|
| 113 |
+
>>> rr, cc = ellipse(1, 2, 3, 6)
|
| 114 |
+
>>> img = np.zeros((6, 12), dtype=np.uint8)
|
| 115 |
+
>>> img[rr, cc] = 1
|
| 116 |
+
>>> img
|
| 117 |
+
array([[1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
|
| 118 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
|
| 119 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1],
|
| 120 |
+
[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1],
|
| 121 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 122 |
+
[1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 1]], dtype=uint8)
|
| 123 |
+
"""
|
| 124 |
+
|
| 125 |
+
center = np.array([r, c])
|
| 126 |
+
radii = np.array([r_radius, c_radius])
|
| 127 |
+
# allow just rotation with in range +/- 180 degree
|
| 128 |
+
rotation %= np.pi
|
| 129 |
+
|
| 130 |
+
# compute rotated radii by given rotation
|
| 131 |
+
r_radius_rot = abs(r_radius * np.cos(rotation)) + c_radius * np.sin(rotation)
|
| 132 |
+
c_radius_rot = r_radius * np.sin(rotation) + abs(c_radius * np.cos(rotation))
|
| 133 |
+
# The upper_left and lower_right corners of the smallest rectangle
|
| 134 |
+
# containing the ellipse.
|
| 135 |
+
radii_rot = np.array([r_radius_rot, c_radius_rot])
|
| 136 |
+
upper_left = np.ceil(center - radii_rot).astype(int)
|
| 137 |
+
lower_right = np.floor(center + radii_rot).astype(int)
|
| 138 |
+
|
| 139 |
+
if shape is not None:
|
| 140 |
+
# Constrain upper_left and lower_right by shape boundary.
|
| 141 |
+
upper_left = np.maximum(upper_left, np.array([0, 0]))
|
| 142 |
+
lower_right = np.minimum(lower_right, np.array(shape[:2]) - 1)
|
| 143 |
+
|
| 144 |
+
shifted_center = center - upper_left
|
| 145 |
+
bounding_shape = lower_right - upper_left + 1
|
| 146 |
+
|
| 147 |
+
rr, cc = _ellipse_in_shape(bounding_shape, shifted_center, radii, rotation)
|
| 148 |
+
rr.flags.writeable = True
|
| 149 |
+
cc.flags.writeable = True
|
| 150 |
+
rr += upper_left[0]
|
| 151 |
+
cc += upper_left[1]
|
| 152 |
+
return rr, cc
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
def disk(center, radius, *, shape=None):
|
| 156 |
+
"""Generate coordinates of pixels within circle.
|
| 157 |
+
|
| 158 |
+
Parameters
|
| 159 |
+
----------
|
| 160 |
+
center : tuple
|
| 161 |
+
Center coordinate of disk.
|
| 162 |
+
radius : double
|
| 163 |
+
Radius of disk.
|
| 164 |
+
shape : tuple, optional
|
| 165 |
+
Image shape as a tuple of size 2. Determines the maximum
|
| 166 |
+
extent of output pixel coordinates. This is useful for disks that
|
| 167 |
+
exceed the image size. If None, the full extent of the disk is used.
|
| 168 |
+
The shape might result in negative coordinates and wraparound
|
| 169 |
+
behaviour.
|
| 170 |
+
|
| 171 |
+
Returns
|
| 172 |
+
-------
|
| 173 |
+
rr, cc : ndarray of int
|
| 174 |
+
Pixel coordinates of disk.
|
| 175 |
+
May be used to directly index into an array, e.g.
|
| 176 |
+
``img[rr, cc] = 1``.
|
| 177 |
+
|
| 178 |
+
Examples
|
| 179 |
+
--------
|
| 180 |
+
>>> import numpy as np
|
| 181 |
+
>>> from skimage.draw import disk
|
| 182 |
+
>>> shape = (4, 4)
|
| 183 |
+
>>> img = np.zeros(shape, dtype=np.uint8)
|
| 184 |
+
>>> rr, cc = disk((0, 0), 2, shape=shape)
|
| 185 |
+
>>> img[rr, cc] = 1
|
| 186 |
+
>>> img
|
| 187 |
+
array([[1, 1, 0, 0],
|
| 188 |
+
[1, 1, 0, 0],
|
| 189 |
+
[0, 0, 0, 0],
|
| 190 |
+
[0, 0, 0, 0]], dtype=uint8)
|
| 191 |
+
>>> img = np.zeros(shape, dtype=np.uint8)
|
| 192 |
+
>>> # Negative coordinates in rr and cc perform a wraparound
|
| 193 |
+
>>> rr, cc = disk((0, 0), 2, shape=None)
|
| 194 |
+
>>> img[rr, cc] = 1
|
| 195 |
+
>>> img
|
| 196 |
+
array([[1, 1, 0, 1],
|
| 197 |
+
[1, 1, 0, 1],
|
| 198 |
+
[0, 0, 0, 0],
|
| 199 |
+
[1, 1, 0, 1]], dtype=uint8)
|
| 200 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 201 |
+
>>> rr, cc = disk((4, 4), 5)
|
| 202 |
+
>>> img[rr, cc] = 1
|
| 203 |
+
>>> img
|
| 204 |
+
array([[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 205 |
+
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 206 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 207 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 208 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 209 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 210 |
+
[1, 1, 1, 1, 1, 1, 1, 1, 1, 0],
|
| 211 |
+
[0, 1, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 212 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 213 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 214 |
+
"""
|
| 215 |
+
r, c = center
|
| 216 |
+
return ellipse(r, c, radius, radius, shape)
|
| 217 |
+
|
| 218 |
+
|
| 219 |
+
@require("matplotlib", ">=3.3")
|
| 220 |
+
def polygon_perimeter(r, c, shape=None, clip=False):
|
| 221 |
+
"""Generate polygon perimeter coordinates.
|
| 222 |
+
|
| 223 |
+
Parameters
|
| 224 |
+
----------
|
| 225 |
+
r : (N,) ndarray
|
| 226 |
+
Row coordinates of vertices of polygon.
|
| 227 |
+
c : (N,) ndarray
|
| 228 |
+
Column coordinates of vertices of polygon.
|
| 229 |
+
shape : tuple, optional
|
| 230 |
+
Image shape which is used to determine maximum extents of output pixel
|
| 231 |
+
coordinates. This is useful for polygons that exceed the image size.
|
| 232 |
+
If None, the full extents of the polygon is used. Must be at least
|
| 233 |
+
length 2. Only the first two values are used to determine the extent of
|
| 234 |
+
the input image.
|
| 235 |
+
clip : bool, optional
|
| 236 |
+
Whether to clip the polygon to the provided shape. If this is set
|
| 237 |
+
to True, the drawn figure will always be a closed polygon with all
|
| 238 |
+
edges visible.
|
| 239 |
+
|
| 240 |
+
Returns
|
| 241 |
+
-------
|
| 242 |
+
rr, cc : ndarray of int
|
| 243 |
+
Pixel coordinates of polygon.
|
| 244 |
+
May be used to directly index into an array, e.g.
|
| 245 |
+
``img[rr, cc] = 1``.
|
| 246 |
+
|
| 247 |
+
Examples
|
| 248 |
+
--------
|
| 249 |
+
>>> from skimage.draw import polygon_perimeter
|
| 250 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 251 |
+
>>> rr, cc = polygon_perimeter([5, -1, 5, 10],
|
| 252 |
+
... [-1, 5, 11, 5],
|
| 253 |
+
... shape=img.shape, clip=True)
|
| 254 |
+
>>> img[rr, cc] = 1
|
| 255 |
+
>>> img
|
| 256 |
+
array([[0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
|
| 257 |
+
[0, 0, 0, 1, 0, 0, 0, 1, 0, 0],
|
| 258 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
|
| 259 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 260 |
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 261 |
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 262 |
+
[1, 0, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 263 |
+
[0, 1, 1, 0, 0, 0, 0, 0, 0, 1],
|
| 264 |
+
[0, 0, 0, 1, 0, 0, 0, 1, 1, 0],
|
| 265 |
+
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0]], dtype=uint8)
|
| 266 |
+
|
| 267 |
+
"""
|
| 268 |
+
if clip:
|
| 269 |
+
if shape is None:
|
| 270 |
+
raise ValueError("Must specify clipping shape")
|
| 271 |
+
clip_box = np.array([0, 0, shape[0] - 1, shape[1] - 1])
|
| 272 |
+
else:
|
| 273 |
+
clip_box = np.array([np.min(r), np.min(c), np.max(r), np.max(c)])
|
| 274 |
+
|
| 275 |
+
# Do the clipping irrespective of whether clip is set. This
|
| 276 |
+
# ensures that the returned polygon is closed and is an array.
|
| 277 |
+
r, c = polygon_clip(r, c, *clip_box)
|
| 278 |
+
|
| 279 |
+
r = np.round(r).astype(int)
|
| 280 |
+
c = np.round(c).astype(int)
|
| 281 |
+
|
| 282 |
+
# Construct line segments
|
| 283 |
+
rr, cc = [], []
|
| 284 |
+
for i in range(len(r) - 1):
|
| 285 |
+
line_r, line_c = line(r[i], c[i], r[i + 1], c[i + 1])
|
| 286 |
+
rr.extend(line_r)
|
| 287 |
+
cc.extend(line_c)
|
| 288 |
+
|
| 289 |
+
rr = np.asarray(rr)
|
| 290 |
+
cc = np.asarray(cc)
|
| 291 |
+
|
| 292 |
+
if shape is None:
|
| 293 |
+
return rr, cc
|
| 294 |
+
else:
|
| 295 |
+
return _coords_inside_image(rr, cc, shape)
|
| 296 |
+
|
| 297 |
+
|
| 298 |
+
def set_color(image, coords, color, alpha=1):
|
| 299 |
+
"""Set pixel color in the image at the given coordinates.
|
| 300 |
+
|
| 301 |
+
Note that this function modifies the color of the image in-place.
|
| 302 |
+
Coordinates that exceed the shape of the image will be ignored.
|
| 303 |
+
|
| 304 |
+
Parameters
|
| 305 |
+
----------
|
| 306 |
+
image : (M, N, C) ndarray
|
| 307 |
+
Image
|
| 308 |
+
coords : tuple of ((K,) ndarray, (K,) ndarray)
|
| 309 |
+
Row and column coordinates of pixels to be colored.
|
| 310 |
+
color : (C,) ndarray
|
| 311 |
+
Color to be assigned to coordinates in the image.
|
| 312 |
+
alpha : scalar or (K,) ndarray
|
| 313 |
+
Alpha values used to blend color with image. 0 is transparent,
|
| 314 |
+
1 is opaque.
|
| 315 |
+
|
| 316 |
+
Examples
|
| 317 |
+
--------
|
| 318 |
+
>>> from skimage.draw import line, set_color
|
| 319 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 320 |
+
>>> rr, cc = line(1, 1, 20, 20)
|
| 321 |
+
>>> set_color(img, (rr, cc), 1)
|
| 322 |
+
>>> img
|
| 323 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 324 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 325 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
| 326 |
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
|
| 327 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 328 |
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
| 329 |
+
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
|
| 330 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
| 331 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 332 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 1]], dtype=uint8)
|
| 333 |
+
|
| 334 |
+
"""
|
| 335 |
+
rr, cc = coords
|
| 336 |
+
|
| 337 |
+
if image.ndim == 2:
|
| 338 |
+
image = image[..., np.newaxis]
|
| 339 |
+
|
| 340 |
+
color = np.array(color, ndmin=1, copy=NP_COPY_IF_NEEDED)
|
| 341 |
+
|
| 342 |
+
if image.shape[-1] != color.shape[-1]:
|
| 343 |
+
raise ValueError(
|
| 344 |
+
f'Color shape ({color.shape[0]}) must match last '
|
| 345 |
+
'image dimension ({image.shape[-1]}).'
|
| 346 |
+
)
|
| 347 |
+
|
| 348 |
+
if np.isscalar(alpha):
|
| 349 |
+
# Can be replaced by ``full_like`` when numpy 1.8 becomes
|
| 350 |
+
# minimum dependency
|
| 351 |
+
alpha = np.ones_like(rr) * alpha
|
| 352 |
+
|
| 353 |
+
rr, cc, alpha = _coords_inside_image(rr, cc, image.shape, val=alpha)
|
| 354 |
+
|
| 355 |
+
alpha = alpha[..., np.newaxis]
|
| 356 |
+
|
| 357 |
+
color = color * alpha
|
| 358 |
+
vals = image[rr, cc] * (1 - alpha)
|
| 359 |
+
|
| 360 |
+
image[rr, cc] = vals + color
|
| 361 |
+
|
| 362 |
+
|
| 363 |
+
def line(r0, c0, r1, c1):
|
| 364 |
+
"""Generate line pixel coordinates.
|
| 365 |
+
|
| 366 |
+
Parameters
|
| 367 |
+
----------
|
| 368 |
+
r0, c0 : int
|
| 369 |
+
Starting position (row, column).
|
| 370 |
+
r1, c1 : int
|
| 371 |
+
End position (row, column).
|
| 372 |
+
|
| 373 |
+
Returns
|
| 374 |
+
-------
|
| 375 |
+
rr, cc : (N,) ndarray of int
|
| 376 |
+
Indices of pixels that belong to the line.
|
| 377 |
+
May be used to directly index into an array, e.g.
|
| 378 |
+
``img[rr, cc] = 1``.
|
| 379 |
+
|
| 380 |
+
Notes
|
| 381 |
+
-----
|
| 382 |
+
Anti-aliased line generator is available with `line_aa`.
|
| 383 |
+
|
| 384 |
+
Examples
|
| 385 |
+
--------
|
| 386 |
+
>>> from skimage.draw import line
|
| 387 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 388 |
+
>>> rr, cc = line(1, 1, 8, 8)
|
| 389 |
+
>>> img[rr, cc] = 1
|
| 390 |
+
>>> img
|
| 391 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 392 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 393 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
| 394 |
+
[0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
|
| 395 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 396 |
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
| 397 |
+
[0, 0, 0, 0, 0, 0, 1, 0, 0, 0],
|
| 398 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0],
|
| 399 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 400 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 401 |
+
"""
|
| 402 |
+
return _line(r0, c0, r1, c1)
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def line_aa(r0, c0, r1, c1):
|
| 406 |
+
"""Generate anti-aliased line pixel coordinates.
|
| 407 |
+
|
| 408 |
+
Parameters
|
| 409 |
+
----------
|
| 410 |
+
r0, c0 : int
|
| 411 |
+
Starting position (row, column).
|
| 412 |
+
r1, c1 : int
|
| 413 |
+
End position (row, column).
|
| 414 |
+
|
| 415 |
+
Returns
|
| 416 |
+
-------
|
| 417 |
+
rr, cc, val : (N,) ndarray (int, int, float)
|
| 418 |
+
Indices of pixels (`rr`, `cc`) and intensity values (`val`).
|
| 419 |
+
``img[rr, cc] = val``.
|
| 420 |
+
|
| 421 |
+
References
|
| 422 |
+
----------
|
| 423 |
+
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
|
| 424 |
+
http://members.chello.at/easyfilter/Bresenham.pdf
|
| 425 |
+
|
| 426 |
+
Examples
|
| 427 |
+
--------
|
| 428 |
+
>>> from skimage.draw import line_aa
|
| 429 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 430 |
+
>>> rr, cc, val = line_aa(1, 1, 8, 8)
|
| 431 |
+
>>> img[rr, cc] = val * 255
|
| 432 |
+
>>> img
|
| 433 |
+
array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 434 |
+
[ 0, 255, 74, 0, 0, 0, 0, 0, 0, 0],
|
| 435 |
+
[ 0, 74, 255, 74, 0, 0, 0, 0, 0, 0],
|
| 436 |
+
[ 0, 0, 74, 255, 74, 0, 0, 0, 0, 0],
|
| 437 |
+
[ 0, 0, 0, 74, 255, 74, 0, 0, 0, 0],
|
| 438 |
+
[ 0, 0, 0, 0, 74, 255, 74, 0, 0, 0],
|
| 439 |
+
[ 0, 0, 0, 0, 0, 74, 255, 74, 0, 0],
|
| 440 |
+
[ 0, 0, 0, 0, 0, 0, 74, 255, 74, 0],
|
| 441 |
+
[ 0, 0, 0, 0, 0, 0, 0, 74, 255, 0],
|
| 442 |
+
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 443 |
+
"""
|
| 444 |
+
return _line_aa(r0, c0, r1, c1)
|
| 445 |
+
|
| 446 |
+
|
| 447 |
+
def polygon(r, c, shape=None):
|
| 448 |
+
"""Generate coordinates of pixels inside a polygon.
|
| 449 |
+
|
| 450 |
+
Parameters
|
| 451 |
+
----------
|
| 452 |
+
r : (N,) array_like
|
| 453 |
+
Row coordinates of the polygon's vertices.
|
| 454 |
+
c : (N,) array_like
|
| 455 |
+
Column coordinates of the polygon's vertices.
|
| 456 |
+
shape : tuple, optional
|
| 457 |
+
Image shape which is used to determine the maximum extent of output
|
| 458 |
+
pixel coordinates. This is useful for polygons that exceed the image
|
| 459 |
+
size. If None, the full extent of the polygon is used. Must be at
|
| 460 |
+
least length 2. Only the first two values are used to determine the
|
| 461 |
+
extent of the input image.
|
| 462 |
+
|
| 463 |
+
Returns
|
| 464 |
+
-------
|
| 465 |
+
rr, cc : ndarray of int
|
| 466 |
+
Pixel coordinates of polygon.
|
| 467 |
+
May be used to directly index into an array, e.g.
|
| 468 |
+
``img[rr, cc] = 1``.
|
| 469 |
+
|
| 470 |
+
See Also
|
| 471 |
+
--------
|
| 472 |
+
polygon2mask:
|
| 473 |
+
Create a binary mask from a polygon.
|
| 474 |
+
|
| 475 |
+
Notes
|
| 476 |
+
-----
|
| 477 |
+
This function ensures that `rr` and `cc` don't contain negative values.
|
| 478 |
+
Pixels of the polygon that whose coordinates are smaller 0, are not drawn.
|
| 479 |
+
|
| 480 |
+
Examples
|
| 481 |
+
--------
|
| 482 |
+
>>> import skimage as ski
|
| 483 |
+
>>> r = np.array([1, 2, 8])
|
| 484 |
+
>>> c = np.array([1, 7, 4])
|
| 485 |
+
>>> rr, cc = ski.draw.polygon(r, c)
|
| 486 |
+
>>> img = np.zeros((10, 10), dtype=int)
|
| 487 |
+
>>> img[rr, cc] = 1
|
| 488 |
+
>>> img
|
| 489 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 490 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 491 |
+
[0, 0, 1, 1, 1, 1, 1, 1, 0, 0],
|
| 492 |
+
[0, 0, 1, 1, 1, 1, 1, 0, 0, 0],
|
| 493 |
+
[0, 0, 0, 1, 1, 1, 1, 0, 0, 0],
|
| 494 |
+
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
|
| 495 |
+
[0, 0, 0, 0, 1, 1, 0, 0, 0, 0],
|
| 496 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 497 |
+
[0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 498 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 499 |
+
|
| 500 |
+
If the image `shape` is defined and vertices / points of the `polygon` are
|
| 501 |
+
outside this coordinate space, only a part (or none at all) of the polygon's
|
| 502 |
+
pixels is returned. Shifting the polygon's vertices by an offset can be used
|
| 503 |
+
to move the polygon around and potentially draw an arbitrary sub-region of
|
| 504 |
+
the polygon.
|
| 505 |
+
|
| 506 |
+
>>> offset = (2, -4)
|
| 507 |
+
>>> rr, cc = ski.draw.polygon(r - offset[0], c - offset[1], shape=img.shape)
|
| 508 |
+
>>> img = np.zeros((10, 10), dtype=int)
|
| 509 |
+
>>> img[rr, cc] = 1
|
| 510 |
+
>>> img
|
| 511 |
+
array([[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
|
| 512 |
+
[0, 0, 0, 0, 0, 0, 1, 1, 1, 1],
|
| 513 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
|
| 514 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 1, 1],
|
| 515 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 1],
|
| 516 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 517 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0],
|
| 518 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 519 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 520 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
|
| 521 |
+
"""
|
| 522 |
+
return _polygon(r, c, shape)
|
| 523 |
+
|
| 524 |
+
|
| 525 |
+
def circle_perimeter(r, c, radius, method='bresenham', shape=None):
|
| 526 |
+
"""Generate circle perimeter coordinates.
|
| 527 |
+
|
| 528 |
+
Parameters
|
| 529 |
+
----------
|
| 530 |
+
r, c : int
|
| 531 |
+
Centre coordinate of circle.
|
| 532 |
+
radius : int
|
| 533 |
+
Radius of circle.
|
| 534 |
+
method : {'bresenham', 'andres'}, optional
|
| 535 |
+
bresenham : Bresenham method (default)
|
| 536 |
+
andres : Andres method
|
| 537 |
+
shape : tuple, optional
|
| 538 |
+
Image shape which is used to determine the maximum extent of output
|
| 539 |
+
pixel coordinates. This is useful for circles that exceed the image
|
| 540 |
+
size. If None, the full extent of the circle is used. Must be at least
|
| 541 |
+
length 2. Only the first two values are used to determine the extent of
|
| 542 |
+
the input image.
|
| 543 |
+
|
| 544 |
+
Returns
|
| 545 |
+
-------
|
| 546 |
+
rr, cc : (N,) ndarray of int
|
| 547 |
+
Bresenham and Andres' method:
|
| 548 |
+
Indices of pixels that belong to the circle perimeter.
|
| 549 |
+
May be used to directly index into an array, e.g.
|
| 550 |
+
``img[rr, cc] = 1``.
|
| 551 |
+
|
| 552 |
+
Notes
|
| 553 |
+
-----
|
| 554 |
+
Andres method presents the advantage that concentric
|
| 555 |
+
circles create a disc whereas Bresenham can make holes. There
|
| 556 |
+
is also less distortions when Andres circles are rotated.
|
| 557 |
+
Bresenham method is also known as midpoint circle algorithm.
|
| 558 |
+
Anti-aliased circle generator is available with `circle_perimeter_aa`.
|
| 559 |
+
|
| 560 |
+
References
|
| 561 |
+
----------
|
| 562 |
+
.. [1] J.E. Bresenham, "Algorithm for computer control of a digital
|
| 563 |
+
plotter", IBM Systems journal, 4 (1965) 25-30.
|
| 564 |
+
.. [2] E. Andres, "Discrete circles, rings and spheres", Computers &
|
| 565 |
+
Graphics, 18 (1994) 695-706.
|
| 566 |
+
|
| 567 |
+
Examples
|
| 568 |
+
--------
|
| 569 |
+
>>> from skimage.draw import circle_perimeter
|
| 570 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 571 |
+
>>> rr, cc = circle_perimeter(4, 4, 3)
|
| 572 |
+
>>> img[rr, cc] = 1
|
| 573 |
+
>>> img
|
| 574 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 575 |
+
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
|
| 576 |
+
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
|
| 577 |
+
[0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
|
| 578 |
+
[0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
|
| 579 |
+
[0, 1, 0, 0, 0, 0, 0, 1, 0, 0],
|
| 580 |
+
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
|
| 581 |
+
[0, 0, 0, 1, 1, 1, 0, 0, 0, 0],
|
| 582 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 583 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 584 |
+
"""
|
| 585 |
+
return _circle_perimeter(r, c, radius, method, shape)
|
| 586 |
+
|
| 587 |
+
|
| 588 |
+
def circle_perimeter_aa(r, c, radius, shape=None):
|
| 589 |
+
"""Generate anti-aliased circle perimeter coordinates.
|
| 590 |
+
|
| 591 |
+
Parameters
|
| 592 |
+
----------
|
| 593 |
+
r, c : int
|
| 594 |
+
Centre coordinate of circle.
|
| 595 |
+
radius : int
|
| 596 |
+
Radius of circle.
|
| 597 |
+
shape : tuple, optional
|
| 598 |
+
Image shape which is used to determine the maximum extent of output
|
| 599 |
+
pixel coordinates. This is useful for circles that exceed the image
|
| 600 |
+
size. If None, the full extent of the circle is used. Must be at least
|
| 601 |
+
length 2. Only the first two values are used to determine the extent of
|
| 602 |
+
the input image.
|
| 603 |
+
|
| 604 |
+
Returns
|
| 605 |
+
-------
|
| 606 |
+
rr, cc, val : (N,) ndarray (int, int, float)
|
| 607 |
+
Indices of pixels (`rr`, `cc`) and intensity values (`val`).
|
| 608 |
+
``img[rr, cc] = val``.
|
| 609 |
+
|
| 610 |
+
Notes
|
| 611 |
+
-----
|
| 612 |
+
Wu's method draws anti-aliased circle. This implementation doesn't use
|
| 613 |
+
lookup table optimization.
|
| 614 |
+
|
| 615 |
+
Use the function ``draw.set_color`` to apply ``circle_perimeter_aa``
|
| 616 |
+
results to color images.
|
| 617 |
+
|
| 618 |
+
References
|
| 619 |
+
----------
|
| 620 |
+
.. [1] X. Wu, "An efficient antialiasing technique", In ACM SIGGRAPH
|
| 621 |
+
Computer Graphics, 25 (1991) 143-152.
|
| 622 |
+
|
| 623 |
+
Examples
|
| 624 |
+
--------
|
| 625 |
+
>>> from skimage.draw import circle_perimeter_aa
|
| 626 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 627 |
+
>>> rr, cc, val = circle_perimeter_aa(4, 4, 3)
|
| 628 |
+
>>> img[rr, cc] = val * 255
|
| 629 |
+
>>> img
|
| 630 |
+
array([[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 631 |
+
[ 0, 0, 60, 211, 255, 211, 60, 0, 0, 0],
|
| 632 |
+
[ 0, 60, 194, 43, 0, 43, 194, 60, 0, 0],
|
| 633 |
+
[ 0, 211, 43, 0, 0, 0, 43, 211, 0, 0],
|
| 634 |
+
[ 0, 255, 0, 0, 0, 0, 0, 255, 0, 0],
|
| 635 |
+
[ 0, 211, 43, 0, 0, 0, 43, 211, 0, 0],
|
| 636 |
+
[ 0, 60, 194, 43, 0, 43, 194, 60, 0, 0],
|
| 637 |
+
[ 0, 0, 60, 211, 255, 211, 60, 0, 0, 0],
|
| 638 |
+
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 639 |
+
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 640 |
+
|
| 641 |
+
>>> from skimage import data, draw
|
| 642 |
+
>>> image = data.chelsea()
|
| 643 |
+
>>> rr, cc, val = draw.circle_perimeter_aa(r=100, c=100, radius=75)
|
| 644 |
+
>>> draw.set_color(image, (rr, cc), [1, 0, 0], alpha=val)
|
| 645 |
+
"""
|
| 646 |
+
return _circle_perimeter_aa(r, c, radius, shape)
|
| 647 |
+
|
| 648 |
+
|
| 649 |
+
def ellipse_perimeter(r, c, r_radius, c_radius, orientation=0, shape=None):
|
| 650 |
+
"""Generate ellipse perimeter coordinates.
|
| 651 |
+
|
| 652 |
+
Parameters
|
| 653 |
+
----------
|
| 654 |
+
r, c : int
|
| 655 |
+
Centre coordinate of ellipse.
|
| 656 |
+
r_radius, c_radius : int
|
| 657 |
+
Minor and major semi-axes. ``(r/r_radius)**2 + (c/c_radius)**2 = 1``.
|
| 658 |
+
orientation : double, optional
|
| 659 |
+
Major axis orientation in clockwise direction as radians.
|
| 660 |
+
shape : tuple, optional
|
| 661 |
+
Image shape which is used to determine the maximum extent of output
|
| 662 |
+
pixel coordinates. This is useful for ellipses that exceed the image
|
| 663 |
+
size. If None, the full extent of the ellipse is used. Must be at
|
| 664 |
+
least length 2. Only the first two values are used to determine the
|
| 665 |
+
extent of the input image.
|
| 666 |
+
|
| 667 |
+
Returns
|
| 668 |
+
-------
|
| 669 |
+
rr, cc : (N,) ndarray of int
|
| 670 |
+
Indices of pixels that belong to the ellipse perimeter.
|
| 671 |
+
May be used to directly index into an array, e.g.
|
| 672 |
+
``img[rr, cc] = 1``.
|
| 673 |
+
|
| 674 |
+
References
|
| 675 |
+
----------
|
| 676 |
+
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
|
| 677 |
+
http://members.chello.at/easyfilter/Bresenham.pdf
|
| 678 |
+
|
| 679 |
+
Examples
|
| 680 |
+
--------
|
| 681 |
+
>>> from skimage.draw import ellipse_perimeter
|
| 682 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 683 |
+
>>> rr, cc = ellipse_perimeter(5, 5, 3, 4)
|
| 684 |
+
>>> img[rr, cc] = 1
|
| 685 |
+
>>> img
|
| 686 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 687 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 688 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 689 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
|
| 690 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 691 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 692 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 1],
|
| 693 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 1, 0],
|
| 694 |
+
[0, 0, 0, 1, 1, 1, 1, 1, 0, 0],
|
| 695 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 696 |
+
|
| 697 |
+
|
| 698 |
+
Note that the positions of `ellipse` without specified `shape` can have
|
| 699 |
+
also, negative values, as this is correct on the plane. On the other hand
|
| 700 |
+
using these ellipse positions for an image afterwards may lead to appearing
|
| 701 |
+
on the other side of image, because ``image[-1, -1] = image[end-1, end-1]``
|
| 702 |
+
|
| 703 |
+
>>> rr, cc = ellipse_perimeter(2, 3, 4, 5)
|
| 704 |
+
>>> img = np.zeros((9, 12), dtype=np.uint8)
|
| 705 |
+
>>> img[rr, cc] = 1
|
| 706 |
+
>>> img
|
| 707 |
+
array([[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
|
| 708 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
|
| 709 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
|
| 710 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
|
| 711 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1],
|
| 712 |
+
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0],
|
| 713 |
+
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
|
| 714 |
+
[0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0],
|
| 715 |
+
[1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 716 |
+
"""
|
| 717 |
+
return _ellipse_perimeter(r, c, r_radius, c_radius, orientation, shape)
|
| 718 |
+
|
| 719 |
+
|
| 720 |
+
def bezier_curve(r0, c0, r1, c1, r2, c2, weight, shape=None):
|
| 721 |
+
"""Generate Bezier curve coordinates.
|
| 722 |
+
|
| 723 |
+
Parameters
|
| 724 |
+
----------
|
| 725 |
+
r0, c0 : int
|
| 726 |
+
Coordinates of the first control point.
|
| 727 |
+
r1, c1 : int
|
| 728 |
+
Coordinates of the middle control point.
|
| 729 |
+
r2, c2 : int
|
| 730 |
+
Coordinates of the last control point.
|
| 731 |
+
weight : double
|
| 732 |
+
Middle control point weight, it describes the line tension.
|
| 733 |
+
shape : tuple, optional
|
| 734 |
+
Image shape which is used to determine the maximum extent of output
|
| 735 |
+
pixel coordinates. This is useful for curves that exceed the image
|
| 736 |
+
size. If None, the full extent of the curve is used.
|
| 737 |
+
|
| 738 |
+
Returns
|
| 739 |
+
-------
|
| 740 |
+
rr, cc : (N,) ndarray of int
|
| 741 |
+
Indices of pixels that belong to the Bezier curve.
|
| 742 |
+
May be used to directly index into an array, e.g.
|
| 743 |
+
``img[rr, cc] = 1``.
|
| 744 |
+
|
| 745 |
+
Notes
|
| 746 |
+
-----
|
| 747 |
+
The algorithm is the rational quadratic algorithm presented in
|
| 748 |
+
reference [1]_.
|
| 749 |
+
|
| 750 |
+
References
|
| 751 |
+
----------
|
| 752 |
+
.. [1] A Rasterizing Algorithm for Drawing Curves, A. Zingl, 2012
|
| 753 |
+
http://members.chello.at/easyfilter/Bresenham.pdf
|
| 754 |
+
|
| 755 |
+
Examples
|
| 756 |
+
--------
|
| 757 |
+
>>> import numpy as np
|
| 758 |
+
>>> from skimage.draw import bezier_curve
|
| 759 |
+
>>> img = np.zeros((10, 10), dtype=np.uint8)
|
| 760 |
+
>>> rr, cc = bezier_curve(1, 5, 5, -2, 8, 8, 2)
|
| 761 |
+
>>> img[rr, cc] = 1
|
| 762 |
+
>>> img
|
| 763 |
+
array([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 764 |
+
[0, 0, 0, 0, 0, 1, 0, 0, 0, 0],
|
| 765 |
+
[0, 0, 0, 1, 1, 0, 0, 0, 0, 0],
|
| 766 |
+
[0, 0, 1, 0, 0, 0, 0, 0, 0, 0],
|
| 767 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 768 |
+
[0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
|
| 769 |
+
[0, 0, 1, 1, 0, 0, 0, 0, 0, 0],
|
| 770 |
+
[0, 0, 0, 0, 1, 1, 1, 0, 0, 0],
|
| 771 |
+
[0, 0, 0, 0, 0, 0, 0, 1, 1, 0],
|
| 772 |
+
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
|
| 773 |
+
"""
|
| 774 |
+
return _bezier_curve(r0, c0, r1, c1, r2, c2, weight, shape)
|
| 775 |
+
|
| 776 |
+
|
| 777 |
+
def rectangle(start, end=None, extent=None, shape=None):
|
| 778 |
+
"""Generate coordinates of pixels within a rectangle.
|
| 779 |
+
|
| 780 |
+
Parameters
|
| 781 |
+
----------
|
| 782 |
+
start : tuple
|
| 783 |
+
Origin point of the rectangle, e.g., ``([plane,] row, column)``.
|
| 784 |
+
end : tuple
|
| 785 |
+
End point of the rectangle ``([plane,] row, column)``.
|
| 786 |
+
For a 2D matrix, the slice defined by the rectangle is
|
| 787 |
+
``[start:(end+1)]``.
|
| 788 |
+
Either `end` or `extent` must be specified.
|
| 789 |
+
extent : tuple
|
| 790 |
+
The extent (size) of the drawn rectangle. E.g.,
|
| 791 |
+
``([num_planes,] num_rows, num_cols)``.
|
| 792 |
+
Either `end` or `extent` must be specified.
|
| 793 |
+
A negative extent is valid, and will result in a rectangle
|
| 794 |
+
going along the opposite direction. If extent is negative, the
|
| 795 |
+
`start` point is not included.
|
| 796 |
+
shape : tuple, optional
|
| 797 |
+
Image shape used to determine the maximum bounds of the output
|
| 798 |
+
coordinates. This is useful for clipping rectangles that exceed
|
| 799 |
+
the image size. By default, no clipping is done.
|
| 800 |
+
|
| 801 |
+
Returns
|
| 802 |
+
-------
|
| 803 |
+
coords : array of int, shape (Ndim, Npoints)
|
| 804 |
+
The coordinates of all pixels in the rectangle.
|
| 805 |
+
|
| 806 |
+
Notes
|
| 807 |
+
-----
|
| 808 |
+
This function can be applied to N-dimensional images, by passing `start` and
|
| 809 |
+
`end` or `extent` as tuples of length N.
|
| 810 |
+
|
| 811 |
+
Examples
|
| 812 |
+
--------
|
| 813 |
+
>>> import numpy as np
|
| 814 |
+
>>> from skimage.draw import rectangle
|
| 815 |
+
>>> img = np.zeros((5, 5), dtype=np.uint8)
|
| 816 |
+
>>> start = (1, 1)
|
| 817 |
+
>>> extent = (3, 3)
|
| 818 |
+
>>> rr, cc = rectangle(start, extent=extent, shape=img.shape)
|
| 819 |
+
>>> img[rr, cc] = 1
|
| 820 |
+
>>> img
|
| 821 |
+
array([[0, 0, 0, 0, 0],
|
| 822 |
+
[0, 1, 1, 1, 0],
|
| 823 |
+
[0, 1, 1, 1, 0],
|
| 824 |
+
[0, 1, 1, 1, 0],
|
| 825 |
+
[0, 0, 0, 0, 0]], dtype=uint8)
|
| 826 |
+
|
| 827 |
+
|
| 828 |
+
>>> img = np.zeros((5, 5), dtype=np.uint8)
|
| 829 |
+
>>> start = (0, 1)
|
| 830 |
+
>>> end = (3, 3)
|
| 831 |
+
>>> rr, cc = rectangle(start, end=end, shape=img.shape)
|
| 832 |
+
>>> img[rr, cc] = 1
|
| 833 |
+
>>> img
|
| 834 |
+
array([[0, 1, 1, 1, 0],
|
| 835 |
+
[0, 1, 1, 1, 0],
|
| 836 |
+
[0, 1, 1, 1, 0],
|
| 837 |
+
[0, 1, 1, 1, 0],
|
| 838 |
+
[0, 0, 0, 0, 0]], dtype=uint8)
|
| 839 |
+
|
| 840 |
+
>>> import numpy as np
|
| 841 |
+
>>> from skimage.draw import rectangle
|
| 842 |
+
>>> img = np.zeros((6, 6), dtype=np.uint8)
|
| 843 |
+
>>> start = (3, 3)
|
| 844 |
+
>>>
|
| 845 |
+
>>> rr, cc = rectangle(start, extent=(2, 2))
|
| 846 |
+
>>> img[rr, cc] = 1
|
| 847 |
+
>>> rr, cc = rectangle(start, extent=(-2, 2))
|
| 848 |
+
>>> img[rr, cc] = 2
|
| 849 |
+
>>> rr, cc = rectangle(start, extent=(-2, -2))
|
| 850 |
+
>>> img[rr, cc] = 3
|
| 851 |
+
>>> rr, cc = rectangle(start, extent=(2, -2))
|
| 852 |
+
>>> img[rr, cc] = 4
|
| 853 |
+
>>> print(img)
|
| 854 |
+
[[0 0 0 0 0 0]
|
| 855 |
+
[0 3 3 2 2 0]
|
| 856 |
+
[0 3 3 2 2 0]
|
| 857 |
+
[0 4 4 1 1 0]
|
| 858 |
+
[0 4 4 1 1 0]
|
| 859 |
+
[0 0 0 0 0 0]]
|
| 860 |
+
|
| 861 |
+
"""
|
| 862 |
+
tl, br = _rectangle_slice(start=start, end=end, extent=extent)
|
| 863 |
+
|
| 864 |
+
if shape is not None:
|
| 865 |
+
n_dim = len(start)
|
| 866 |
+
br = np.minimum(shape[0:n_dim], br)
|
| 867 |
+
tl = np.maximum(np.zeros_like(shape[0:n_dim]), tl)
|
| 868 |
+
coords = np.meshgrid(*[np.arange(st, en) for st, en in zip(tuple(tl), tuple(br))])
|
| 869 |
+
return coords
|
| 870 |
+
|
| 871 |
+
|
| 872 |
+
@require("matplotlib", ">=3.3")
|
| 873 |
+
def rectangle_perimeter(start, end=None, extent=None, shape=None, clip=False):
|
| 874 |
+
"""Generate coordinates of pixels that are exactly around a rectangle.
|
| 875 |
+
|
| 876 |
+
Parameters
|
| 877 |
+
----------
|
| 878 |
+
start : tuple
|
| 879 |
+
Origin point of the inner rectangle, e.g., ``(row, column)``.
|
| 880 |
+
end : tuple
|
| 881 |
+
End point of the inner rectangle ``(row, column)``.
|
| 882 |
+
For a 2D matrix, the slice defined by inner the rectangle is
|
| 883 |
+
``[start:(end+1)]``.
|
| 884 |
+
Either `end` or `extent` must be specified.
|
| 885 |
+
extent : tuple
|
| 886 |
+
The extent (size) of the inner rectangle. E.g.,
|
| 887 |
+
``(num_rows, num_cols)``.
|
| 888 |
+
Either `end` or `extent` must be specified.
|
| 889 |
+
Negative extents are permitted. See `rectangle` to better
|
| 890 |
+
understand how they behave.
|
| 891 |
+
shape : tuple, optional
|
| 892 |
+
Image shape used to determine the maximum bounds of the output
|
| 893 |
+
coordinates. This is useful for clipping perimeters that exceed
|
| 894 |
+
the image size. By default, no clipping is done. Must be at least
|
| 895 |
+
length 2. Only the first two values are used to determine the extent of
|
| 896 |
+
the input image.
|
| 897 |
+
clip : bool, optional
|
| 898 |
+
Whether to clip the perimeter to the provided shape. If this is set
|
| 899 |
+
to True, the drawn figure will always be a closed polygon with all
|
| 900 |
+
edges visible.
|
| 901 |
+
|
| 902 |
+
Returns
|
| 903 |
+
-------
|
| 904 |
+
coords : array of int, shape (2, Npoints)
|
| 905 |
+
The coordinates of all pixels in the rectangle.
|
| 906 |
+
|
| 907 |
+
Examples
|
| 908 |
+
--------
|
| 909 |
+
>>> import numpy as np
|
| 910 |
+
>>> from skimage.draw import rectangle_perimeter
|
| 911 |
+
>>> img = np.zeros((5, 6), dtype=np.uint8)
|
| 912 |
+
>>> start = (2, 3)
|
| 913 |
+
>>> end = (3, 4)
|
| 914 |
+
>>> rr, cc = rectangle_perimeter(start, end=end, shape=img.shape)
|
| 915 |
+
>>> img[rr, cc] = 1
|
| 916 |
+
>>> img
|
| 917 |
+
array([[0, 0, 0, 0, 0, 0],
|
| 918 |
+
[0, 0, 1, 1, 1, 1],
|
| 919 |
+
[0, 0, 1, 0, 0, 1],
|
| 920 |
+
[0, 0, 1, 0, 0, 1],
|
| 921 |
+
[0, 0, 1, 1, 1, 1]], dtype=uint8)
|
| 922 |
+
|
| 923 |
+
>>> img = np.zeros((5, 5), dtype=np.uint8)
|
| 924 |
+
>>> r, c = rectangle_perimeter(start, (10, 10), shape=img.shape, clip=True)
|
| 925 |
+
>>> img[r, c] = 1
|
| 926 |
+
>>> img
|
| 927 |
+
array([[0, 0, 0, 0, 0],
|
| 928 |
+
[0, 0, 1, 1, 1],
|
| 929 |
+
[0, 0, 1, 0, 1],
|
| 930 |
+
[0, 0, 1, 0, 1],
|
| 931 |
+
[0, 0, 1, 1, 1]], dtype=uint8)
|
| 932 |
+
|
| 933 |
+
"""
|
| 934 |
+
top_left, bottom_right = _rectangle_slice(start=start, end=end, extent=extent)
|
| 935 |
+
|
| 936 |
+
top_left -= 1
|
| 937 |
+
r = [top_left[0], top_left[0], bottom_right[0], bottom_right[0], top_left[0]]
|
| 938 |
+
c = [top_left[1], bottom_right[1], bottom_right[1], top_left[1], top_left[1]]
|
| 939 |
+
return polygon_perimeter(r, c, shape=shape, clip=clip)
|
| 940 |
+
|
| 941 |
+
|
| 942 |
+
def _rectangle_slice(start, end=None, extent=None):
|
| 943 |
+
"""Return the slice ``(top_left, bottom_right)`` of the rectangle.
|
| 944 |
+
|
| 945 |
+
Returns
|
| 946 |
+
-------
|
| 947 |
+
(top_left, bottom_right)
|
| 948 |
+
The slice you would need to select the region in the rectangle defined
|
| 949 |
+
by the parameters.
|
| 950 |
+
Select it like:
|
| 951 |
+
|
| 952 |
+
``rect[top_left[0]:bottom_right[0], top_left[1]:bottom_right[1]]``
|
| 953 |
+
"""
|
| 954 |
+
if end is None and extent is None:
|
| 955 |
+
raise ValueError("Either `end` or `extent` must be given.")
|
| 956 |
+
if end is not None and extent is not None:
|
| 957 |
+
raise ValueError("Cannot provide both `end` and `extent`.")
|
| 958 |
+
|
| 959 |
+
if extent is not None:
|
| 960 |
+
end = np.asarray(start) + np.asarray(extent)
|
| 961 |
+
top_left = np.minimum(start, end)
|
| 962 |
+
bottom_right = np.maximum(start, end)
|
| 963 |
+
|
| 964 |
+
top_left = np.round(top_left).astype(int)
|
| 965 |
+
bottom_right = np.round(bottom_right).astype(int)
|
| 966 |
+
|
| 967 |
+
if extent is None:
|
| 968 |
+
bottom_right += 1
|
| 969 |
+
|
| 970 |
+
return (top_left, bottom_right)
|
envs/kitoverlay/skimage/draw/draw3d.py
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
from scipy.special import elliprg
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
def ellipsoid(a, b, c, spacing=(1.0, 1.0, 1.0), levelset=False):
|
| 6 |
+
"""Generate ellipsoid for given semi-axis lengths.
|
| 7 |
+
|
| 8 |
+
The respective semi-axis lengths are given along three dimensions in
|
| 9 |
+
Cartesian coordinates. Each dimension may use a different grid spacing.
|
| 10 |
+
|
| 11 |
+
Parameters
|
| 12 |
+
----------
|
| 13 |
+
a : float
|
| 14 |
+
Length of semi-axis along x-axis.
|
| 15 |
+
b : float
|
| 16 |
+
Length of semi-axis along y-axis.
|
| 17 |
+
c : float
|
| 18 |
+
Length of semi-axis along z-axis.
|
| 19 |
+
spacing : 3-tuple of floats
|
| 20 |
+
Grid spacing in three spatial dimensions.
|
| 21 |
+
levelset : bool
|
| 22 |
+
If True, returns the level set for this ellipsoid (signed level
|
| 23 |
+
set about zero, with positive denoting interior) as np.float64.
|
| 24 |
+
False returns a binarized version of said level set.
|
| 25 |
+
|
| 26 |
+
Returns
|
| 27 |
+
-------
|
| 28 |
+
ellipsoid : (M, N, P) array
|
| 29 |
+
Ellipsoid centered in a correctly sized array for given `spacing`.
|
| 30 |
+
Boolean dtype unless `levelset=True`, in which case a float array is
|
| 31 |
+
returned with the level set above 0.0 representing the ellipsoid.
|
| 32 |
+
|
| 33 |
+
"""
|
| 34 |
+
if (a <= 0) or (b <= 0) or (c <= 0):
|
| 35 |
+
raise ValueError('Parameters a, b, and c must all be > 0')
|
| 36 |
+
|
| 37 |
+
offset = np.r_[1, 1, 1] * np.r_[spacing]
|
| 38 |
+
|
| 39 |
+
# Calculate limits, and ensure output volume is odd & symmetric
|
| 40 |
+
low = np.ceil(-np.r_[a, b, c] - offset)
|
| 41 |
+
high = np.floor(np.r_[a, b, c] + offset + 1)
|
| 42 |
+
|
| 43 |
+
for dim in range(3):
|
| 44 |
+
if (high[dim] - low[dim]) % 2 == 0:
|
| 45 |
+
low[dim] -= 1
|
| 46 |
+
num = np.arange(low[dim], high[dim], spacing[dim])
|
| 47 |
+
if 0 not in num:
|
| 48 |
+
low[dim] -= np.max(num[num < 0])
|
| 49 |
+
|
| 50 |
+
# Generate (anisotropic) spatial grid
|
| 51 |
+
x, y, z = np.mgrid[
|
| 52 |
+
low[0] : high[0] : spacing[0],
|
| 53 |
+
low[1] : high[1] : spacing[1],
|
| 54 |
+
low[2] : high[2] : spacing[2],
|
| 55 |
+
]
|
| 56 |
+
|
| 57 |
+
if not levelset:
|
| 58 |
+
arr = ((x / float(a)) ** 2 + (y / float(b)) ** 2 + (z / float(c)) ** 2) <= 1
|
| 59 |
+
else:
|
| 60 |
+
arr = ((x / float(a)) ** 2 + (y / float(b)) ** 2 + (z / float(c)) ** 2) - 1
|
| 61 |
+
|
| 62 |
+
return arr
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def ellipsoid_stats(a, b, c):
|
| 66 |
+
"""Calculate analytical volume and surface area of an ellipsoid.
|
| 67 |
+
|
| 68 |
+
The surface area of an ellipsoid is given by
|
| 69 |
+
|
| 70 |
+
.. math:: S=4\\pi b c R_G\\!\\left(1, \\frac{a^2}{b^2}, \\frac{a^2}{c^2}\\right)
|
| 71 |
+
|
| 72 |
+
where :math:`R_G` is Carlson's completely symmetric elliptic integral of
|
| 73 |
+
the second kind [1]_. The latter is implemented as
|
| 74 |
+
:py:func:`scipy.special.elliprg`.
|
| 75 |
+
|
| 76 |
+
Parameters
|
| 77 |
+
----------
|
| 78 |
+
a : float
|
| 79 |
+
Length of semi-axis along x-axis.
|
| 80 |
+
b : float
|
| 81 |
+
Length of semi-axis along y-axis.
|
| 82 |
+
c : float
|
| 83 |
+
Length of semi-axis along z-axis.
|
| 84 |
+
|
| 85 |
+
Returns
|
| 86 |
+
-------
|
| 87 |
+
vol : float
|
| 88 |
+
Calculated volume of ellipsoid.
|
| 89 |
+
surf : float
|
| 90 |
+
Calculated surface area of ellipsoid.
|
| 91 |
+
|
| 92 |
+
References
|
| 93 |
+
----------
|
| 94 |
+
.. [1] Paul Masson (2020). Surface Area of an Ellipsoid.
|
| 95 |
+
https://analyticphysics.com/Mathematical%20Methods/Surface%20Area%20of%20an%20Ellipsoid.htm
|
| 96 |
+
|
| 97 |
+
"""
|
| 98 |
+
if (a <= 0) or (b <= 0) or (c <= 0):
|
| 99 |
+
raise ValueError('Parameters a, b, and c must all be > 0')
|
| 100 |
+
|
| 101 |
+
# Volume
|
| 102 |
+
vol = 4 / 3.0 * np.pi * a * b * c
|
| 103 |
+
|
| 104 |
+
# Surface area
|
| 105 |
+
surf = 3 * vol * elliprg(1 / a**2, 1 / b**2, 1 / c**2)
|
| 106 |
+
|
| 107 |
+
return vol, surf
|
envs/kitoverlay/skimage/draw/draw_nd.py
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
def _round_safe(coords):
|
| 5 |
+
"""Round coords while ensuring successive values are less than 1 apart.
|
| 6 |
+
|
| 7 |
+
When rounding coordinates for `line_nd`, we want coordinates that are less
|
| 8 |
+
than 1 apart (always the case, by design) to remain less than one apart.
|
| 9 |
+
However, NumPy rounds values to the nearest *even* integer, so:
|
| 10 |
+
|
| 11 |
+
>>> np.round([0.5, 1.5, 2.5, 3.5, 4.5])
|
| 12 |
+
array([0., 2., 2., 4., 4.])
|
| 13 |
+
|
| 14 |
+
So, for our application, we detect whether the above case occurs, and use
|
| 15 |
+
``np.floor`` if so. It is sufficient to detect that the first coordinate
|
| 16 |
+
falls on 0.5 and that the second coordinate is 1.0 apart, since we assume
|
| 17 |
+
by construction that the inter-point distance is less than or equal to 1
|
| 18 |
+
and that all successive points are equidistant.
|
| 19 |
+
|
| 20 |
+
Parameters
|
| 21 |
+
----------
|
| 22 |
+
coords : 1D array of float
|
| 23 |
+
The coordinates array. We assume that all successive values are
|
| 24 |
+
equidistant (``np.all(np.diff(coords) = coords[1] - coords[0])``)
|
| 25 |
+
and that this distance is no more than 1
|
| 26 |
+
(``np.abs(coords[1] - coords[0]) <= 1``).
|
| 27 |
+
|
| 28 |
+
Returns
|
| 29 |
+
-------
|
| 30 |
+
rounded : 1D array of int
|
| 31 |
+
The array correctly rounded for an indexing operation, such that no
|
| 32 |
+
successive indices will be more than 1 apart.
|
| 33 |
+
|
| 34 |
+
Examples
|
| 35 |
+
--------
|
| 36 |
+
>>> coords0 = np.array([0.5, 1.25, 2., 2.75, 3.5])
|
| 37 |
+
>>> _round_safe(coords0)
|
| 38 |
+
array([0, 1, 2, 3, 4])
|
| 39 |
+
>>> coords1 = np.arange(0.5, 8, 1)
|
| 40 |
+
>>> coords1
|
| 41 |
+
array([0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5])
|
| 42 |
+
>>> _round_safe(coords1)
|
| 43 |
+
array([0, 1, 2, 3, 4, 5, 6, 7])
|
| 44 |
+
"""
|
| 45 |
+
if len(coords) > 1 and coords[0] % 1 == 0.5 and coords[1] - coords[0] == 1:
|
| 46 |
+
_round_function = np.floor
|
| 47 |
+
else:
|
| 48 |
+
_round_function = np.round
|
| 49 |
+
return _round_function(coords).astype(int)
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def line_nd(start, stop, *, endpoint=False, integer=True):
|
| 53 |
+
"""Draw a single-pixel thick line in n dimensions.
|
| 54 |
+
|
| 55 |
+
The line produced will be ndim-connected. That is, two subsequent
|
| 56 |
+
pixels in the line will be either direct or diagonal neighbors in
|
| 57 |
+
n dimensions.
|
| 58 |
+
|
| 59 |
+
Parameters
|
| 60 |
+
----------
|
| 61 |
+
start : array-like, shape (N,)
|
| 62 |
+
The start coordinates of the line.
|
| 63 |
+
stop : array-like, shape (N,)
|
| 64 |
+
The end coordinates of the line.
|
| 65 |
+
endpoint : bool, optional
|
| 66 |
+
Whether to include the endpoint in the returned line. Defaults
|
| 67 |
+
to False, which allows for easy drawing of multi-point paths.
|
| 68 |
+
integer : bool, optional
|
| 69 |
+
Whether to round the coordinates to integer. If True (default),
|
| 70 |
+
the returned coordinates can be used to directly index into an
|
| 71 |
+
array. `False` could be used for e.g. vector drawing.
|
| 72 |
+
|
| 73 |
+
Returns
|
| 74 |
+
-------
|
| 75 |
+
coords : tuple of arrays
|
| 76 |
+
The coordinates of points on the line.
|
| 77 |
+
|
| 78 |
+
Examples
|
| 79 |
+
--------
|
| 80 |
+
>>> lin = line_nd((1, 1), (5, 2.5), endpoint=False)
|
| 81 |
+
>>> lin
|
| 82 |
+
(array([1, 2, 3, 4]), array([1, 1, 2, 2]))
|
| 83 |
+
>>> im = np.zeros((6, 5), dtype=int)
|
| 84 |
+
>>> im[lin] = 1
|
| 85 |
+
>>> im
|
| 86 |
+
array([[0, 0, 0, 0, 0],
|
| 87 |
+
[0, 1, 0, 0, 0],
|
| 88 |
+
[0, 1, 0, 0, 0],
|
| 89 |
+
[0, 0, 1, 0, 0],
|
| 90 |
+
[0, 0, 1, 0, 0],
|
| 91 |
+
[0, 0, 0, 0, 0]])
|
| 92 |
+
>>> line_nd([2, 1, 1], [5, 5, 2.5], endpoint=True)
|
| 93 |
+
(array([2, 3, 4, 4, 5]), array([1, 2, 3, 4, 5]), array([1, 1, 2, 2, 2]))
|
| 94 |
+
"""
|
| 95 |
+
start = np.asarray(start)
|
| 96 |
+
stop = np.asarray(stop)
|
| 97 |
+
npoints = int(np.ceil(np.max(np.abs(stop - start))))
|
| 98 |
+
if endpoint:
|
| 99 |
+
npoints += 1
|
| 100 |
+
|
| 101 |
+
coords = np.linspace(start, stop, num=npoints, endpoint=endpoint).T
|
| 102 |
+
if integer:
|
| 103 |
+
for dim in range(len(start)):
|
| 104 |
+
coords[dim, :] = _round_safe(coords[dim, :])
|
| 105 |
+
|
| 106 |
+
coords = coords.astype(int)
|
| 107 |
+
|
| 108 |
+
return tuple(coords)
|
envs/kitoverlay/skimage/feature/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (433 Bytes). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/_basic_features.cpython-311.pyc
ADDED
|
Binary file (9.29 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/_canny.cpython-311.pyc
ADDED
|
Binary file (9.72 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/_fisher_vector.cpython-311.pyc
ADDED
|
Binary file (12.3 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/_orb_descriptor_positions.cpython-311.pyc
ADDED
|
Binary file (763 Bytes). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/blob.cpython-311.pyc
ADDED
|
Binary file (31.1 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/corner.cpython-311.pyc
ADDED
|
Binary file (51.9 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/haar.cpython-311.pyc
ADDED
|
Binary file (14.9 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/match.cpython-311.pyc
ADDED
|
Binary file (4.46 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/sift.cpython-311.pyc
ADDED
|
Binary file (36.9 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/texture.cpython-311.pyc
ADDED
|
Binary file (23.3 kB). View file
|
|
|
envs/kitoverlay/skimage/feature/__pycache__/util.cpython-311.pyc
ADDED
|
Binary file (10.4 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__init__.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Reading and saving of images and videos."""
|
| 2 |
+
|
| 3 |
+
import warnings
|
| 4 |
+
|
| 5 |
+
from .manage_plugins import *
|
| 6 |
+
from .manage_plugins import _hide_plugin_deprecation_warnings
|
| 7 |
+
from .sift import *
|
| 8 |
+
from .collection import *
|
| 9 |
+
|
| 10 |
+
from ._io import *
|
| 11 |
+
from ._image_stack import *
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
with _hide_plugin_deprecation_warnings():
|
| 15 |
+
reset_plugins()
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
__all__ = [
|
| 19 |
+
"concatenate_images",
|
| 20 |
+
"imread",
|
| 21 |
+
"imread_collection",
|
| 22 |
+
"imread_collection_wrapper",
|
| 23 |
+
"imsave",
|
| 24 |
+
"load_sift",
|
| 25 |
+
"load_surf",
|
| 26 |
+
"pop",
|
| 27 |
+
"push",
|
| 28 |
+
"ImageCollection",
|
| 29 |
+
"MultiImage",
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def __getattr__(name):
|
| 34 |
+
if name == "available_plugins":
|
| 35 |
+
warnings.warn(
|
| 36 |
+
"`available_plugins` is deprecated since version 0.25 and will "
|
| 37 |
+
"be removed in version 0.27. Instead, use `imageio` or other "
|
| 38 |
+
"I/O packages directly.",
|
| 39 |
+
category=FutureWarning,
|
| 40 |
+
stacklevel=2,
|
| 41 |
+
)
|
| 42 |
+
return globals()["_available_plugins"]
|
| 43 |
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
envs/kitoverlay/skimage/io/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (1.59 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/_image_stack.cpython-311.pyc
ADDED
|
Binary file (1.1 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/_io.cpython-311.pyc
ADDED
|
Binary file (11.4 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/collection.cpython-311.pyc
ADDED
|
Binary file (21.2 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/manage_plugins.cpython-311.pyc
ADDED
|
Binary file (16.4 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/sift.cpython-311.pyc
ADDED
|
Binary file (3.45 kB). View file
|
|
|
envs/kitoverlay/skimage/io/__pycache__/util.cpython-311.pyc
ADDED
|
Binary file (2.61 kB). View file
|
|
|
envs/kitoverlay/skimage/io/_image_stack.py
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import numpy as np
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
__all__ = ['image_stack', 'push', 'pop']
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
# Shared image queue
|
| 8 |
+
image_stack = []
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def push(img):
|
| 12 |
+
"""Push an image onto the shared image stack.
|
| 13 |
+
|
| 14 |
+
Parameters
|
| 15 |
+
----------
|
| 16 |
+
img : ndarray
|
| 17 |
+
Image to push.
|
| 18 |
+
|
| 19 |
+
"""
|
| 20 |
+
if not isinstance(img, np.ndarray):
|
| 21 |
+
raise ValueError("Can only push ndarrays to the image stack.")
|
| 22 |
+
|
| 23 |
+
image_stack.append(img)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def pop():
|
| 27 |
+
"""Pop an image from the shared image stack.
|
| 28 |
+
|
| 29 |
+
Returns
|
| 30 |
+
-------
|
| 31 |
+
img : ndarray
|
| 32 |
+
Image popped from the stack.
|
| 33 |
+
|
| 34 |
+
"""
|
| 35 |
+
return image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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import pathlib
|
| 2 |
+
import warnings
|
| 3 |
+
|
| 4 |
+
import numpy as np
|
| 5 |
+
|
| 6 |
+
from .._shared.utils import warn, deprecate_func, deprecate_parameter, DEPRECATED
|
| 7 |
+
from .._shared.version_requirements import require
|
| 8 |
+
from ..exposure import is_low_contrast
|
| 9 |
+
from ..color.colorconv import rgb2gray, rgba2rgb
|
| 10 |
+
from ..io.manage_plugins import call_plugin, _hide_plugin_deprecation_warnings
|
| 11 |
+
from .util import file_or_url_context
|
| 12 |
+
|
| 13 |
+
__all__ = [
|
| 14 |
+
'imread',
|
| 15 |
+
'imsave',
|
| 16 |
+
'imshow',
|
| 17 |
+
'show',
|
| 18 |
+
'imread_collection',
|
| 19 |
+
'imshow_collection',
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
_remove_plugin_param_template = (
|
| 24 |
+
"The plugin infrastructure in `skimage.io` and the parameter "
|
| 25 |
+
"`{deprecated_name}` are deprecated since version {deprecated_version} and "
|
| 26 |
+
"will be removed in {changed_version} (or later). To avoid this warning, "
|
| 27 |
+
"please do not use the parameter `{deprecated_name}`. Instead, use `imageio` "
|
| 28 |
+
"or other I/O packages directly. See also `{func_name}`."
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
@deprecate_parameter(
|
| 33 |
+
"plugin",
|
| 34 |
+
start_version="0.25",
|
| 35 |
+
stop_version="0.27",
|
| 36 |
+
template=_remove_plugin_param_template,
|
| 37 |
+
)
|
| 38 |
+
def imread(fname, as_gray=False, plugin=DEPRECATED, **plugin_args):
|
| 39 |
+
"""Load an image from file.
|
| 40 |
+
|
| 41 |
+
Parameters
|
| 42 |
+
----------
|
| 43 |
+
fname : str or pathlib.Path
|
| 44 |
+
Image file name, e.g. ``test.jpg`` or URL.
|
| 45 |
+
as_gray : bool, optional
|
| 46 |
+
If True, convert color images to gray-scale (64-bit floats).
|
| 47 |
+
Images that are already in gray-scale format are not converted.
|
| 48 |
+
|
| 49 |
+
Other Parameters
|
| 50 |
+
----------------
|
| 51 |
+
plugin_args : DEPRECATED
|
| 52 |
+
The plugin infrastructure is deprecated.
|
| 53 |
+
|
| 54 |
+
Returns
|
| 55 |
+
-------
|
| 56 |
+
img_array : ndarray
|
| 57 |
+
The different color bands/channels are stored in the
|
| 58 |
+
third dimension, such that a gray-image is MxN, an
|
| 59 |
+
RGB-image MxNx3 and an RGBA-image MxNx4.
|
| 60 |
+
|
| 61 |
+
"""
|
| 62 |
+
if plugin is DEPRECATED:
|
| 63 |
+
plugin = None
|
| 64 |
+
if plugin_args:
|
| 65 |
+
msg = (
|
| 66 |
+
"The plugin infrastructure in `skimage.io` is deprecated since "
|
| 67 |
+
"version 0.25 and will be removed in 0.27 (or later). To avoid "
|
| 68 |
+
"this warning, please do not pass additional keyword arguments "
|
| 69 |
+
"for plugins (`**plugin_args`). Instead, use `imageio` or other "
|
| 70 |
+
"I/O packages directly. See also `skimage.io.imread`."
|
| 71 |
+
)
|
| 72 |
+
warnings.warn(msg, category=FutureWarning, stacklevel=3)
|
| 73 |
+
|
| 74 |
+
if isinstance(fname, pathlib.Path):
|
| 75 |
+
fname = str(fname.resolve())
|
| 76 |
+
|
| 77 |
+
if plugin is None and hasattr(fname, 'lower'):
|
| 78 |
+
if fname.lower().endswith(('.tiff', '.tif')):
|
| 79 |
+
plugin = 'tifffile'
|
| 80 |
+
|
| 81 |
+
with file_or_url_context(fname) as fname, _hide_plugin_deprecation_warnings():
|
| 82 |
+
img = call_plugin('imread', fname, plugin=plugin, **plugin_args)
|
| 83 |
+
|
| 84 |
+
if not hasattr(img, 'ndim'):
|
| 85 |
+
return img
|
| 86 |
+
|
| 87 |
+
if img.ndim > 2:
|
| 88 |
+
if img.shape[-1] not in (3, 4) and img.shape[-3] in (3, 4):
|
| 89 |
+
img = np.swapaxes(img, -1, -3)
|
| 90 |
+
img = np.swapaxes(img, -2, -3)
|
| 91 |
+
|
| 92 |
+
if as_gray:
|
| 93 |
+
if img.shape[2] == 4:
|
| 94 |
+
img = rgba2rgb(img)
|
| 95 |
+
img = rgb2gray(img)
|
| 96 |
+
|
| 97 |
+
return img
|
| 98 |
+
|
| 99 |
+
|
| 100 |
+
@deprecate_parameter(
|
| 101 |
+
"plugin",
|
| 102 |
+
start_version="0.25",
|
| 103 |
+
stop_version="0.27",
|
| 104 |
+
template=_remove_plugin_param_template,
|
| 105 |
+
)
|
| 106 |
+
def imread_collection(
|
| 107 |
+
load_pattern, conserve_memory=True, plugin=DEPRECATED, **plugin_args
|
| 108 |
+
):
|
| 109 |
+
"""
|
| 110 |
+
Load a collection of images.
|
| 111 |
+
|
| 112 |
+
Parameters
|
| 113 |
+
----------
|
| 114 |
+
load_pattern : str or list
|
| 115 |
+
List of objects to load. These are usually filenames, but may
|
| 116 |
+
vary depending on the currently active plugin. See :class:`ImageCollection`
|
| 117 |
+
for the default behaviour of this parameter.
|
| 118 |
+
conserve_memory : bool, optional
|
| 119 |
+
If True, never keep more than one in memory at a specific
|
| 120 |
+
time. Otherwise, images will be cached once they are loaded.
|
| 121 |
+
|
| 122 |
+
Returns
|
| 123 |
+
-------
|
| 124 |
+
ic : :class:`ImageCollection`
|
| 125 |
+
Collection of images.
|
| 126 |
+
|
| 127 |
+
Other Parameters
|
| 128 |
+
----------------
|
| 129 |
+
plugin_args : DEPRECATED
|
| 130 |
+
The plugin infrastructure is deprecated.
|
| 131 |
+
|
| 132 |
+
"""
|
| 133 |
+
if plugin is DEPRECATED:
|
| 134 |
+
plugin = None
|
| 135 |
+
if plugin_args:
|
| 136 |
+
msg = (
|
| 137 |
+
"The plugin infrastructure in `skimage.io` is deprecated since "
|
| 138 |
+
"version 0.25 and will be removed in 0.27 (or later). To avoid "
|
| 139 |
+
"this warning, please do not pass additional keyword arguments "
|
| 140 |
+
"for plugins (`**plugin_args`). Instead, use `imageio` or other "
|
| 141 |
+
"I/O packages directly. See also `skimage.io.imread_collection`."
|
| 142 |
+
)
|
| 143 |
+
warnings.warn(msg, category=FutureWarning, stacklevel=3)
|
| 144 |
+
with _hide_plugin_deprecation_warnings():
|
| 145 |
+
return call_plugin(
|
| 146 |
+
'imread_collection',
|
| 147 |
+
load_pattern,
|
| 148 |
+
conserve_memory,
|
| 149 |
+
plugin=plugin,
|
| 150 |
+
**plugin_args,
|
| 151 |
+
)
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
@deprecate_parameter(
|
| 155 |
+
"plugin",
|
| 156 |
+
start_version="0.25",
|
| 157 |
+
stop_version="0.27",
|
| 158 |
+
template=_remove_plugin_param_template,
|
| 159 |
+
)
|
| 160 |
+
def imsave(fname, arr, plugin=DEPRECATED, *, check_contrast=True, **plugin_args):
|
| 161 |
+
"""Save an image to file.
|
| 162 |
+
|
| 163 |
+
Parameters
|
| 164 |
+
----------
|
| 165 |
+
fname : str or pathlib.Path
|
| 166 |
+
Target filename.
|
| 167 |
+
arr : ndarray of shape (M,N) or (M,N,3) or (M,N,4)
|
| 168 |
+
Image data.
|
| 169 |
+
check_contrast : bool, optional
|
| 170 |
+
Check for low contrast and print warning (default: True).
|
| 171 |
+
|
| 172 |
+
Other Parameters
|
| 173 |
+
----------------
|
| 174 |
+
plugin_args : DEPRECATED
|
| 175 |
+
The plugin infrastructure is deprecated.
|
| 176 |
+
"""
|
| 177 |
+
if plugin is DEPRECATED:
|
| 178 |
+
plugin = None
|
| 179 |
+
if plugin_args:
|
| 180 |
+
msg = (
|
| 181 |
+
"The plugin infrastructure in `skimage.io` is deprecated since "
|
| 182 |
+
"version 0.25 and will be removed in 0.27 (or later). To avoid "
|
| 183 |
+
"this warning, please do not pass additional keyword arguments "
|
| 184 |
+
"for plugins (`**plugin_args`). Instead, use `imageio` or other "
|
| 185 |
+
"I/O packages directly. See also `skimage.io.imsave`."
|
| 186 |
+
)
|
| 187 |
+
warnings.warn(msg, category=FutureWarning, stacklevel=3)
|
| 188 |
+
|
| 189 |
+
if isinstance(fname, pathlib.Path):
|
| 190 |
+
fname = str(fname.resolve())
|
| 191 |
+
if plugin is None and hasattr(fname, 'lower'):
|
| 192 |
+
if fname.lower().endswith(('.tiff', '.tif')):
|
| 193 |
+
plugin = 'tifffile'
|
| 194 |
+
if arr.dtype == bool:
|
| 195 |
+
warn(
|
| 196 |
+
f'{fname} is a boolean image: setting True to 255 and False to 0. '
|
| 197 |
+
'To silence this warning, please convert the image using '
|
| 198 |
+
'img_as_ubyte.',
|
| 199 |
+
stacklevel=3,
|
| 200 |
+
)
|
| 201 |
+
arr = arr.astype('uint8') * 255
|
| 202 |
+
if check_contrast and is_low_contrast(arr):
|
| 203 |
+
warn(f'{fname} is a low contrast image')
|
| 204 |
+
|
| 205 |
+
with _hide_plugin_deprecation_warnings():
|
| 206 |
+
return call_plugin('imsave', fname, arr, plugin=plugin, **plugin_args)
|
| 207 |
+
|
| 208 |
+
|
| 209 |
+
@deprecate_func(
|
| 210 |
+
deprecated_version="0.25",
|
| 211 |
+
removed_version="0.27",
|
| 212 |
+
hint="Please use `matplotlib`, `napari`, etc. to visualize images.",
|
| 213 |
+
)
|
| 214 |
+
def imshow(arr, plugin=None, **plugin_args):
|
| 215 |
+
"""Display an image.
|
| 216 |
+
|
| 217 |
+
Parameters
|
| 218 |
+
----------
|
| 219 |
+
arr : ndarray or str
|
| 220 |
+
Image data or name of image file.
|
| 221 |
+
plugin : str
|
| 222 |
+
Name of plugin to use. By default, the different plugins are
|
| 223 |
+
tried (starting with imageio) until a suitable candidate is found.
|
| 224 |
+
|
| 225 |
+
Other Parameters
|
| 226 |
+
----------------
|
| 227 |
+
plugin_args : keywords
|
| 228 |
+
Passed to the given plugin.
|
| 229 |
+
|
| 230 |
+
"""
|
| 231 |
+
if isinstance(arr, str):
|
| 232 |
+
arr = call_plugin('imread', arr, plugin=plugin)
|
| 233 |
+
with _hide_plugin_deprecation_warnings():
|
| 234 |
+
return call_plugin('imshow', arr, plugin=plugin, **plugin_args)
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
@deprecate_func(
|
| 238 |
+
deprecated_version="0.25",
|
| 239 |
+
removed_version="0.27",
|
| 240 |
+
hint="Please use `matplotlib`, `napari`, etc. to visualize images.",
|
| 241 |
+
)
|
| 242 |
+
def imshow_collection(ic, plugin=None, **plugin_args):
|
| 243 |
+
"""Display a collection of images.
|
| 244 |
+
|
| 245 |
+
Parameters
|
| 246 |
+
----------
|
| 247 |
+
ic : :class:`ImageCollection`
|
| 248 |
+
Collection to display.
|
| 249 |
+
|
| 250 |
+
Other Parameters
|
| 251 |
+
----------------
|
| 252 |
+
plugin_args : keywords
|
| 253 |
+
Passed to the given plugin.
|
| 254 |
+
|
| 255 |
+
"""
|
| 256 |
+
with _hide_plugin_deprecation_warnings():
|
| 257 |
+
return call_plugin('imshow_collection', ic, plugin=plugin, **plugin_args)
|
| 258 |
+
|
| 259 |
+
|
| 260 |
+
@require("matplotlib", ">=3.3")
|
| 261 |
+
@deprecate_func(
|
| 262 |
+
deprecated_version="0.25",
|
| 263 |
+
removed_version="0.27",
|
| 264 |
+
hint="Please use `matplotlib`, `napari`, etc. to visualize images.",
|
| 265 |
+
)
|
| 266 |
+
def show():
|
| 267 |
+
"""Display pending images.
|
| 268 |
+
|
| 269 |
+
Launch the event loop of the current GUI plugin, and display all
|
| 270 |
+
pending images, queued via `imshow`. This is required when using
|
| 271 |
+
`imshow` from non-interactive scripts.
|
| 272 |
+
|
| 273 |
+
A call to `show` will block execution of code until all windows
|
| 274 |
+
have been closed.
|
| 275 |
+
|
| 276 |
+
Examples
|
| 277 |
+
--------
|
| 278 |
+
>>> import skimage.io as io
|
| 279 |
+
>>> rng = np.random.default_rng()
|
| 280 |
+
>>> for i in range(4):
|
| 281 |
+
... ax_im = io.imshow(rng.random((50, 50))) # doctest: +SKIP
|
| 282 |
+
>>> io.show() # doctest: +SKIP
|
| 283 |
+
|
| 284 |
+
"""
|
| 285 |
+
with _hide_plugin_deprecation_warnings():
|
| 286 |
+
return call_plugin('_app_show')
|
envs/kitoverlay/skimage/io/_plugins/__init__.py
ADDED
|
File without changes
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/__init__.cpython-311.pyc
ADDED
|
Binary file (176 Bytes). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/fits_plugin.cpython-311.pyc
ADDED
|
Binary file (5.47 kB). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/gdal_plugin.cpython-311.pyc
ADDED
|
Binary file (755 Bytes). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/imageio_plugin.cpython-311.pyc
ADDED
|
Binary file (817 Bytes). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/imread_plugin.cpython-311.pyc
ADDED
|
Binary file (1.45 kB). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/matplotlib_plugin.cpython-311.pyc
ADDED
|
Binary file (9.04 kB). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/pil_plugin.cpython-311.pyc
ADDED
|
Binary file (10.5 kB). View file
|
|
|
envs/kitoverlay/skimage/io/_plugins/__pycache__/simpleitk_plugin.cpython-311.pyc
ADDED
|
Binary file (1.08 kB). View file
|
|
|