pychubby.utils module

Collection of utilities.

pychubby.utils.points_to_rectangle_mask(shape, top_left, bottom_right, width=1)

Convert two points into a rectangle boolean mask.

Parameters:
  • shape (tuple) – Represents the (height, width) of the final mask.
  • top_left (tuple) – Two element tuple representing (row, column) of the top left corner of the inner rectangle.
  • bottom_right (tuple) – Two element tuple representing (row, column) of the bottom right corner of the inner rectangle.
  • width (int) – Width of the edge of the rectangle. Note that it is generated by dilation.
Returns:

rectangle_mask – Boolean mask of shape shape where True entries represent the edge of the rectangle.

Return type:

np.ndarray

Notes

The output can be easily used for quickly visualizing a rectangle in an image. One simply does something like img[rectangle_mask] = 255.