6

我有一个图像,6130x5548 pixels我想重新缩放它,以便最长的边是32768 pixels(​​然后做一个具有 7 个缩放级别的瓷砖金字塔)。我不明白vips resize是这样的明显方式,因此我尝试了下面的行

vips resize image_in.tif img_rescaled.tif 5.345513866231648

数字5.34551只是比例32768/6130,我的比例因子x axis。如果我想以像素为单位指定返回图像的确切尺寸,我该怎么做?

我尝试vips thumbnail用于此目的,我不知道这是否推荐,但它确实有效。

vips thumbnail image_in.tif img_rescaled.tif 32768

请问这样的可以吗?

此外,这两种方法在 MB 大小方面给出了完全不同的输出。虽然vips thumbnail产生一个with tifsize调用返回一个with size 。2.8Gbvips resizetif1.8Gb

两幅图像(显然)具有相同的尺寸32768x29657 pixels、相同的分辨率72dpi但不同bit depthtiffrom vips thumbnail具有24 bit depth而一个 from vips resize 16 bit depth。原图有bit depth=16

此外,我了解所使用的算法vips translate对生成的文件大小起着重要作用。我可以在使用vips thumbnail和/或bit depth请时设置算法吗?

4

1 回答 1

6

resize only takes a scale factor, so you need to calculate it. You can use something like:

width=$(vipsheader -f width somefile.tif)
height=$(vipsheader -f height somefile.tif)
size=$((width > height ? width : height))
factor=$(bc <<< "scale=10; 32768 / $size")
vips resize somefile.tif huge.tif $factor

I'd go to 8-bit before upscaling, since you only need 8 bits for the display. You can use:

vips colourspace thing.tif other.tif srgb

To make an 8-bit srgb version.

bash gets so ugly when you start doing stuff like this that I'd be tempted to switch to pyvips.

import pyvips

image = pyvips.Image.new_from_file('somefile.tif', access='sequential')
image = image.colourspace('srgb')
image = image.resize(32768 / max(image.width, image.height))
image.dzsave('mypyramid')

It has the extra advantage that it won't use any temporary files. pyvips builds pipelines of image processing operations, so that program will stream pixels from your input, upsize them, and write the pyramid all at the same time, and all in parallel. It won't use much memory and it'll be quick.

于 2019-05-24T14:54:57.867 回答