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)
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)
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)
def cached_omedict(format: AbstractFormat) -> dict: tf = cached_tifffile(format) return format.get_cached('_omedict', xml2dict, tf.pages[0].description)
def cached_omexml(format: AbstractFormat) -> OMEXML: tf = cached_tifffile(format) return format.get_cached('_omexml', parse_ome, tf.pages[0].description)
def cached_tifffile_baseline(format: AbstractFormat) -> TiffPage: tf = cached_tifffile(format) return format.get_cached('_tf_baseline', tf.pages.__getitem__, 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))