def mask_on_image(mask, image): from skimage.color import label2rgb from skimage.color import color_dict, colorlabel from skimage.segmentation import mark_boundaries default_colors = [ "red", "blue", "yellow", "magenta", "green", "indigo", "darkorange", "cyan", "pink", "yellowgreen", ] mask = mask.squeeze().astype(int) image = hi.image_as_uint8(image) / 255.0 labels = [l for l in np.unique(mask) if l < len(color_dict)] colors = default_colors + list(color_dict.keys())[len(default_colors) :] colors = np.array(colors)[labels] image_label_overlay = label2rgb( mask, image=f2l(image).squeeze().clip(0, 1), colors=colors, bg_label=0, bg_color=None, kind="overlay" ) return mark_boundaries(image_label_overlay, mask)
def mask_on_image(mask, image): from skimage.color import label2rgb from skimage.color import color_dict, colorlabel from skimage.segmentation import mark_boundaries default_colors = ['red', 'blue', 'yellow', 'magenta', 'green', 'indigo', 'darkorange', 'cyan', 'pink', 'yellowgreen'] mask = mask.squeeze().astype(int) image = hi.image_as_uint8(image) / 255. labels = [l for l in np.unique(mask) if l < len(color_dict)] colors = (default_colors + list(color_dict.keys())[len(default_colors):]) colors = np.array(colors)[labels] image_label_overlay = label2rgb(mask, image=f2l(image).squeeze().clip(0,1), colors=colors, bg_label=0, bg_color=None, kind='overlay') return mark_boundaries(image_label_overlay, mask)
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 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
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