bboxconversion
bboxconversion ¶
Module for bounding box conversion functions
Classes¶
Functions¶
bbox_list_to_ullr_array ¶
Converts a list of bounding boxes to a numpy array with (left, top, right, bottom)
Source code in niceml/utilities/boundingboxes/bboxconversion.py
bounding_box_from_absolute_cxcywh ¶
Returns a bounding box from absolute center coordinates [x,y,width,height] in pixels
Source code in niceml/utilities/boundingboxes/bboxconversion.py
compute_target_gt_array ¶
compute_target_gt_array(
anchor_boxes,
gt_boxes,
iou_matrix,
box_variances,
class_index_array,
num_classes,
match_iou=0.5,
ignore_iou=0.4,
)
Computes the np.array which is used as a target for the net training
Parameters:
-
anchor_boxes
(ndarray
) –n x 4 array with anchors in ullr format
-
gt_boxes
(ndarray
) –m x 4 array with gt boxes in ullr format
-
iou_matrix
(ndarray
) –n x m matrix with corresponding iou values
-
box_variances
(ndarray
) –array with 4 values for scaling
-
class_index_array
(ndarray
) –array with length m with gt class indices
-
num_classes
(int
) –number of classes as int
-
match_iou
(float
, default:0.5
) –float value between zero and one to define when two bounding boxes are matching
-
ignore_iou
(float
, default:0.4
) –bounding boxes with an iou between ignore_iou and match_iou are ignored
Returns:
-
ndarray
–Returns a vector with length 4 + 1 + num_classes.
-
ndarray
–The first four digits are the encoded bounding box coordinates,
-
ndarray
–then comes the mask value (POSITIVE,NEGATIVE,IGNORE) and finally
-
ndarray
–a target class list representing the corresponding class label of the bounding box.
Source code in niceml/utilities/boundingboxes/bboxconversion.py
convert_to_ullr ¶
Changes the box format from [x, y, width, height] to corner coordinates [xmin, ymin, xmax, ymax]
Parameters:
-
boxes
(ndarray
) –A tensor of rank 2 or higher with a shape of
( num_boxes, 4)
representing bounding boxes where each box is of the format[x, y, width, height]
.
Returns:
-
–
converted boxes with shape same as that of boxes.
Source code in niceml/utilities/boundingboxes/bboxconversion.py
convert_to_xywh ¶
Changes the box format from the format [left, top, right, bottom] to [upper left x, upper left y, width and height].
Parameters:
-
boxes
(ndarray
) –A tensor of rank 2 or higher with a shape of
(num_boxes, 4)
representing bounding boxes where each box is of the format[left, top, right, bottom]
.
Returns:
-
ndarray
–Converted bounding boxes with shape same as that of boxes.
Source code in niceml/utilities/boundingboxes/bboxconversion.py
dict_to_bounding_box ¶
Creates an BoundingBox from a dict
shift_bbox_by_percentage ¶
Shifts a bounding box to a direction by a given percentage of the bounding box Args: bbox_coords: Bounding box coordinates to be shifted percentage: Percentage of the bounding box to shift by axis: Perform shift on y-axis [0], on x-axis [1] or on both [0,1] direction: Shift direction;
UP if direction == 0 and axis == 0;
DOWN if direction == 1 and axis == 0;
LEFT if direction == 0 and axis == 1;
RIGHT if direction == 1 and axis == 1;
If axis is a list (0,1) the direction has to be a list too.
In this case the first position of the direction list is on x
and the second position is the shift at y.
Returns:
-
–
Shifted bounding box
Source code in niceml/utilities/boundingboxes/bboxconversion.py
shift_x_axis ¶
Shifts a bounding box on x-axis in a specified direction by percentage of that bounding box.
Parameters:
-
bbox
(BoundingBox
) –bounding box to be shifted
-
direction
(int
) –the direction of the shift (0 = up, 1 = down)
-
percentage
(float
) –Percentage of the bounding box to shift by
Returns:
-
BoundingBox
–Shifted bounding box
Source code in niceml/utilities/boundingboxes/bboxconversion.py
shift_y_axis ¶
Shifts a bounding box on the y-axis in a specified direction by percentage of that bounding box.
Parameters:
-
bbox
(BoundingBox
) –bounding box to be shifted
-
direction
(int
) –the direction of the shift (0 = left, 1 = right)
-
percentage
(float
) –Percentage of the bounding box to shift by
Returns:
-
BoundingBox
–Shifted bounding box
Source code in niceml/utilities/boundingboxes/bboxconversion.py
to_relative_bbox_values ¶
Converts absolute image coordinates to relative image coordinates based on image size