# -*- coding: utf-8 -*-
"""
Created on Fri Jun 22 19:00:54 2018
@author: PC
"""
import cv2
import numpy as np
def whiteBalance(src):
B,G,R = cv2.split(src)
B_mean = np.mean(B)
G_mean = np.mean(G)
R_mean = np.mean(R)
gray_mean = (B_mean+G_mean+R_mean) / 3
B_corf = 0.9 * gray_mean / B_mean
G_corf = 0.9 * gray_mean / G_mean
R_corf = 0.9 * gray_mean / R_mean
B_Correct = np.uint8(B_corf * B)
G_Correct = np.uint8(G_corf * G)
R_Correct = np.uint8(R_corf * R)
dst = cv2.merge((B_Correct,G_Correct,R_Correct))
return dst
def main():
img = cv2.imread('C:\\Users\\PC\\Desktop\\program\\skin\\Images\\12345\\4.jpg')
width, height = img.shape[:2]
if height>800 :
rate = height/800
width1 = int(width/rate)
height1 = 800
img = cv2.resize(img,(height1,width1),cv2.INTER_CUBIC)
# dst = LightNormalization.lightNormalization(img)
dst = whiteBalance(img)
cv2.imshow("img", img)
cv2.imshow("whiteBalance", dst)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == "__main__":
main()