def pad_if_need(sz_atleast, img, mode='<STR_LIT>'):<EOL>
<EOL>imsz = img.shape[:<NUM_LIT:2>]  <EOL>padneed = np.asarray((sz_atleast[<NUM_LIT:0>] - imsz[<NUM_LIT:0>], sz_atleast[<NUM_LIT:1>] - imsz[<NUM_LIT:1>]))<EOL>if np.any(padneed > <NUM_LIT:0>):<EOL><INDENT>padding = np.zeros((img.ndim, <NUM_LIT:2>), dtype='<STR_LIT>')<EOL>padneed = np.maximum(padneed, <NUM_LIT:0>)<EOL>padding[:<NUM_LIT:2>, <NUM_LIT:0>] = padneed/<NUM_LIT:2><EOL>padding[:<NUM_LIT:2>, <NUM_LIT:1>] = padneed - padneed/<NUM_LIT:2><EOL>img = np.pad(img, padding, mode=mode)<EOL><DEDENT>return img<EOL>
pad img if need to guarantee minumum size
:param sz_atleast: [H,W] at least
:param img: image np.array [H,W, ...]
:param mode: str, padding mode
:return: padded image or asis if enought size