批测图像通道数量的代码
发布时间
阅读量:
阅读量
通过Python代码可以判断图像文件属于PNG格式还是JPG格式。PNG格式的图像通常包含四个通道,而JPG格式的图像则一般具有三个通道。
import os
from PIL import Image
#图片文件夹路径
path = 'JPEGImages/'
for file in os.listdir(path):
pic_file = path + file
img = Image.open(pic_file)
print("file : %s , pass_count : %s" % (file, len(img.split())) )
全部评论 (0)
还没有任何评论哟~
