All problems
Center Crop with Padding
Problem
Center crop an image to out_h x out_w, padding with value when the crop is larger than the image.
Use top = (H - out_h) // 2 and left = (W - out_w) // 2, then read the source pixel; out-of-bounds pixels become value.
Test cases
case 1
in: [[[1,2],[3,4]],4,4,0]
expected: [[0,0,0,0],[0,1,2,0],[0,3,4,0],[0,0,0,0]]
case 2
in: [[[0,1,2,3],[4,5,6,7],[8,9,10,11],[12,13,14,15]],2,2,9]
expected: [[5,6],[9,10]]
case 3
in: [[[5]],3,3,0]
expected: [[0,0,0],[0,5,0],[0,0,0]]
case 4
in: [[[1,2,3],[4,5,6],[7,8,9]],3,3,0]
expected: [[1,2,3],[4,5,6],[7,8,9]]
Starter codePython
def center_crop_pad(image, out_h, out_w, value):
# Your code here
pass4 test cases · run your code against them in the editor