Exemplo n.º 1
0
 def resolve_color(channel):
     color = colors.get(channel, None)
     if color is None or isinstance(color, str):
         return cvcolor.map(color)
     else:
         if len(color) != 3 or np.array(color).min() < 0 or np.array(color).max() > 1:
             raise ValueError(
                 'Color for channel "{}" should be 3 item list-like with values in [0, 1] not "{}"'
                 .format(channel, color)
             )
         return color
Exemplo n.º 2
0
def _load_montage_data():
    from skimage.transform import resize

    path = cytokit_io.get_montage_image_path(cfg.region_index,
                                             cfg.montage_name)
    path = osp.join(cfg.exp_data_dir, path)
    img, meta = cytokit_io.read_tile(path, return_metadata=True)

    # Select cycle and z plane
    img = img[cfg.montage_cycle, cfg.montage_z]
    labels = list(meta['structured_labels'][cfg.montage_cycle, cfg.montage_z])

    ############################
    # Montage Display Properties
    ############################

    channel_filter = cfg.montage_channel_names
    if channel_filter is not None:
        # Validate that all provided channel names exist
        for c in channel_filter:
            if c not in labels:
                raise ValueError(
                    'Configured montage channel name "{}" does not exist in montage image '
                    '(available channels = {}); Fix or remove this channel name from the (comma-separated) environment '
                    'variable "{}" and run again'.format(
                        c, labels, ENV_APP_MONTAGE_CHANNEL_NAMES))

        # Subset both the image and the labels to the channels provided (make sure order of arrays matches
        # order of given channels -- which then matches to other montage options like color/range)
        img = img[np.array([labels.index(c) for c in channel_filter])]
        labels = channel_filter

    ranges = cfg.montage_channel_ranges
    colors = cfg.montage_channel_colors
    # Map string color names to rgb multipliers
    if colors is not None:
        colors = [color.map(c) for c in colors]

    ####################
    # Montage Resampling
    ####################

    logger.info('Loaded montage image with shape = %s, dtype = %s', img.shape,
                img.dtype)
    if img.dtype != np.uint8 and img.dtype != np.uint16:
        raise ValueError(
            'Only 8 or 16 bit images are supported (image type = {})'.format(
                img.dtype))

    # Resize the montage image to something much smaller (resize function expects channels last
    # and preserves them if not specified in target shape)
    img = np.moveaxis(img, 0, -1)
    img = resize(img,
                 cfg.montage_target_shape,
                 order=0,
                 mode='constant',
                 anti_aliasing=False,
                 preserve_range=True).astype(img.dtype)
    img = np.moveaxis(img, -1, 0)

    # Image is now (C, H, W)
    db.put('images', 'montage', img)
    db.put('channels', 'montage', labels)
    db.put('colors', 'montage', colors)
    db.put('ranges', 'montage', ranges)
Exemplo n.º 3
0
def handle_display_settings_update(channel_ranges, channel_colors):
    data.db.put('app', 'tile_channel_ranges', channel_ranges)
    data.db.put('app', 'tile_channel_colors', channel_colors)
    ac['processor']['tile'].ranges = channel_ranges
    ac['processor']['tile'].colors = [color.map(c) for c in channel_colors]