module api.transforms.image.spatial
Global Variables
- interp_codes
function Resize
Resize(
src,
dsize_w: int = None,
dsize_h: int = None,
scale: float = None,
interpolation: str = 'nearest',
keep_ratio: bool = False,
return_scale: bool = False
)
Args:
-
src
(np.ndarray): The input image to be resized. -
dsize_w
(int, optional): Target width. Higher priority thanscale
. Defaults to None. -
dsize_h
(int, optional): Target height. Should be assigned if dsize_w is specified. Defaults to None. -
scale
(float, optional): Calculate target size using this scale. Defaults to None. -
interpolation
(str, optional): Interpolation method, accepted values are "nearest", "bilinear", "bicubic", "area", "lanczos".. Defaults to "nearest". -
keep_ratio
(bool, optional): If dsize is specified, the image will be rescaled as large as possible and keep its aspect ratio, and padding redundant areas with zeros. Defaults to False. -
return_scale
(bool, optional): Whether to return actualw_scale
andh_scale
. Defaults to False.
Raises:
-
TypeError
: when only one of dsize_w and dsize_h is specified. -
TypeError
: when scale is negative.
Returns:
tuple | ndarray
: (resized_img
,w_scale
,h_scale
) orresized_img
function Crop
crop a region of interest from the src
array.
Args:
-
src
(np.ndarray): source array (H, W) or (H, W, C) -
roi
(Tuple): region of interst (top, bottom, left, right)
Returns:
np.ndarray
:src[top:bottom, left:right, ...]
function Flip
flip the src
image.
Args:
-
src
(np.ndarray): image (H, W) or (H, W, C) -
direction
(str, optional): choose in "horizontal" and "vertical". Defaults to "horizontal".
Raises:
ValueError
: bad direction value
Returns:
np.ndarray
: flipped image.
function Pad
Padding a image to target size.
Args:
-
src
(np.ndarray): Source image. -
dst_w
(int): target width. -
dst_h
(int): target height. -
pad_val
(int, optional): padding value to be filled in. Defaults to 0. User should set the value to some value meant to be ignored. -
padding_mode
(str): Type of padding. Should be: constant, edge, -
reflect or symmetric. Default
: constant.- constant: pads with a constant value, this value is specified
with pad_val.
- edge: pads with the last value at the edge of the image. - reflect: pads with reflection of image without repeating the
last value on the edge. For example, padding [1, 2, 3, 4] with 2 elements on both sides in reflect mode will result in [3, 2, 1, 2, 3, 4, 3, 2].
- symmetric: pads with reflection of image repeating the last
value on the edge. For example, padding [1, 2, 3, 4] with 2 elements on both sides in symmetric mode will result in [2, 1, 1, 2, 3, 4, 4, 3]
Returns:
np.ndarray
: padded image.
function SizeDivisorMultiple
Returns a smallest but larger shape to ensure each edge to be multiple to some number.
Args:
-
img
(np.ndarray, optional): (H, W) or (H, W, 3), will extract image size if w or h not specified. -
w
(int, optional): original width -
h
(int, optional): original height -
divisor
(int, optional): the returned edge is a multiple of this value.
Returns:
dict
: {"h": new_h, "w": new_w}