img_processing#


We use shape naming conventions in this module (applied to all variables).

hw: height, width. Sometimes also called y_size and x_size yx: y, x (positions).

exception IncompatibleShapeError[source]#
centered_constrained_bbox(limiting_bbox_yxhw: tuple[int, int, int, int], new_bbox_shape_hw: tuple[int, int]) tuple[int, int, int, int][source]#

Returns a bounding box centered on and contained within the limiting bounding box with the specified shape. A bounding box is a tuple of type (y_pos, x_pos, height, width) where (y_pos, x_pos) point to the upper left corner.

Can be interpreted as "center cropping" the input bounding box to the specified shape.

Parameters:
  • limiting_bbox_yxhw -- Bounding box that new bbox is contained within and centered on

  • new_bbox_shape_hw -- Shape of centered bounding box

Returns:

Centered bounding box

crop_center(img_hw: ndarray, shape_hw: tuple[int, int]) ndarray[source]#

Perform a center crop of the input image to the specified shape.

Parameters:
  • img_hw -- a 2d array to be cropped

  • shape_hw -- Shape of the cropped image