def channel_shift(x, intensity, is_random=False, channel_index=2):
 if is_random:
  factor = np.random.uniform((- intensity), intensity)
 else:
  factor = intensity
 x = np.rollaxis(x, channel_index, 0)
 (min_x, max_x) = (np.min(x), np.max(x))
 channel_images = [np.clip((x_channel + factor), min_x, max_x) for x_channel in x]
 x = np.stack(channel_images, axis=0)
 x = np.rollaxis(x, 0, (channel_index + 1))
 return x

def channel_shift ( x , intensity , is_random = False , channel_index = 2 ) : if is_random : factor = np . random . uniform ( ( - intensity ) , intensity ) else : factor = intensity x = np . rollaxis ( x , channel_index , 0 ) ( min_x , max_x ) = ( np . min ( x ) , np . max ( x ) ) channel_images = [ np . clip ( ( x_channel + factor ) , min_x , max_x ) for x_channel in x ] x = np . stack ( channel_images , axis = 0 ) x = np . rollaxis ( x , 0 , ( channel_index + 1 ) ) return x
shift the channels of an image .