tf.keras.utils.bounding_boxes.crop
Stay organized with collections
Save and categorize content based on your preferences.
Crops bounding boxes based on the given offsets and dimensions.
tf.keras.utils.bounding_boxes.crop(
boxes, top, left, height, width, bounding_box_format='xyxy'
)
This function crops bounding boxes to a specified region defined by
top, left, height, and width. The boxes are first converted to
xyxy format, cropped, and then returned.
Args |
boxes
|
The bounding boxes to crop. A NumPy array or tensor of shape
(N, 4) or (batch_size, N, 4).
|
top
|
The vertical offset of the top-left corner of the cropping region.
|
left
|
The horizontal offset of the top-left corner of the cropping
region.
|
height
|
The height of the cropping region. Defaults to None.
|
width
|
The width of the cropping region. Defaults to None.
|
bounding_box_format
|
The format of the input bounding boxes. Defaults to
"xyxy".
|
Returns |
|
The cropped bounding boxes.
|
Example:
boxes = np.array([[10, 20, 50, 60], [70, 80, 100, 120]]) # xyxy format
cropped_boxes = keras.utils.bounding_boxes.crop(
boxes, bounding_box_format="xyxy", top=10, left=20, height=40, width=30
) # Cropping a 30x40 region starting at (20, 10)
print(cropped_boxes)
# Expected output:
# array([[ 0., 10., 30., 50.],
# [50., 70., 80., 110.]])
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates. Some content is licensed under the numpy license.
Last updated 2026-10-31 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2026-10-31 UTC."],[],[]]