How to get jpeg image from a tiff file?

Viewed 107

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. If i want to get the jpeg image without decompression, how should I do with the tiff. Can I parse the TIFF file to get some image data and directly generate a JPEG image?

1 Answers

This is the final implementation method with 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.

Related