统计图像数据集下图像分辨率的分布情况

需求:统计图像数据集下图像分辨率的分布情况,以便将图像在输入到模型之前裁剪到合适的大小

待统计的图像数据:(位于./lid/下)
在这里插入图片描述

代码:

import os
import pandas as pd
from PIL import Image
from collections import Counter


source = './lid/'
imgfile = os.listdir(source)
shot_cut = []
long_cut = []

print('filenum:', len([lists for lists in os.listdir(source)]))

for img in imgfile:
    img_path = os.path.join(source, img)
    img = Image.open(img_path)
    imgSize = img.size  # 图片的长和宽
    #print(imgSize)
    maxSize = max(imgSize)  # 图片的长边
    long_cut.append(maxSize)
    minSize = min(imgSize)  # 图片的短边
    shot_cut.append(minSize)

#shot_result = Counter(shot_cut)
#long_result = Counter(long_cut)
shot_result = pd.value_counts(shot_cut, normalize=True)
long_result = pd.value_counts(long_cut, normalize=True)

print(shot_result)
print(long_result)

shot_result.to_csv('shot.csv', header=0)
long_result.to_csv('long.csv', header=0)

结果:
长边分布:
在这里插入图片描述
短边分布:
在这里插入图片描述
由于目前使用的模型要求输入长宽一致,根据分布情况可以裁剪成360*360左右。

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值