python读取pgm格式图片并显示

涉及到使用BioID_Face_Database人脸数据集,而其中图片的存储格式是.pgm,所以简单写了几句python代码来读取并显示图片进行查看,代码如下:

import os
from PIL import Image

def eachFile(filepath):
    for root, dirs, files in os.walk(filepath):
        for file in files:
            if os.path.splitext(file)[1] == '.pgm':
                print(os.path.join(root, file))
                im = Image.open(os.path.join(root, file))
                im.show()
                print(im.size)       
    
if __name__ == '__main__':
    filepath = "G:/BioID_Face_Database/BioID-FaceDatabase-V1.2/"
    eachFile(filepath)

猜你喜欢

转载自blog.csdn.net/xiakejiang/article/details/86999822