假设您安装了scipy并假设使用"reshape"实际意味着"调整大小",以下代码应该加载目录中的所有图像/foo/bar,将它们调整为64x64并将它们添加到列表中images:
import os
from scipy import ndimage, misc
images = []
for root, dirnames, filenames in os.walk("/foo/bar"):
for filename in filenames:
if re.search("\.(jpg|jpeg|png|bmp|tiff)$", filename):
filepath = os.path.join(root, filename)
image = ndimage.imread(filepath, mode="RGB")
image_resized = misc.imresize(image, (64, 64))
images.append(image_resized)
Run Code Online (Sandbox Code Playgroud)
如果你需要一个numpy数组(要调用reshape),那么只需images = np.array(images)在末尾添加(import numpy as np在开始时).
| 归档时间: |
|
| 查看次数: |
13789 次 |
| 最近记录: |