imcropbox
imcropbox(img: np.ndarray, box: Union[Box, np.ndarray], use_pad: bool = False) -> np.ndarray
-
Description: Crops the input image using the provided bounding box.
-
Parameters
- img (
np.ndarray
): The input image to crop. - box (
Union[Box, np.ndarray]
): The cropping box. The input can be a customBox
object from Capybara, defined by the coordinates (x1, y1, x2, y2), or a NumPy array with the same format. - use_pad (
bool
): Whether to use padding for out-of-bounds areas. If set to True, the outer regions will be padded with zeros. Default is False.
- img (
-
Returns
- np.ndarray: The cropped image.
-
Example
import capybara as cb
# Using custom Box object
img = cb.imread('lena.png')
box = cb.Box([50, 50, 200, 200], box_mode='xyxy')
cropped_img = cb.imcropbox(img, box, use_pad=True)
# Resize the cropped image to the original size for visualization
cropped_img = cb.imresize(cropped_img, [img.shape[0], img.shape[1]])