bboxresize

Resize bounding boxes

Description

example

bboxB = bboxresize(bboxA,scale) returns bounding boxes, bboxB, resized by the amount specified by scale.

Examples

collapse all

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

collapse all

Bounding boxes, specified as an M-by-4 matrix of M bounding boxes. Each row, M, of the matrix defines a bounding box as a four-element vector [x,y,width,height] in pixel coordinates.

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.

Output Arguments

collapse all

Resized bounding boxes, returned as an M-by-4 matrix of M bounding boxes. Each row, M, of the matrix defines one bounding box in pixel coordinates, as a four-element vector [x,y,width,height].

Introduced in R2019b