experiments/overlap/augmentations/color.py [67:104]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        return { 'smoothness' : smoothness, 'color0' : color0, 'color1': color1,
                'color2': color2, 'color3' : color3, 'color4' : color4, 'amount' : amount }

    def transform(self, image, color0, color1, color2, color3, color4, smoothness, amount):

        color0 = color0.astype(np.uint8)
        color1 = color1.astype(np.uint8)
        color2 = color2.astype(np.uint8)
        color3 = color3.astype(np.uint8)
        color4 = color4.astype(np.uint8)
        def get_color(color0, color1, edge0, edge1, luma, smoothness):
            smooth_color = color0 + ((color1 - color0) * smoothstep(edge0, edge1, luma))
            a = 4.0 * (luma - edge0)
            linear_color = (1 - a) * color0 + a * color1
            return (1 - smoothness) * linear_color + smoothness * smooth_color

        vals = np.array([0.2126, 0.7152, 0.0722]).reshape(1,1,3)
        luma = np.sum(image.astype(np.float32)*vals, axis=2, keepdims=True)/255

        c1 = get_color(color0, color1, 0.0, 0.25, luma, smoothness)
        c2 = get_color(color1, color2, 0.25, 0.50, luma, smoothness)
        c3 = get_color(color2, color3, 0.5, 0.75, luma, smoothness)
        c4 = get_color(color3, color4, 0.75, 1.0, luma, smoothness)
        out = (luma < 0.25) * c1 + ((luma >= 0.25)&(luma < 0.5)) * c2\
                + ((luma >= 0.5)&(luma < 0.75)) * c3 + (luma >= 0.75) * c4
        return np.clip((1 - amount) * image + amount * out, 0, 255).astype(np.uint8)
        
    def convert_to_numpy(self, params):
        colors = []
        for i in range(5):
            colors.extend(params['color'+str(i)].tolist())
        return np.array([params['smoothness']] + colors + [params['amount']])

    def convert_from_numpy(self, numpy_record):
        params = {'smoothness' : numpy_record[0], 'amount' : numpy_record[16]}
        for i in range(5):
            params['color'+str(i)] = numpy_record[1+3*i:1+3*(i+1)]
        return params
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



imagenet_c_bar/corrupt.py [484:521]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        return { 'smoothness' : smoothness, 'color0' : color0, 'color1': color1,
                'color2': color2, 'color3' : color3, 'color4' : color4, 'amount' : amount }

    def transform(self, image, color0, color1, color2, color3, color4, smoothness, amount):

        color0 = color0.astype(np.uint8)
        color1 = color1.astype(np.uint8)
        color2 = color2.astype(np.uint8)
        color3 = color3.astype(np.uint8)
        color4 = color4.astype(np.uint8)
        def get_color(color0, color1, edge0, edge1, luma, smoothness):
            smooth_color = color0 + ((color1 - color0) * smoothstep(edge0, edge1, luma))
            a = 4.0 * (luma - edge0)
            linear_color = (1 - a) * color0 + a * color1
            return (1 - smoothness) * linear_color + smoothness * smooth_color

        vals = np.array([0.2126, 0.7152, 0.0722]).reshape(1,1,3)
        luma = np.sum(image.astype(np.float32)*vals, axis=2, keepdims=True)/255

        c1 = get_color(color0, color1, 0.0, 0.25, luma, smoothness)
        c2 = get_color(color1, color2, 0.25, 0.50, luma, smoothness)
        c3 = get_color(color2, color3, 0.5, 0.75, luma, smoothness)
        c4 = get_color(color3, color4, 0.75, 1.0, luma, smoothness)
        out = (luma < 0.25) * c1 + ((luma >= 0.25)&(luma < 0.5)) * c2\
                + ((luma >= 0.5)&(luma < 0.75)) * c3 + (luma >= 0.75) * c4
        return np.clip((1 - amount) * image + amount * out, 0, 255).astype(np.uint8)
        
    def convert_to_numpy(self, params):
        colors = []
        for i in range(5):
            colors.extend(params['color'+str(i)].tolist())
        return np.array([params['smoothness']] + colors + [params['amount']])

    def convert_from_numpy(self, numpy_record):
        params = {'smoothness' : numpy_record[0], 'amount' : numpy_record[16]}
        for i in range(5):
            params['color'+str(i)] = numpy_record[1+3*i:1+3*(i+1)]
        return params
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



