Beispiel #1
0
 def __call__(self, file_a, file_b, label, mask):
     angle = float(
         torch.empty(1).uniform_(float(self.degrees[0]),
                                 float(self.degrees[1])).item())
     # print('angle: ', angle)
     center_f = [0.0, 0.0]
     matrix = tf._get_inverse_affine_matrix(center_f, -angle, [0.0, 0.0],
                                            1.0, [0.0, 0.0])
     return (F_t.rotate(file_a,
                        matrix=matrix,
                        resample=self.resample,
                        expand=self.expand,
                        fill=self.fill),
             F_t.rotate(file_b,
                        matrix=matrix,
                        resample=self.resample,
                        expand=self.expand,
                        fill=self.fill),
             F_t.rotate(label.unsqueeze(0),
                        matrix=matrix,
                        resample=self.resample,
                        expand=self.expand,
                        fill=self.fill).squeeze(0),
             F_t.rotate(mask.unsqueeze(0),
                        matrix=matrix,
                        resample=self.resample,
                        expand=self.expand,
                        fill=self.fill).squeeze(0))
Beispiel #2
0
def rotate_image_tensor(
    img: torch.Tensor,
    angle: float,
    interpolation: InterpolationMode = InterpolationMode.NEAREST,
    expand: bool = False,
    fill: Optional[List[float]] = None,
    center: Optional[List[float]] = None,
) -> torch.Tensor:
    center_f = [0.0, 0.0]
    if center is not None:
        if expand:
            warnings.warn(
                "The provided center argument has no effect on the result if expand is True"
            )
        else:
            _, height, width = get_dimensions_image_tensor(img)
            # Center values should be in pixel coordinates but translated such that (0, 0) corresponds to image center.
            center_f = [
                1.0 * (c - s * 0.5) for c, s in zip(center, [width, height])
            ]

    # due to current incoherence of rotation angle direction between affine and rotate implementations
    # we need to set -angle.
    matrix = _get_inverse_affine_matrix(center_f, -angle, [0.0, 0.0], 1.0,
                                        [0.0, 0.0])
    return _FT.rotate(img,
                      matrix,
                      interpolation=interpolation.value,
                      expand=expand,
                      fill=fill)
Beispiel #3
0
 def __call__(self, file):
     file = torch.from_numpy(file)
     angle = float(torch.empty(1).uniform_(float(self.degrees[0]), float(self.degrees[1])).item())
     # print('angle: ', angle)
     center_f = [0.0, 0.0]
     matrix = tf._get_inverse_affine_matrix(center_f, -angle, [0.0, 0.0], 1.0, [0.0, 0.0])
     return F_t.rotate(file, matrix=matrix, resample=self.resample,
                         expand=self.expand, fill=self.fill)