experiments/overlap/augmentations/obscure.py [134:169]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        angle = np.random.uniform(low=0.0, high=2*np.pi)
        angle_variation = np.random.uniform(low=0.1, high=1.0)
        seed = np.random.randint(low=0, high=2**32)

        return {'length' : length, 'density' : density, 'angle' : angle, 'angle_variation' : angle_variation, 'seed' : seed}

    def transform(self, image, length, density, angle, angle_variation, seed):

        num_lines = int(density * self.im_size)
        l = length * self.im_size
        random_state = np.random.RandomState(seed=seed)
        out = image.copy()
        for i in range(num_lines):
            x = self.im_size * random_state.uniform()
            y = self.im_size * random_state.uniform()
            a = angle + 2 * np.pi * angle_variation * (random_state.uniform() - 0.5)
            s = np.sin(a) * l
            c = np.cos(a) * l
            #x1 = max(min(int(x-c), self.im_size-1), 0)
            #x2 = max(min(int(x+c), self.im_size-1), 0)
            #y1 = max(min(int(y-s), self.im_size-1), 0)
            #y2 = max(min(int(y+s), self.im_size-1), 0)
            x1 = int(x-c)
            x2 = int(x+c)
            y1 = int(y-s)
            y2 = int(y+s)
            rxc, ryc, rval = line_aa(x1, y1, x2, y2)
            xc, yc, val = [], [], []
            for rx, ry, rv in zip(rxc, ryc, rval):
                if rx >= 0 and ry >= 0 and rx < self.im_size and ry < self.im_size:
                    xc.append(rx)
                    yc.append(ry)
                    val.append(rv)
            xc, yc, val = np.array(xc, dtype=np.int), np.array(yc, dtype=np.int), np.array(val)
            out[xc, yc, :] = (1.0 - val.reshape(-1,1)) * out[xc, yc, :].astype(np.float32) + val.reshape(-1,1)*128
        return out.astype(np.uint8)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



imagenet_c_bar/corrupt.py [648:679]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        angle = np.random.uniform(low=0.0, high=2*np.pi)
        angle_variation = np.random.uniform(low=0.1, high=1.0)
        seed = np.random.randint(low=0, high=2**32)

        return {'length' : length, 'density' : density, 'angle' : angle, 'angle_variation' : angle_variation, 'seed' : seed}

    def transform(self, image, length, density, angle, angle_variation, seed):

        num_lines = int(density * self.im_size)
        l = length * self.im_size
        random_state = np.random.RandomState(seed=seed)
        out = image.copy()
        for i in range(num_lines):
            x = self.im_size * random_state.uniform()
            y = self.im_size * random_state.uniform()
            a = angle + 2 * np.pi * angle_variation * (random_state.uniform() - 0.5)
            s = np.sin(a) * l
            c = np.cos(a) * l
            x1 = int(x-c)
            x2 = int(x+c)
            y1 = int(y-s)
            y2 = int(y+s)
            rxc, ryc, rval = line_aa(x1, y1, x2, y2)
            xc, yc, val = [], [], []
            for rx, ry, rv in zip(rxc, ryc, rval):
                if rx >= 0 and ry >= 0 and rx < self.im_size and ry < self.im_size:
                    xc.append(rx)
                    yc.append(ry)
                    val.append(rv)
            xc, yc, val = np.array(xc, dtype=np.int), np.array(yc, dtype=np.int), np.array(val)
            out[xc, yc, :] = (1.0 - val.reshape(-1,1)) * out[xc, yc, :].astype(np.float32) + val.reshape(-1,1)*128
        return out.astype(np.uint8)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



