bbox_to_slices#

bbox_to_slices(bbox)[source]#

Given a tuple containing bounding box coordinates, return a tuple of slice objects.

A bounding box in the form of a straight list is returned by several functions in skimage, but these cannot be used to direct index into an image. This function returns a tuples of slices can be, such as: im[bbox_to_slices([xmin, ymin, xmax, ymax])].

Parameters:

bbox (tuple of ints) – The bounding box indices in the form (xmin, ymin, zmin, xmax, ymax, zmax). For a 2D image, simply omit the zmin and zmax entries.

Returns:

slices – A tuple of slice objects that can be used to directly index into a larger image.

Return type:

tuple

Examples

Click here to view online example.