import os import imghdr from collections import namedtuple import numpy as np from skimage import io from skimage import img_as_ubyte from skimage.transform import resize from skimage.color import color_dict from skimage._shared import six # Convert colors from `skimage.color` to uint8 and allow access through # dict or a named tuple. color_dict = dict((name, tuple(int(255 * c + 0.5) for c in rgb)) for name, rgb in six.iteritems(color_dict)) colors = namedtuple('colors', color_dict.keys())(**color_dict) def open(path): """Return Picture object from the given image path.""" return Picture(path=os.path.abspath(path)) def _verify_picture_index(index): """Raise error if picture index is not a 2D index/slice.""" if not (isinstance(index, tuple) and len(index) == 2): raise IndexError("Expected 2D index but got {!r}".format(index)) if all(isinstance(i, int) for i in index): return index
from skimage import img_as_float from skimage._shared import six from skimage._shared.six.moves import zip from .colorconv import rgb2gray, gray2rgb from . import rgb_colors __all__ = ['color_dict', 'label2rgb', 'DEFAULT_COLORS'] DEFAULT_COLORS = ('red', 'blue', 'yellow', 'magenta', 'green', 'indigo', 'darkorange', 'cyan', 'pink', 'yellowgreen') color_dict = dict((k, v) for k, v in six.iteritems(rgb_colors.__dict__) if isinstance(v, tuple)) def _rgb_vector(color): """Return RGB color as (1, 3) array. This RGB array gets multiplied by masked regions of an RGB image, which are partially flattened by masking (i.e. dimensions 2D + RGB -> 1D + RGB). Parameters ---------- color : str or array Color name in `color_dict` or RGB float values between [0, 1]. """ if isinstance(color, six.string_types):
import os import imghdr from collections import namedtuple import numpy as np from skimage import io from skimage import img_as_ubyte from skimage.transform import resize from skimage.color import color_dict from skimage._shared import six # Convert colors from `skimage.color` to uint8 and allow access through # dict or a named tuple. color_dict = dict((name, tuple(int(255 * c + 0.5) for c in rgb)) for name, rgb in six.iteritems(color_dict)) colors = namedtuple("colors", color_dict.keys())(**color_dict) def open(path): """Return Picture object from the given image path.""" return Picture(path=os.path.abspath(path)) def _verify_picture_index(index): """Raise error if picture index is not a 2D index/slice.""" if not (isinstance(index, tuple) and len(index) == 2): raise IndexError("Expected 2D index but got {!r}".format(index)) if all(isinstance(i, int) for i in index): return index