使用 glob 对目录中的图像进行切片,image_slicer基于像素大小而不是指定要拼接的图像数量?

Slice images in directory using glob, image_slicer based on pixel sizes instead of specifying the number of images to splice?

提问人:ihb 提问时间:9/9/2020 最后编辑:desertnautihb 更新时间:10/21/2020 访问量:956

问:

我正在使用尺寸为 4000 x 3000 像素的图像数据库,我希望根据像素大小 (1000 x 1000) 对目录中的每个图像进行切片。我目前正在使用 and 模块,并且目前正在执行试错以使图像达到首选像素大小。globimage_slicer

import glob, os
import image_slicer

for file in glob.glob('~\\test_folder\\*.jpg'):
    image_slicer.slice(file, 15)

15 个切片生成尺寸为 1000 x 750 的输出照片,这很接近,但仍然没有雪茄。有没有办法指定具体尺寸?

python slice glob image-slicer

评论


答:

1赞 KolaB 9/9/2020 #1

如果您查看 image_slicer.slice 的源代码,则可以指定两个参数。源代码显示了如何使用它们来计算水平和垂直方向的瓦片数量。您可以从这里向后工作,以查看需要多少行和列才能获得 1000x1000 像素的磁贴。在您的情况下(基于将 4000x3000 图像转换为 1000x1000 图块),它是 和 .即rowcolrow=3col=4

import glob, os
import image_slicer

for file in glob.glob('~\\test_folder\\*.jpg'):
    image_slicer.slice(file, row=3, col=4)