<jupyter_start><jupyter_text>bbox_to_slices  Import packages<jupyter_code>import numpy as np
import porespy as ps
import scipy.ndimage as spim
import matplotlib.pyplot as plt
import skimage
ps.visualization.set_mpl_style()<jupyter_output><empty_output><jupyter_text>Generate image for testing<jupyter_code>np.random.seed(0)
im = ps.generators.blobs([500, 500])
im3d = ps.generators.blobs([100, 100,100])<jupyter_output><empty_output><jupyter_text>Visualize the images<jupyter_code>fig, ax = plt.subplots(1, 2, figsize=[8, 4]);
ax[0].imshow(im);
ax[0].axis(False)
ax[0].set_title('2D image')
ax[1].imshow(im3d[25,...]);
ax[1].axis(False)
ax[1].set_title('3D image');<jupyter_output><empty_output><jupyter_text>Demonstration of function Define some bounding boxes in 2D and 3D:<jupyter_code>bbox3d = [0, 0, 0, 50, 50, 50]
bbox2d = [0, 0, 50, 50]<jupyter_output><empty_output><jupyter_text>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:<jupyter_code>box2d = ps.tools.bbox_to_slices(bbox = bbox2d)
box3d = ps.tools.bbox_to_slices(bbox = bbox3d)
fig, ax = plt.subplots(1, 2, figsize=[7, 7])
ax[0].imshow(im[box2d])
ax[0].axis(False)
ax[0].set_title('2D')

ax[1].imshow(im3d[box3d][25, ...])
ax[1].axis(False)
ax[1].set_title('3D')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14228456913827656, 'fraction_numerical': 0.04809619238476954, 'mean_word_length': 7.185792349726776, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '212057', 'license': 'MIT', 'n_tokens_mistral': 647, 'n_tokens_neox': 606, 'n_words': 133, 'path': 'examples/tools/howtos/bbox_to_slices.ipynb', 'repo_name': 'jamesobutler/porespy', 'size': '1497'}