bboxresize - Resize bounding boxes - MATLAB (original) (raw)
Syntax
Description
[bboxB](#mw%5F1fa7b4cb-15c5-4837-ba89-f0dd7d9d2ffb) = bboxresize([bboxA](#mw%5F98d6ca1a-1927-4936-ba26-dc60ba58a279),[scale](#mw%5F839531aa-bf4d-4bac-9a09-929ea02e8b24))
resizes bounding boxes in bboxA
by the amount specified byscale
. This function supports 2-D and 3-D bounding boxes.
Examples
Read an image.
I = imread('peppers.png');
Define bounding boxes and labels.
bboxA = [ 410 230 100 90 186 78 80 60 ]
bboxA = 2×4
410 230 100 90 186 78 80 60
labelsA = [ "garlic" "onion" ];
Resize the image and the bounding boxes.
scale = 1.5; J = imresize(I,scale); bboxB = bboxresize(bboxA,scale);
Display the results.
figure I = insertObjectAnnotation(I,'Rectangle',bboxA,labelsA); J = insertObjectAnnotation(J,'Rectangle',bboxB,labelsA); imshowpair(I,J,'montage')
Input Arguments
Bounding boxes, specified as an _M_-by-4,_M_-by-5, or M_-by-9 nonsparse numeric matrix of_M bounding boxes. Each row, M, of the matrix defines a bounding box as either an axis-aligned rectangle, a rotate rectangle, or a cuboid. The table below describes the format of the bounding boxes.
Bounding Box | Description |
---|---|
Axis-aligned rectangle | Defined in spatial coordinates as an _M_-by-4 numeric matrix with rows of the form [x y w _h_], where: M is the number of axis-aligned rectangles.x and y specify the upper-left corner of the rectangle.w specifies the width of the rectangle, which is its length along the _x_-axis.h specifies the height of the rectangle, which is its length along the _y_-axis. |
Rotated rectangle | Defined in spatial coordinates as an _M_-by-5 numeric matrix with rows of the form [xctr yctr xlen ylen _yaw_], where: M is the number of rotated rectangles.xctr and yctr specify the center of the rectangle.xlen specifies the width of the rectangle, which is its length along the _x_-axis before rotation.ylen specifies the height of the rectangle, which is its length along the _y_-axis before rotation.yaw specifies the rotation angle in degrees. The rotation is clockwise-positive around the center of the bounding box. ![]() |
Cuboid | Defined in spatial coordinates as an _M_-by-9 numeric matrix with rows of the form [xctr yctr zctr xlen ylen zlen xrot yrot _zrot_], where: M is the number of cuboids.xctr, yctr, and zctr specify the center of the cuboid.xlen, ylen, and zlen specify the length of the cuboid along the _x_-axis,_y_-axis, and _z_-axis, respectively, before rotation.xrot, yrot, and zrot specify the rotation angles of the cuboid around the _x_-axis,_y_-axis, and z_-axis, respectively. The_xrot, yrot, and zrot rotation angles are in degrees about the cuboid center. Each rotation is clockwise-positive with respect to the positive direction of the associated spatial axis. The function computes rotation matrices assuming ZYX order Euler angles [xrot yrot _zrot_].The figure shows how these values determine the position of a cuboid. ![]() |
Scale, specified as a scalar or a row vector. When you specify a scalar, the function applies the same scale factor to the height and width of the bounding boxes inbboxA. When you specify a row vector, the function applies the factor in the first element of the vector to resize the height and the second element to resize the width of the bounding boxes.
Output Arguments
Warped bounding boxes, returned as an _M2_-by-N matrix of M2 bounding boxes. The number of bounding boxes returned is less than the number of bounding boxes in the input. Each row, M2, of the matrix defines one bounding box of the same type as the inputbboxA. When bboxB
contains floating point data, the function returns it with the same type as bboxA
. Otherwise, the function returns bboxB
as typesingle
.
Version History
Introduced in R2019b
The bboxresize,bboxcrop,bboxwarp, andshowShape functions assume the input bounding box coordinates for axis-aligned rectangles are specified in spatial coordinates and return the transformed bounding boxes in spatial coordinates.