Resize bounding boxes
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')
bboxA— Bounding boxes
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.
|Axis-aligned rectangle||[xmin, ymin, width, height]||This type of bounding box is defined in pixel coordinates as an M-by-4 matrix representing M bounding boxes|
|Rotated rectangle||[xcenter, ycenter, width, height, yaw]||This type of bounding box is defined in spatial coordinates as an M-by-5 matrix representing M bounding boxes. The xcenter and ycenter coordinates represent the center of the bounding box. The width and height elements represent the length of the box along the x and y axes, respectively. The yaw represents the rotation angle in degrees. The amount of rotation about the center of the bounding box is measured in the clockwise direction.|
|Cuboid||[xcenter, ycenter, zcenter, width, height, depth, rx, ry, rz]||Defined in spatial coordinates as an M-by-9 matrix
representing M bounding boxes. The
ycenter coordinates represent the
center of the bounding box. The width and
height elements represent the length of the box along
the x and y axes, respectively. The
rx,ry, and rz
rotation angles are in degrees about the cuboid center. The rotation is
positive in the clockwise direction, with respect to the positive direction of
Rotation matrices are computed assuming ZYX order Euler angles [rx, ry, rz].
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 in
bboxA. 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.
bboxB— Warped bounding boxes
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 input