美文网首页
深度学习之用python计算数据集均值

深度学习之用python计算数据集均值

作者: 小王子威威 | 来源:发表于2018-01-24 09:57 被阅读311次

import os  

from PIL import Image    

import matplotlib.pyplot as plt  

import numpy as np  

from scipy.misc import imread   

filepath ='/home/JPEGImages' # 数据集目录  

pathDir = os.listdir(filepath)  

R_channel =0  

G_channel =0  

B_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])  

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 / num  

G_mean = G_channel / num  

B_mean = B_channel / num  

print("R_mean is %f, G_mean is %f, B_mean is %f" %(R_mean, G_mean, B_mean))  

相关文章

网友评论

      本文标题:深度学习之用python计算数据集均值

      本文链接:https://www.haomeiwen.com/subject/nkbyaxtx.html