def image_whitening(data):
 assert (len(np.shape(data)) == 4)
 nb_pixels = ((np.shape(data)[1] * np.shape(data)[2]) * np.shape(data)[3])
 mean = np.mean(data, axis=(1, 2, 3))
 ones = np.ones(np.shape(data)[1:4], dtype=np.float32)
 for i in xrange(len(data)):
  data[i, :, :, :] -= (mean[i] * ones)
 adj_std_var = np.maximum((np.ones(len(data), dtype=np.float32) / math.sqrt(nb_pixels)), np.std(data, axis=(1, 2, 3)))
 for i in xrange(len(data)):
  data[i, :, :, :] = (data[i, :, :, :] / adj_std_var[i])
 print(np.shape(data))
 return data

def image_whitening ( data ) : assert ( len ( np . shape ( data ) ) == 4 ) nb_pixels = ( ( np . shape ( data ) [ 1 ] * np . shape ( data ) [ 2 ] ) * np . shape ( data ) [ 3 ] ) mean = np . mean ( data , axis = ( 1 , 2 , 3 ) ) ones = np . ones ( np . shape ( data ) [ 1 : 4 ] , dtype = np . float32 ) for i in xrange ( len ( data ) ) : data [ i , : , : , : ] -= ( mean [ i ] * ones ) adj_std_var = np . maximum ( ( np . ones ( len ( data ) , dtype = np . float32 ) / math . sqrt ( nb_pixels ) ) , np . std ( data , axis = ( 1 , 2 , 3 ) ) ) for i in xrange ( len ( data ) ) : data [ i , : , : , : ] = ( data [ i , : , : , : ] / adj_std_var [ i ] ) print ( np . shape ( data ) ) return data
subtracts mean of image and divides by adjusted standard variance .