All problems
Crop Image
Problem
Crop a rectangular region out of a 2D image.
Return the sub-image containing rows top through top + height - 1 and columns left through left + width - 1, using slicing semantics. You may assume the crop fits inside the image and that height and width are positive.
Test cases
case 1
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11]],0,0,3,4]
expected: [[0,1,2,3],[4,5,6,7],[8,9,10,11]]
case 2
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11]],1,1,2,2]
expected: [[5,6],[9,10]]
case 3
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11]],2,3,1,1]
expected: [[11]]
Starter codePython
def crop_image(image, top, left, height, width):
# Your code here
pass3 test cases · run your code against them in the editor