示例#1
0
def show_channels(path: Path = Depends(imagepath_parameter)):
    """
    Get image channel info
    """
    original = path.get_original()
    check_representation_existence(original)
    return response_list(ChannelsInfo.from_image(original))
示例#2
0
def show_associated(path: Path = Depends(imagepath_parameter)):
    """
    Get associated file info
    """
    original = path.get_original()
    check_representation_existence(original)
    return response_list(AssociatedInfo.from_image(original))
示例#3
0
def show_channels_histogram_bounds(
    path: Path = Depends(imagepath_parameter),
    channels: Optional[List[conint(ge=0)]] = Query(
        None, description="Only return histograms for these channels"
    ),
):
    """
    Get histogram bounds per channel where all planes (Z,T) are merged.
    """
    in_image = path.get_spatial()
    check_representation_existence(in_image)

    channels = ensure_list(channels)
    channels = get_channel_indexes(in_image, channels)

    hist_info = []
    htype = in_image.histogram_type()
    hist_filter = operator.itemgetter(*channels)
    channels_bounds = hist_filter(in_image.channels_bounds())
    if len(channels) == 1:
        channels_bounds = [channels_bounds]

    for channel, bounds in zip(channels, channels_bounds):
        mini, maxi = bounds
        hist_info.append(
            ChannelHistogramInfo(
                channel=channel, type=htype,
                color=in_image.channels[channel].hex_color,
                minimum=mini, maximum=maxi
            )
        )

    return response_list(hist_info)
示例#4
0
def show_plane_histogram(
    z_slices: conint(ge=0),
    timepoints: conint(ge=0),
    path: Path = Depends(imagepath_parameter),
    channels: Optional[List[conint(ge=0)]] = Query(
        None, description="Only return histograms for these channels"
    ),
):
    """
    Get histogram per plane.
    """
    in_image = path.get_spatial()
    check_representation_existence(in_image)

    channels = ensure_list(channels)
    z_slices = ensure_list(z_slices)
    timepoints = ensure_list(timepoints)

    channels = get_channel_indexes(in_image, channels)
    z_slices = get_zslice_indexes(in_image, z_slices)
    timepoints = get_timepoint_indexes(in_image, timepoints)

    hist_info = []
    htype = in_image.histogram_type()
    for c, z, t in itertools.product(channels, z_slices, timepoints):
        mini, maxi = in_image.plane_bounds(c, z, t)
        hist_info.append(
            PlaneHistogramInfo(
                channel=c, z_slice=z, timepoint=t, type=htype,
                color=in_image.channels[c].hex_color,
                minimum=mini, maximum=maxi
            )
        )

    return response_list(hist_info)
示例#5
0
def list_representations(path: Path = Depends(imagepath_parameter)):
    """
    Get all image representation info
    """
    return response_list([
        RepresentationInfo.from_path(rpr)
        for rpr in path.get_representations()
    ])
示例#6
0
def show_metadata(path: Path = Depends(imagepath_parameter)):
    """
    Get image metadata
    """
    original = path.get_original()
    check_representation_existence(original)

    store = original.raw_metadata
    return response_list([Metadata.from_metadata(md) for md in store.values()])
示例#7
0
def show_metadata_annotations(path: Path = Depends(imagepath_parameter)):
    """
    Get image annotation metadata
    """
    original = path.get_original()
    check_representation_existence(original)
    return response_list([
        MetadataAnnotation.from_metadata_annotation(a)
        for a in original.annotations
    ])
示例#8
0
def list_colormaps(with_inverted: bool = Query(
    False, description="Also list inverted colormaps")):
    """
    List all colormaps
    """
    colormaps = [
        _serialize_colormap(cmap) for cmap in COLORMAPS.values()
        if with_inverted or not cmap.inverted
    ]
    return response_list(colormaps)
示例#9
0
def show_plane_histogram(
    z_slices: conint(ge=0),
    timepoints: conint(ge=0),
    path: Path = Depends(imagepath_parameter),
    hist_config: HistogramConfig = Depends(),
    channels: Optional[List[conint(ge=0)]] = Query(
        None, description="Only return histograms for these channels"
    ),
):
    """
    Get histogram per plane.
    """
    in_image = path.get_spatial()
    check_representation_existence(in_image)

    channels = ensure_list(channels)
    z_slices = ensure_list(z_slices)
    timepoints = ensure_list(timepoints)

    channels = get_channel_indexes(in_image, channels)
    z_slices = get_zslice_indexes(in_image, z_slices)
    timepoints = get_timepoint_indexes(in_image, timepoints)

    histograms = []
    n_bins = parse_n_bins(hist_config.n_bins, len(in_image.value_range))
    htype = in_image.histogram_type()
    for c, z, t in itertools.product(channels, z_slices, timepoints):
        histograms.append(
            PlaneHistogram(
                channel=c, z_slice=z, timepoint=t, type=htype,
                color=in_image.channels[c].hex_color,
                **histogram_formatter(
                    in_image.plane_histogram(c, z, t),
                    in_image.plane_bounds(c, z, t),
                    n_bins, hist_config.full_range
                )
            )
        )

    return response_list(histograms)
示例#10
0
def show_channels_histogram(
    path: Path = Depends(imagepath_parameter),
    hist_config: HistogramConfig = Depends(),
    channels: Optional[List[conint(ge=0)]] = Query(
        None, description="Only return histograms for these channels"
    ),
):
    """
    Get histograms per channel where all planes (Z,T) are merged.
    """
    in_image = path.get_spatial()
    check_representation_existence(in_image)

    channels = ensure_list(channels)
    channels = get_channel_indexes(in_image, channels)

    histograms = []
    n_bins = parse_n_bins(hist_config.n_bins, len(in_image.value_range))
    htype = in_image.histogram_type()

    # hist_filter = operator.itemgetter(*channels)
    # channels_bounds = hist_filter(in_image.channels_bounds())
    # channels_histograms = hist_filter(in_image.channel_histogram()) TODO
    for channel in channels:
        histograms.append(
            ChannelHistogram(
                channel=channel, type=htype,
                color=in_image.channels[channel].hex_color,
                **histogram_formatter(
                    in_image.channel_histogram(channel),
                    in_image.channel_bounds(channel),
                    n_bins, hist_config.full_range
                )
            )
        )

    return response_list(histograms)
示例#11
0
def list_filters():
    """
    List all filters
    """
    filters = [_serialize_filter(imgfilter) for imgfilter in FILTERS.values()]
    return response_list(filters)
示例#12
0
def list_formats():
    """
    List all formats
    """
    formats = [_serialize_format(format) for format in FORMATS.values()]
    return response_list(formats)