为什么 vipsX 在裁剪后将 16 位(浮点)/波段 TIFF 图像转换为 8 位(字节)/波段 TIFF?

Why is vipsCC converting 16bits(float)/band TIFF image to 8bits(byte)/band TIFF after cropping?

我尝试裁剪 16 位(浮点)/波段的 TIFF 图像,但生成的图像是 8 位(字节)/波段。有什么我应该做的吗?

from vipsCC import *

input_file_path = 'input.tiff'
output_file_path = 'output.tiff'

bands = 4
bg = VImage.VImage.black(width,height,bands)
im = VImage.VImage(input_file_path) # Giving 16bits(float)/band TIFF image...

im_frag = im.extract_area(dx,dy,width,height)
bg.insertplace(im_frag,0,0)
bg.write(output_file_path) # Results 8bits(byte)/band ...

a.insertplace(b) 执行就地插入操作。它直接修改a,将b粘贴进去。如果 b 不是正确的类型,它会被转换为匹配 a.

你可能想要普通的 insert。尝试:

import sys
from vipsCC import *

im = VImage.VImage(sys.argv[1]) 
im_frag = im.extract_area(10, 10, 200, 200)

bg = VImage.VImage.black(1000, 1000, 1)
bg = bg.insert(im_frag, 100, 100)
bg.write(sys.argv[2])

a.insert(b) 制作一个新图像,它足够大以容纳所有 ab,因此根据需要添加波段,转换格式,等等.它也比 insertplace 快很多,并且可以处理任何大小的图像。

您还在使用旧的 vips7 Python 界面。现在有一个新的 vips8 更好一点:

http://www.vips.ecs.soton.ac.uk/supported/current/doc/html/libvips/using-from-python.html

大约一年前 post 有一篇博客介绍了新界面:

http://libvips.blogspot.co.uk/2014/10/image-annotation-with-pyvips8.html