在自己获取的图像样本上,在网络的训练之前还需要做预处理操作。 预处理步骤:
原图:
预处理结果图 (像素值已扩大100倍):
# coding=utf-8
import numpy as np
import cv2
pic_path = './Elegent_Girl.jpg'
def normalization(input):
pic = cv2.imread(input)
pic = pic.astype(np.float32)
# zero-center
pic -= [np.mean(pic[..., 0]), np.mean(pic[..., 1]), np.mean(pic[..., 2])]
# normalize
pic /= [np.std(pic[..., 0]), np.std(pic[..., 1]), np.std(pic[..., 2])]
print pic[..., 0]
pic *= (pic>0)
pic *= 100
pic = pic * (pic<=255) + 255 * (pic>255)
pic = pic.astype(np.uint8)
print pic[..., 0]
cv2.imshow('', pic)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == '__main__':
# 均值0中心化(zero-center), 规范化(normalize)
normalization(pic_path)