bbox_to_slice#

omnipose.utils.bbox_to_slice(bbox, shape, pad=0, im_pad=0)[source]#

return the tuple of slices for cropping an image based on the skimage.measure bounding box optional padding allows for the bounding box to be expanded, but not outside the original image dimensions

Parameters
  • bbox (ndarray, float) -- input bounding box, e.g. [y0,x0,y1,x1]

  • shape (array, tuple, or list, int) -- shape of corresponding array to be sliced

  • pad (array, tuple, or list, int) -- padding to be applied to each axis of the bounding box can be a common padding (5 means 5 on every side) or a list of each axis padding ([3,4] means 3 on y and 4 on x). N-volume requires an N-tuple.

  • im_pad (int) -- region around the edges to avoid (pull back coordinate limits)

Return type

tuple of slices