All problems
Clip Boxes to Image
Problem
Clip boxes to the image rectangle.
Clamp x1 and x2 to [0, width] and y1 and y2 to [0, height], rounding each coordinate to 4 decimal places.
Test cases
case 1
in: [[[-1,2,5,20]],4,10]
expected: [[0,2,4,10]]
case 2
in: [[[0,0,4,10]],4,10]
expected: [[0,0,4,10]]
case 3
in: [[[5,5,6,6]],4,4]
expected: [[4,4,4,4]]
case 4
in: [[[-2,-3,2,3],[1,1,2,2]],3,3]
expected: [[0,0,2,3],[1,1,2,2]]
Starter codePython
def clip_boxes(boxes, width, height):
# Your code here
pass4 test cases · run your code against them in the editor