z-score normalization就是标准化,将影像的R、G、B分别减去其均值然后再除以方差
在深度学习中,这样做可以加快模型的收敛速度。
imgdir = os.listdir(filepath)
mean = np.zeros(3)
std = np.zeros(3)
count = 0
for z in imgdir:
count += 1
img = cv2.imread(filepath + z)
for d in range(3):
mean[d] += img[:, :, d].mean()
std[d] += img[:, :, d].std()
mean = mean/count
std = mean/count
print (list(mean), list(std))