【发布时间】:2019-12-18 16:16:49
【问题描述】:
我正在尝试使用 pyvips 将多个图像连接在一起,但在此过程中图像的宽度增加了一倍以上,我似乎无法弄清楚原因
这是我的代码的关键部分:
files = ['small_images\\'+filename for filename in os.listdir('small_images')]
files = natsorted(files)
images = [pyvips.Image.new_from_file(filename, access="sequential") for filename in files]
[print(f'width: {image.width}, height: {image.height}') for image in images]
raster = pyvips.Image.arrayjoin(images,across=len(images))
print(f'raster width: {raster.width}, raster height: {raster.height}')
raster.write_to_file(f'rasters.png')
5 个文件的预期输出应该是:
width: 115, height: 1449
width: 44, height: 1449
width: 226, height: 1449
width: 74, height: 1449
width: 35, height: 1449
raster width: 494, raster height: 1449
但我的实际输出是:
width: 115, height: 1449
width: 44, height: 1449
width: 226, height: 1449
width: 74, height: 1449
width: 35, height: 1449
raster width: 1130, raster height: 1449
图片:https://imgur.com/a/IDuRtIK
这是什么原因造成的?
【问题讨论】:
-
请出示您的图片 - 可能有不同的高度吗?
-
如果您不在字符串中使用
{filename}等变量,则不必在字符串中使用前缀f -
@MarkSetchell 是的,它们的高度变化高达 50 像素,从 1400 像素到 1450 像素。为什么这会导致它们被水平拉伸?
-
目前我只能猜测,因为我看不到你的图片。
-
@MarkSetchell 这是图像示例,我已将它们更新为相同的高度以消除潜在问题:imgur.com/a/IDuRtIK
标签: python image image-processing image-resizing vips