<jupyter_start><jupyter_text>Select region of interest from an imageThis example shows how to crop an image using `nanomesh`.<jupyter_code>from nanomesh import Volume
vol = Volume.load('sample_data.npy')
plane = vol.select_plane(x=161)<jupyter_output>Jupyter environment detected. Enabling Open3D WebVisualizer.
[Open3D INFO] WebRTC GUI backend enabled.
[Open3D INFO] WebRTCWindowSystem: HTTP handshake server disabled.<jupyter_text>Use `.select_roi` to open an interactive widget. Select a region of interest in the figure by enclosing them within a polygon. A rectangle is fitted to the polygon.- Press the 'esc' key to start a new polygon- Hold the 'shift' key to move all of the vertices- Hold the 'ctrl' key to move a single vertex<jupyter_code>roi = plane.select_roi()<jupyter_output><empty_output><jupyter_text>The `.bbox` attribute is updated when the selection above changes.<jupyter_code>roi.bbox<jupyter_output><empty_output><jupyter_text>Use the `.crop_to_roi` method to extract the region of interest.<jupyter_code>plane_roi = plane.crop_to_roi(bbox=roi.bbox)
plane_roi.show()<jupyter_output><empty_output><jupyter_text>Manual croppingAlternatively, if you know which points to extract from the  to Use the `minimum_bounding_rectangle` function to fit the smallest rectangle around the given points.The example below demonstrates this on a slanted square. Well, almost, because the coordinates contain a small error to demonstrate the function.<jupyter_code>from nanomesh.roi2d import minimum_bounding_rectangle
import numpy as np

roi = np.array([
    [ 60,  60],
    [110, 110],
    [ 60, 145],  # <- should be 150
    [ 10, 110],
])

bbox = minimum_bounding_rectangle(roi)
bbox<jupyter_output><empty_output><jupyter_text>The bounding box (`bbox`) can then be used to extract this region from the image using `extract_rectangle`. If the bounding box is slanted, the image will be straightened using an Euclidean transform.<jupyter_code>from nanomesh.roi2d import extract_rectangle

cropped = plane.apply(extract_rectangle, bbox=bbox)
cropped.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07883420926899187, 'fraction_numerical': 0.014811275680840898, 'mean_word_length': 6.146757679180888, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 24, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '109080', 'license': 'Apache-2.0', 'n_tokens_mistral': 698, 'n_tokens_neox': 654, 'n_words': 223, 'path': 'notebooks/sample_data/How to select a region of interest from an image.ipynb', 'repo_name': 'hpgem/nanomesh', 'size': '2093'}