# -*- coding: utf-8 -*-
import os
import cv2
import numpy as np
def compute_mean(path):
file_names = os.listdir(path)
file_names.sort()
per_image_Rmean = []
per_image_Gmean = []
per_image_Bmean = []
image_R_std = []
image_G_std = []
image_B_std = []
// 我这里是两个子文件夹
for file in file_names:
file_path = os.path.join(path, file)
img_list = os.listdir(file_path)
img_list.sort()
for img_path in img_list:
img_ = os.path.join(file_path, img_path)
print(img_)
img = cv2.imread(img_)
per_image_Bmean.append(np.mean(img[:, :, 0] / 255.0))
per_image_Gmean.append(np.mean(img[:, :, 1] / 255.0))
per_image_Rmean.append(np.mean(img[:, :, 2] / 255.0))
image_B_std.append(np.std(img[:, :, 0] / 255.0))
image_G_std.append(np.std(img[:, :, 1] / 255.0))
image_R_std.append(np.std(img[:, :, 2] / 255.0))
R_mean = np.mean(per_image_Rmean)
G_mean = np.mean(per_image_Gmean)
B_mean = np.mean(per_image_Bmean)
R_std = np.std(image_R_std)
G_std = np.std(image_G_std)
B_std = np.std(image_B_std)
return R_mean, G_mean, B_mean, R_std, G_std, B_std
def main():
path = '/home/Disc_Z/youku/train/LR'
R_mean, G_mean, B_mean, R_std, G_std, B_std = compute_mean(path)
print('R_mean', R_mean)
print('G_mean', G_mean)
print('B_mean', B_mean)
print('R_std', R_std)
print('G_std', G_std)
print('B_std', B_std)
if __name__ == '__main__':
main()
图像的均值方差统计
最新推荐文章于 2024-03-25 11:01:14 发布