bbox_to_slices
#
Import packages#
import matplotlib.pyplot as plt
import numpy as np
import porespy as ps
ps.visualization.set_mpl_style()
Generate image for testing#
np.random.seed(0)
im = ps.generators.blobs([500, 500])
im3d = ps.generators.blobs([100, 100, 100])
Visualize the images
Demonstration of function#
Define some bounding boxes in 2D and 3D:
bbox3d = [0, 0, 0, 50, 50, 50]
bbox2d = [0, 0, 50, 50]
The bounding box as defined by most packages are given as lists without much context as to how the values should be used. The bbox_to_slices
function returns a tuple of slice objects than can be used to directly index into a ND-array to retrieve the area defined by the bounding box:
box2d = ps.tools.bbox_to_slices(bbox=bbox2d)
box3d = ps.tools.bbox_to_slices(bbox=bbox3d)