Python怎么计算图片数据集的均值方差
发表于:2025-11-06 作者:千家信息网编辑
千家信息网最后更新 2025年11月06日,本文小编为大家详细介绍"Python怎么计算图片数据集的均值方差",内容详细,步骤清晰,细节处理妥当,希望这篇"Python怎么计算图片数据集的均值方差"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢
千家信息网最后更新 2025年11月06日Python怎么计算图片数据集的均值方差
本文小编为大家详细介绍"Python怎么计算图片数据集的均值方差",内容详细,步骤清晰,细节处理妥当,希望这篇"Python怎么计算图片数据集的均值方差"文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
Python批量reshape图片
# -*- coding: utf-8 -*-"""Created on Thu Aug 23 16:06:35 2018@author: libo"""from PIL import Imageimport osdef image_resize(image_path, new_path): # 统一图片尺寸 print('============>>修改图片尺寸') for img_name in os.listdir(image_path): img_path = image_path + "/" + img_name # 获取该图片全称 image = Image.open(img_path) # 打开特定一张图片 image = image.resize((512, 512)) # 设置需要转换的图片大小 # process the 1 channel image image.save(new_path + '/'+ img_name) print("end the processing!")if __name__ == '__main__': print("ready for :::::::: ") ori_path = r"Z:\pycharm_projects\ssd\VOC2007\JPEGImages" # 输入图片的文件夹路径 new_path = 'Z:/pycharm_projects/ssd/VOC2007/reshape' # resize之后的文件夹路径 image_resize(ori_path, new_path)import osfrom PIL import Imageimport matplotlib.pyplot as pltimport numpy as npfrom scipy.misc import imreadfilepath = r'Z:\pycharm_projects\ssd\VOC2007\reshape' # 数据集目录pathDir = os.listdir(filepath)R_channel = 0G_channel = 0B_channel = 0for idx in range(len(pathDir)): filename = pathDir[idx] img = imread(os.path.join(filepath, filename)) / 255.0 R_channel = R_channel + np.sum(img[:, :, 0]) G_channel = G_channel + np.sum(img[:, :, 1]) B_channel = B_channel + np.sum(img[:, :, 2])num = len(pathDir) * 512 * 512 # 这里(512,512)是每幅图片的大小,所有图片尺寸都一样R_mean = R_channel / numG_mean = G_channel / numB_mean = B_channel / numR_channel = 0G_channel = 0B_channel = 0for idx in range(len(pathDir)): filename = pathDir[idx] img = imread(os.path.join(filepath, filename)) / 255.0 R_channel = R_channel + np.sum((img[:, :, 0] - R_mean) ** 2) G_channel = G_channel + np.sum((img[:, :, 1] - G_mean) ** 2) B_channel = B_channel + np.sum((img[:, :, 2] - B_mean) ** 2)R_var = np.sqrt(R_channel / num)G_var = np.sqrt(G_channel / num)B_var = np.sqrt(B_channel / num)print("R_mean is %f, G_mean is %f, B_mean is %f" % (R_mean, G_mean, B_mean))print("R_var is %f, G_var is %f, B_var is %f" % (R_var, G_var, B_var))可能有点慢,慢慢等着就行。。。。。。。
最后得到的结果是介个
参考
计算数据集均值和方差
import osfrom PIL import Image import matplotlib.pyplot as pltimport numpy as npfrom scipy.misc import imread filepath = '/home/JPEGImages' # 数据集目录pathDir = os.listdir(filepath)R_channel = 0G_channel = 0B_channel = 0for idx in xrange(len(pathDir)): filename = pathDir[idx] img = imread(os.path.join(filepath, filename)) R_channel = R_channel + np.sum(img[:,:,0]) G_channel = G_channel + np.sum(img[:,:,1]) B_channel = B_channel + np.sum(img[:,:,2])num = len(pathDir) * 384 * 512 # 这里(384,512)是每幅图片的大小,所有图片尺寸都一样R_mean = R_channel / numG_mean = G_channel / numB_mean = B_channel / num
R_channel = 0G_channel = 0B_channel = 0
for idx in xrange(len(pathDir)): filename = pathDir[idx] img = imread(os.path.join(filepath, filename)) R_channel = R_channel + np.sum((img[:,:,0] - R_mean)**2) G_channel = G_channel + np.sum((img[:,:,1] - G_mean)**2) B_channel = B_channel + np.sum((img[:,:,2] - B_mean)**2)R_var = R_channel / numG_var = G_channel / numB_var = B_channel / numprint("R_mean is %f, G_mean is %f, B_mean is %f" % (R_mean, G_mean, B_mean))print("R_var is %f, G_var is %f, B_var is %f" % (R_var, G_var, B_var))读到这里,这篇"Python怎么计算图片数据集的均值方差"文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注行业资讯频道。
图片
数据
均值
方差
尺寸
大小
文章
内容
文件
文件夹
目录
路径
妥当
全称
思路
新知
更多
步骤
知识
知识点
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
梦幻西游可购买的服务器
数据库加群速度
地下城手游服务器密码
如何读取数据库文件
设备软件开发邀请函
招远商城软件开发公司
捷克软件开发薪酬
企业服务器虚拟化用什么软件
办公系统软件开发报告
北京麻将软件开发服务为先
网络技术中什么是会话
惠州支付软件开发收费
16核服务器能带几台电脑
成都net软件开发需要多少钱
湖南工程学院网络安全中心
上海交通大学icsd数据库
我的世界服务器制作成果
千峰网络安全
一键备份数据库
云服务器linux域名
反邪教网络安全主题班会教案
lol服务器延迟太高
云服务器安全组添加端口
男子利用网络技术获利400
金华电力软件开发
java 哪个数据库
币安服务器在哪儿
程序员打造自己的服务器
四平数据库置疑修复培训
一网科技网络技术有限公司