Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在大小不是2倍的特定文件夹中查找图像?_Python_Image Size_Mipmaps - Fatal编程技术网

Python 如何在大小不是2倍的特定文件夹中查找图像?

Python 如何在大小不是2倍的特定文件夹中查找图像?,python,image-size,mipmaps,Python,Image Size,Mipmaps,我有一些文件夹,大约有200个图像,我想突出显示的图像大小不是2的倍数 有没有一种有效的方法 致以最良好的祝愿 下面是一个Python脚本,它可以打印大小不是2的倍数的所有图像。它只需查找所有图像并使用PIL获取尺寸 import glob from PIL import Image # Get all images image_path = 'PATH TO YOUR IMAGES' images = glob.glob(image_path + '/**.png') # Dependin

我有一些文件夹,大约有200个图像,我想突出显示的图像大小不是2的倍数

有没有一种有效的方法


致以最良好的祝愿

下面是一个Python脚本,它可以打印大小不是2的倍数的所有图像。它只需查找所有图像并使用PIL获取尺寸

import glob
from PIL import Image

# Get all images
image_path = 'PATH TO YOUR IMAGES'
images = glob.glob(image_path + '/**.png')  # Depending on your images extension
images_not_pair = []

# For all images open them with PIL and get the image size
for image in images:
    with Image.open(image) as im:
        width, height = im.size
        if width % 2 is not 0 or height % 2 is not 0:
            images_not_pair.append(image)

print(images_not_pair)

图像是2的倍数意味着什么?您可以匹配所有文件名,然后使用图像库打开并找到尺寸,然后打印出2的倍数。khelwood,我的意思是2x2、4x4、8x8。。。256 x 256和64 x 128,如果图像是例如127x63,我希望看到它高亮显示,以便修复错误。谢谢你的回答,彼得·伍德,我来试试看。塞普里昂,非常感谢你!这远远超出了我目前所能编写的代码,所以我试图理解每一行。我真是太感谢你了!顺致敬意,