# Get indices of image patches that are inside a bounding box

I want to find the indexes of the patched image tensor which are inside a bounding box. I have the given parameters:

``````img = patched_image_from_vit(image) # tensor shape: [batch_size, width*height, patch_size*patch_size*3]
bboxes = get_bbox_coordinates() # tensor shape: [batch_size, 4]; each bbox has (x_min, y_min, x_max, y_max)

patch_indices = get_patches_inside_bbox(img, bboxes)

def get_patches_inside_bbox(img, bboxes):
''' returns indices of patches that are inside (width*height) and
also inside the bounding box area defined by each bboxes'''
``````

I am having hard time mapping area inside coordinates into patches. Is there any resource or codebase on this that can provide me some reference?