简体   繁体   English

如何从 tiff 文件中获取 jpeg 图像?

[英]How to get jpeg image from a tiff file?

I have a large tiff file contains multiple JPEG image.When I want to get the image from tiff,it will take a lots of time because of decompression from jpeg to rgb.我有一个包含多个 JPEG 图像的大型 tiff 文件。当我想从 tiff 获取图像时,由于从 jpeg 到 rgb 的解压缩,这将需要很多时间。 If i want to get the jpeg image without decompression, how should I do with the tiff.如果我想在不解压缩的情况下获取 jpeg 图像,我应该如何处理 tiff。 Can I parse the TIFF file to get some image data and directly generate a JPEG image?我可以解析 TIFF 文件以获取一些图像数据并直接生成 JPEG 图像吗?

This is the final implementation method with opentile:这是opentile的最终实现方法:

 from opentile import OpenTile import os import traceback os.environ.setdefault('TURBOJPEG', 'C:/lib/') try: tiler = OpenTile.open('name.svs') except: traceback.print_exc() tile_leve=tiler.levels print("{}".format(len(tile_leve))) s=tiler.get_level(0) print(s.compression.split('.')[1]) print(s.photometric_interpretation) print(s.samples_per_pixel) print(s.pixel_spacing) tile_size=str(s.tiled_size).split("x") print(s.tile_size) print(tile_size) y={} for i in range(int(tile_size[0])): for j in range(int(tile_size[1])): tile = tiler.get_tile(0,0,0, (i, j)) y[(i,j)]=tile with open("im/im_{}_{}.jpg".format(i,j),"wb") as f: f.write(tile)

Tifffile is also feasible. Tifffile 也是可行的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM