【发布时间】:2016-03-02 09:49:21
【问题描述】:
我在一个 numpy 数组 (10000 x 480 x 752) 中有近 10000 张灰度图像,我想使用 scipy.misc 中的 imresize 函数调整它们的大小。它适用于围绕所有图像构建的 for 循环,但需要 15 分钟。
images_resized = np.zeros([0, newHeight, newWidth], dtype=np.uint8)
for image in range(images.shape[0]):
temp = imresize(images[image], [newHeight, newWidth], 'bilinear')
images_resized = np.append(images_resized, np.expand_dims(temp, axis=0), axis=0)
有什么方法可以通过类似应用的功能更快地做到这一点?我查看了 apply_along_axis
def resize_image(image):
return imresize(image, [newHeight, newWidth], 'bilinear')
np.apply_along_axis(lambda x: resize_image(x), 0, images)
但这给出了一个
'arr' does not have a suitable array shape for any mode
错误。
【问题讨论】:
-
如果您希望任何人帮助您,您必须提供如何调整图像大小的代码。请参阅stackoverflow.com/help/mcve
-
我不确定这是否是您要找的东西,但请看一下:stackoverflow.com/questions/13242382/…
-
您是否有一组特定的
newHeight、newWidth值供您使用?您是仅进行下采样还是上采样,或者两者都可以? -
这不是您所要求的,但如果您从头开始创建
images_resized = np.zeros([images.shape[0], newHeight, newWidth], dtype=np.uint8)并通过枚举images在右侧插入调整大小的x,请检查您的循环有多快。调整 numpy 数组的大小需要时间... -
你最后用@Peter做了什么?
标签: python numpy image-resizing