r"""Batched affine transformation on 2D images. Affine transformation is a linear transformation between two-dimensional coordinates. Args: inp: input image. mat: `(batch, 2, 3)` transformation matrix. out_shape: output tensor shape. border_mode: pixel extrapolat
(
inp: Tensor,
mat: Tensor,
out_shape: Union[Tuple[int, int], int, Tensor],
border_mode: str = "replicate",
border_val: float = 0.0,
format: str = "NHWC",
interp_mode: str = "linear",
)
| 349 | |
| 350 | |
| 351 | def warp_affine( |
| 352 | inp: Tensor, |
| 353 | mat: Tensor, |
| 354 | out_shape: Union[Tuple[int, int], int, Tensor], |
| 355 | border_mode: str = "replicate", |
| 356 | border_val: float = 0.0, |
| 357 | format: str = "NHWC", |
| 358 | interp_mode: str = "linear", |
| 359 | ) -> Tensor: |
| 360 | r"""Batched affine transformation on 2D images. Affine transformation is a linear transformation between two-dimensional coordinates. |
| 361 | |
| 362 | Args: |
| 363 | inp: input image. |
| 364 | mat: `(batch, 2, 3)` transformation matrix. |
| 365 | out_shape: output tensor shape. |
| 366 | border_mode: pixel extrapolation method. |
| 367 | Default: "replicate". Currently "constant", "reflect", |
| 368 | "reflect_101", "isolated", "wrap", "replicate", "transparent" are supported. |
| 369 | border_val: value used in case of a constant border. Default: 0 |
| 370 | format: NHWC" as default based on historical concerns, |
| 371 | "NCHW" is also supported. Default: "NHWC". |
| 372 | interp_mode: interpolation methods. Could be "linear", "nearest", "cubic", "area". |
| 373 | Default: "linear". |
| 374 | |
| 375 | Returns: |
| 376 | output tensor. |
| 377 | |
| 378 | Note: |
| 379 | Here all available options for params are listed, |
| 380 | however it does not mean that you can use all the combinations. |
| 381 | On different platforms, different combinations are supported. |
| 382 | ``warp_affine`` only support forward inference, Please refer to ``warp_perspective`` if backward is needed. |
| 383 | """ |
| 384 | op = builtin.WarpAffine( |
| 385 | border_mode=border_mode, |
| 386 | border_val=border_val, |
| 387 | format=format, |
| 388 | imode=interp_mode, |
| 389 | ) |
| 390 | out_shape = utils.astensor1d(out_shape, inp, dtype="int32", device=inp.device) |
| 391 | (result,) = apply(op, inp, mat, out_shape) |
| 392 | return result |
| 393 | |
| 394 | |
| 395 | def warp_perspective( |