示例#1
0
    def __call__(self, sample):
        inputs, target = sample
        h, w, _ = inputs.shape

        applied_angle = random.uniform(-self.angle, self.angle)
        diff = random.uniform(-self.diff_angle, self.diff_angle)
        angle1 = applied_angle - diff / 2

        angle1_rad = angle1 * np.pi / 180

        inputs = F.rotate(inputs, angle1)
        target = F.rotate(target, angle1)

        # keep angle1 and angle2 within [0,pi/2] with a reflection at pi/2: -1rad is 1rad, 2rad is pi - 2 rad
        angle1_rad = np.pi / 2 - np.abs(angle1_rad % np.pi - np.pi / 2)

        c1 = np.cos(angle1_rad)
        s1 = np.sin(angle1_rad)
        c_diag = h / np.sqrt(h * h + w * w)
        s_diag = w / np.sqrt(h * h + w * w)

        ratio = 1. / (c1 + w / float(h) * s1)

        crop = CropCenter((int(h * ratio), int(w * ratio)))
        return crop(inputs, target)
 def perform_transformation_operation(temp_x, temp_y):
     threshold = 0.5
     threshold_angle = 0.2
     if threshold_angle <= random.random() == True:
         angle = random.randint(-10, 10)
         temp_x = F.rotate(temp_x, angle)
         temp_y = F.rotate(temp_y, angle)
     if threshold <= random.random() == True:
         temp_x = transforms.functional.hflip(temp_x)
         temp_y = transforms.functional.hflip(temp_y)
     if threshold <= random.random() == True:
         temp_x = transforms.functional.hflip(temp_x)
         temp_y = transforms.functional.hflip(temp_y)
     return (temp_x, temp_y)
示例#3
0
    def __call__(self, img):
        """
            img (PIL Image): Image to be rotated.

        Returns:
            PIL Image: Rotated image.
        """

        angle = self.get_params(self.degrees)

        return F.rotate(img, angle, self.resample, self.expand, self.center)
示例#4
0
 def apply(self, image, mask, rand_h, rand_w, angle, **params):
     h, w = image.shape[:2]
     mask = F.rotate(mask, angle) if self.rotate[1] > 0 else mask
     mask = mask[:, :, np.newaxis] if image.ndim == 3 else mask
     image *= mask[rand_h:rand_h + h, rand_w:rand_w + w].astype(image.dtype)
     return image