|
发表于 2022-9-19 13:21:03
|
显示全部楼层
最直接的办法是贴上imresize函数
@ np.deprecate(message="'imresize' is deprecated in SciPy 1.0.0,"
"and will be removed in 1.3.0\n"
"Use Pillow instead ``numpy.array(Image.fromarray(arr).resize())``.")
def imresize(arr, size, interp='bilinear', mode=None):
im = Image.fromarray(arr, mode=mode)
ts = type(size)
if np.issubdtype(ts, np.signedinteger):
percent = size / 100.0
size = tuple((np.array(im.size)*percent).astype(int))
elif np.issubdtype(type(size), np.floating):
size = tuple((np.array(im.size)*size).astype(int))
else:
size = (size[1], size[0])
func = {'nearest': 0, 'lanczos': 1, 'bilinear': 2, 'bicubic': 3, 'cubic': 3}
imnew = im.resize(size, resample=func[interp])
return np.array(imnew) |
|