示例#1
0
def cached_tifffile_baseseries(format: AbstractFormat) -> TiffPageSeries:
    tf = cached_tifffile(format)

    def get_baseseries(tf: TiffFile) -> TiffPageSeries:
        idx = np.argmax([np.prod(s.shape) for s in tf.series])
        return tf.series[idx]

    return format.get_cached('_tf_baseseries', get_baseseries, tf)
示例#2
0
def cached_palette_converted_pillow_file(
        format: AbstractFormat, pil_format_slug: Optional[str]) -> PILImage:
    """Palette converted pillow image"""
    def _open_palette_converted(_format, _pil_format_slug):
        image = cached_pillow_file(format, pil_format_slug)
        palette = getattr(image, "palette", None)
        if palette:
            image = image.convert(palette.mode)
        return image

    return format.get_cached('_pil_palette_converted', _open_palette_converted,
                             format.path, pil_format_slug)
示例#3
0
def cached_pillow_file(format: AbstractFormat,
                       pil_format_slug: Optional[str]) -> PILImage:
    slugs = [pil_format_slug] if pil_format_slug else None
    return format.get_cached('_pil', PILImage.open, format.path, formats=slugs)
示例#4
0
def cached_omedict(format: AbstractFormat) -> dict:
    tf = cached_tifffile(format)
    return format.get_cached('_omedict', xml2dict, tf.pages[0].description)
示例#5
0
def cached_omexml(format: AbstractFormat) -> OMEXML:
    tf = cached_tifffile(format)
    return format.get_cached('_omexml', parse_ome, tf.pages[0].description)
示例#6
0
def cached_tifffile_baseline(format: AbstractFormat) -> TiffPage:
    tf = cached_tifffile(format)
    return format.get_cached('_tf_baseline', tf.pages.__getitem__, 0)
示例#7
0
def cached_vips_file(format: AbstractFormat) -> VIPSImage:
    """Get cached vips object for the image format."""
    return format.get_cached('_vips', VIPSImage.new_from_file, str(format.path))