libvips / pyvips

python binding for libvips using cffi
MIT License
652 stars 50 forks source link

generate tiff file size question #410

Closed chengdonglin closed 1 year ago

chengdonglin commented 1 year ago

I using next code to generate tiff file, the tiles total size is 90M, width = 69632, height = 32768, finally tiff file size is 1.3G,

  1. openSlide open it find 11 level, it correct? can I reduce the level by args or other methods to reduce the size?
  2. qupath open the filee, loss the pixel info, can I set the pixel width or puxel height ?
import pyvips

tiles_across = 34
tiles_down = 16

tiles = [pyvips.Image.new_from_file(f"D:\\test\\ttt\\{x}_{y}.jpg", access="sequential")
         for y in range(tiles_down) for x in range(tiles_across)]
im = pyvips.Image.arrayjoin(tiles, across=tiles_across)

im.write_to_file("ljh.tiff", compression="jpeg", Q=90, tile=True, pyramid=True)
jcupitt commented 1 year ago

Hello @chengdonglin,

  1. Try Q=85. At Q 90, libvips will encode without chroma subsampling, which needs a lot more space.
  2. I think you need to put some XML in IMAGEDESCRIPTION with the OME-TIFF pixel info. See: https://forum.image.sc/t/writing-qupath-bio-formats-compatible-pyramidal-image-with-libvips/51223/14?u=jcupitt
chengdonglin commented 1 year ago

thanks! @jcupitt ,

  1. Try Q=85. At Q 90, libvips will encode without chroma subsampling, which needs a lot more space.
  2. I think you need to put some XML in IMAGEDESCRIPTION with the OME-TIFF pixel info. See: https://forum.image.sc/t/writing-qupath-bio-formats-compatible-pyramidal-image-with-libvips/51223/14?u=jcupitt
  1. Yes, set Q= 85, total size from 1.3G to 425M
  2. I should generated generic-tiff, because I shoud use openSlide open it, If use OME-TIFF description, openslide not support, I use qupath open, loss pixel width and pixel height, see image image
jcupitt commented 1 year ago

Ah OK. I would guess qupath is still looking for some XML in IMAGEDESCRIPTiON.

You could also try setting the TIFF DPI, eg.;

im.write_to_file("ljh.tiff", compression="jpeg", Q=90, tile=True, pyramid=True, xres=100, yres=100)

Where the units are pixels per millimetre.

chengdonglin commented 1 year ago

@jcupitt I publish the code on my server, cpu is 4, memory 32G, But I find it is slowly generate tiff and dzi files compare the win,It normal? image

jcupitt commented 1 year ago

It should be maybe 20% faster than win, depending on various factors.

Perhaps your server does not have libjpeg-turbo installed?

chengdonglin commented 1 year ago

libjpeg-turbo

yes,I not install libjpeg-turbo, I use the Docker to build the serve。

chengdonglin commented 1 year ago

It should be maybe 20% faster than win, depending on various factors.

Perhaps your server does not have libjpeg-turbo installed?

@jcupitt , have you install it by Dockerfile, I have find there is no name libjpeg-turbo by apt-get, then I install it by apt-get libturbojpeg-dev, it slowly too, next my part dockerfile:


FROM python:3.9.7-slim

# Keeps Python from generating .pyc files in the container
ENV PYTHONDONTWRITEBYTECODE=1
# Turns off buffering for easier container logging
ENV PYTHONUNBUFFERED=1

RUN apt update \
    && apt install -y libmariadb-dev \
        gcc\
        python3-dev \
        libcogl-pango-dev \
        libcairo2-dev \
        libtool \
        linux-headers-amd64 \
        musl-dev \
        libffi-dev \
        libssl-dev \
        libjpeg-dev \
        zlib1g-dev \
        libcurl4
chengdonglin commented 1 year ago

image It means success install libjpeg-turbo?

jcupitt commented 1 year ago

Yes, that looks OK.

There are some sample dockerfiles here:

https://github.com/jcupitt/docker-builds

chengdonglin commented 1 year ago

Yes, that looks OK.

There are some sample dockerfiles here:

https://github.com/jcupitt/docker-builds

after install libturbojpeg-dev, regenerate the tiff and dzi, It cost 297978ms and 663214ms,I will use https://github.com/jcupitt/docker-builds/blob/master/pyvips-python3.7-alpine/Dockerfile to rebuild and retry generate

chengdonglin commented 1 year ago

https://github.com/jcupitt/docker-builds/blob/master/pyvips-python3.7-alpine/Dockerfile

https://github.com/jcupitt/docker-builds/blob/master/pyvips-python3.7-alpine/Dockerfile I run this dockerfile, return error image