vis4d.data.transforms.resize

Resize transformation.

Functions

get_resize_shape(original_shape, new_shape)

Get shape for resize, considering keep_ratio and align_long_edge.

get_target_shape(input_shape, shape[, ...])

Generate possibly random target shape.

resize_image(inputs, shape[, interpolation, ...])

Resize image.

resize_tensor(inputs, shape[, ...])

Resize Tensor.

Classes

GenResizeParameters(*[, in_keys, out_keys, ...])

Generate the parameters for a resize operation.

ResizeBoxes2D(*[, in_keys, out_keys, ...])

Resize list of 2D bounding boxes.

ResizeDepthMaps(*[, in_keys, out_keys, ...])

Resize depth maps.

ResizeImages(*[, in_keys, out_keys, ...])

Resize Images.

ResizeInstanceMasks(*[, in_keys, out_keys, ...])

Resize instance segmentation masks.

ResizeIntrinsics(*[, in_keys, out_keys, ...])

Resize Intrinsics.

ResizeOpticalFlows(*[, in_keys, out_keys, ...])

Resize optical flows.

ResizeParam

Parameters for Resize.

ResizeSegMasks(*[, in_keys, out_keys, ...])

Resize segmentation masks.

class GenResizeParameters(*, in_keys=['images'], out_keys=['transforms.resize', 'input_hw'], sensors=None, same_on_batch=True, **kwargs)[source]

Generate the parameters for a resize operation.

__call__(images)[source]

Compute the parameters and put them in the data dict.

Return type:

tuple[list[ResizeParam], list[tuple[int, int]]]

class ResizeBoxes2D(*, in_keys=['boxes2d', 'transforms.resize.scale_factor'], out_keys=['boxes2d'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize list of 2D bounding boxes.

__call__(boxes_list, scale_factors)[source]

Resize 2D bounding boxes.

Parameters:
  • boxes_list (list[ndarray[Any, dtype[float32]]]) – (list[NDArrayF32]): The bounding boxes to be resized.

  • scale_factors (list[tuple[float, float]]) – scaling factors.

Returns:

Resized bounding boxes according to parameters in

resize.

Return type:

list[NDArrayF32]

class ResizeDepthMaps(*, in_keys=['depth_maps', 'transforms.resize.target_shape', 'transforms.resize.scale_factor'], out_keys=['depth_maps'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize depth maps.

__call__(depth_maps, target_shapes, scale_factors)[source]

Resize depth maps.

Return type:

list[ndarray[Any, dtype[float32]]]

class ResizeImages(*, in_keys=['images', 'transforms.resize.target_shape'], out_keys=['images'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize Images.

__call__(images, target_shapes)[source]

Resize an image of dimensions [N, H, W, C].

Parameters:
  • image (Tensor) – The image.

  • target_shape (tuple[int, int]) – The target shape after resizing.

Returns:

Resized images according to parameters in resize.

Return type:

list[NDArrayF32]

class ResizeInstanceMasks(*, in_keys=['instance_masks', 'transforms.resize.target_shape'], out_keys=['instance_masks'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize instance segmentation masks.

__call__(masks_list, target_shapes)[source]

Resize masks.

Return type:

list[ndarray[Any, dtype[float32]]]

class ResizeIntrinsics(*, in_keys=['intrinsics', 'transforms.resize.scale_factor'], out_keys=['intrinsics'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize Intrinsics.

__call__(intrinsics, scale_factors)[source]

Scale camera intrinsics when resizing.

Return type:

list[ndarray[Any, dtype[float32]]]

class ResizeOpticalFlows(*, in_keys=['optical_flows', 'transforms.resize.target_shape', 'transforms.resize.scale_factor'], out_keys=['optical_flows'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize optical flows.

__call__(optical_flows, target_shapes, scale_factors)[source]

Resize optical flows.

Return type:

list[ndarray[Any, dtype[float32]]]

class ResizeParam[source]

Parameters for Resize.

class ResizeSegMasks(*, in_keys=['seg_masks', 'transforms.resize.target_shape'], out_keys=['seg_masks'], sensors=None, same_on_batch=True, **kwargs)[source]

Resize segmentation masks.

__call__(masks_list, target_shape_list)[source]

Resize masks.

Return type:

list[ndarray[Any, dtype[float32]]]

get_resize_shape(original_shape, new_shape, keep_ratio=True, align_long_edge=False, resize_short_edge=False, allow_overflow=False)[source]

Get shape for resize, considering keep_ratio and align_long_edge.

Parameters:
  • original_shape (tuple[int, int]) – Original shape in [H, W].

  • new_shape (tuple[int, int]) – New shape in [H, W].

  • keep_ratio (bool, optional) – Whether to keep the aspect ratio. Defaults to True.

  • align_long_edge (bool, optional) – Whether to align the long edge of the original shape with the long edge of the new shape. Defaults to False.

  • resize_short_edge (bool, optional) – Whether to resize according to the short edge. Defaults to False.

  • allow_overflow (bool, optional) – Whether to allow overflow. Defaults to False.

Returns:

The new shape in [H, W].

Return type:

tuple[int, int]

get_target_shape(input_shape, shape, keep_ratio=False, multiscale_mode='range', scale_range=(1.0, 1.0), align_long_edge=False, resize_short_edge=False, allow_overflow=False)[source]

Generate possibly random target shape.

Return type:

tuple[int, int]

resize_image(inputs, shape, interpolation='bilinear', antialias=False, backend='torch')[source]

Resize image.

Return type:

ndarray[Any, dtype[float32]]

resize_tensor(inputs, shape, interpolation='bilinear', antialias=False)[source]

Resize Tensor.

Return type:

Tensor