mmagic.models.utils.bbox_utils
¶
Module Contents¶
Functions¶
|
Extract patch from a given bbox. |
|
Modify bbox to target size. |
|
Extract patches around the given bbox. |
- mmagic.models.utils.bbox_utils.extract_bbox_patch(bbox, img, channel_first=True)[source]¶
Extract patch from a given bbox.
- Parameters
bbox (torch.Tensor | numpy.array) – Bbox with (top, left, h, w). If img has batch dimension, the bbox must be stacked at first dimension. The shape should be (4,) or (n, 4).
img (torch.Tensor | numpy.array) – Image data to be extracted. If organized in batch dimension, the batch dimension must be the first order like (n, h, w, c) or (n, c, h, w).
channel_first (bool) – If True, the channel dimension of img is before height and width, e.g. (c, h, w). Otherwise, the img shape (samples in the batch) is like (h, w, c). Default: True.
- Returns
Extracted patches. The dimension of the output should be the same as img.
- Return type
(torch.Tensor | numpy.array)
- mmagic.models.utils.bbox_utils.scale_bbox(bbox, target_size)[source]¶
Modify bbox to target size.
The original bbox will be enlarged to the target size with the original bbox in the center of the new bbox.
- Parameters
bbox (np.ndarray | torch.Tensor) – Bboxes to be modified. Bbox can be in batch or not. The shape should be (4,) or (n, 4).
target_size (tuple[int]) – Target size of final bbox.
- Returns
Modified bboxes.
- Return type
(np.ndarray | torch.Tensor)
- mmagic.models.utils.bbox_utils.extract_around_bbox(img, bbox, target_size, channel_first=True)[source]¶
Extract patches around the given bbox.
- Parameters
img (torch.Tensor | numpy.array) – Image data to be extracted. If organized in batch dimension, the batch dimension must be the first order like (n, h, w, c) or (n, c, h, w).
bbox (np.ndarray | torch.Tensor) – Bboxes to be modified. Bbox can be in batch or not.
target_size (List(int)) – Target size of final bbox.
channel_first (bool) – If True, the channel dimension of img is before height and width, e.g. (c, h, w). Otherwise, the img shape (samples in the batch) is like (h, w, c). Default: True.
- Returns
Extracted patches. The dimension of the output should be the same as img.
- Return type
(torch.Tensor | np.ndarray)