<s> from __future__ import division , print_function , absolute_import <EOL> import numpy as np <EOL> def match_lightness ( img , ref_img ) : <EOL> if ref_img . ndim == <NUM_LIT:3> : <EOL> ref_grayscale = ref_img . mean ( - <NUM_LIT:1> ) <EOL> else : <EOL> ref_grayscale = ref_img <EOL> new_img = img - img . mean ( - <NUM_LIT:1> , keepdims = True ) + ref_grayscale [ ... , np . newaxis ] <EOL> return new_img . clip ( <NUM_LIT:0> , <NUM_LIT:1> ) </s>
