如何仅更改文件夹中没有特定像素宽度和高度的那些图像的像素大小?

How to change the size in pixels only of those images that do not have a certain width and height of pixels within a folder?

我有一个名为 'p' 的文件夹,里面有 60 张 .png 图像,我需要的是仅将像素大小更改为那些不是 113 x 222 像素的图像

import cv2
import numpy as np
import glob

img_files = glob.glob("p/*.png")

for img_file in img_files:
    if(): #The condition that verify the dimentions
        img = cv2.imread(img_file)
        res = cv2.resize(img, dsize=(113, 222), interpolation=cv2.INTER_CUBIC)

我认为使用 for 循环我可以遍历该目录中的图像,但我不确定如何验证那些必须调整大小的图像以及哪些不应该调整大小的图像(以像素为单位) .

重要的是,其余具有 113 x 222 像素的图像不要对其进行修改,并且仅将那些以前没有这些尺寸的图像替换为调整后的版本。

我终于可以编写这段代码了:

import cv2
import numpy as np
import glob

img_files = glob.glob("imgs/*.png")

for img_file in img_files:
    print(img_file)
    img = cv2.imread(img_file)
    print(img.shape)
    if( img.shape != (222, 113, 3) ):
        print("Esta imagen no coincide con las dimensiones deseadas! La redimensionaré!")
        res = cv2.resize(img, dsize=(113, 222), interpolation=cv2.INTER_CUBIC)
        #cv2.imwrite(img_file, res) #Reemplaza por la nueva imagen ya redimensionada
        print("Imagen: " + str(img_file) + " redimensionada " + "--->" + str(res.shape))
    print("\n-------\n")