experiments/overlap/augmentations/pil.py [385:421]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def sample_parameters(self):
        points = np.array([
            [0,0],
            [0, self.im_size],
            [self.im_size, self.im_size],
            [self.im_size, 0]
            ]).astype(np.float32)
        shift = float_parameter(self.severity, self.im_size / 3) * np.random.uniform(low=-1,high=1, size=(4,2))
        points += shift
        return {'points' : points}

    def transform(self, image, points):
        im = Image.fromarray(image)
        im = im.transform(
                (self.im_size, self.im_size), 
                Image.QUAD, 
                points.flatten(), 
                resample=Image.BILINEAR
                )
        im = np.array(im).astype(np.float32)
        mask = Image.fromarray(np.ones_like(image).astype(np.uint8)*255)
        mask = mask.transform(
                (self.im_size, self.im_size),
                Image.QUAD,
                points.flatten(),
                resample=Image.BILINEAR
                )
        mask = np.array(mask).astype(np.float32) / 255
        im = mask * im + (1-mask) * image

        return im.astype(np.uint8)

    def convert_to_numpy(self, params):
        return params['points'].flatten()

    def convert_from_numpy(self, numpy_record):
        return {'points' : numpy_record.reshape(4,2)}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



imagenet_c_bar/corrupt.py [1037:1073]:
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    def sample_parameters(self):
        points = np.array([
            [0,0],
            [0, self.im_size],
            [self.im_size, self.im_size],
            [self.im_size, 0]
            ]).astype(np.float32)
        shift = float_parameter(self.severity, self.im_size / 3) * np.random.uniform(low=-1,high=1, size=(4,2))
        points += shift
        return {'points' : points}

    def transform(self, image, points):
        im = Image.fromarray(image)
        im = im.transform(
                (self.im_size, self.im_size), 
                Image.QUAD, 
                points.flatten(), 
                resample=Image.BILINEAR
                )
        im = np.array(im).astype(np.float32)
        mask = Image.fromarray(np.ones_like(image).astype(np.uint8)*255)
        mask = mask.transform(
                (self.im_size, self.im_size),
                Image.QUAD,
                points.flatten(),
                resample=Image.BILINEAR
                )
        mask = np.array(mask).astype(np.float32) / 255
        im = mask * im + (1-mask) * image

        return im.astype(np.uint8)

    def convert_to_numpy(self, params):
        return params['points'].flatten()

    def convert_from_numpy(self, numpy_record):
        return {'points' : numpy_record.reshape(4,2)}
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -



