在azure blob中存储和附加numpy数组

2024-04-20 01:05:24 发布

您现在位置:Python中文网/ 问答频道 /正文

我想遍历图像列表,将其转换为numpy.darray并将其存储在azure blob存储中。我想将np.array附加到azure blob的每个循环。总体目标是通过azure blob整合y轴上的所有图像


Tags: 图像numpy列表npazurearrayblob总体目标
1条回答
网友
1楼 · 发布于 2024-04-20 01:05:24

简单的演示可能会有所帮助。要将映像转换为数组,请首先安装Pillow以使用PIL

from azure.storage.blob import BlockBlobService
from PIL import Image
from numpy import asarray
import numpy as np
import os

account_name = '<your storage account name>'
account_key = '<your access key>'
container_name = '<your container name>'

blob_service = BlockBlobService(account_name, account_key)
 
FilePathlist = ['xxxxx', 'xxxxx']
 
blob = []

for filePath in FilePathlist :
 
    print(filePath)
    # load the image
    image = Image.open(filePath)
    
    # convert image to numpy array
    data = asarray(image)

    # append np.array
    blob = np.append(blob, data)

# Upload to blob
print("upload")
blob_service.create_blob_from_bytes(container_name, "aaaaa.jpg", blob.tobytes())

我尝试了这个,并将它们上传到blob

enter image description here

enter image description here

参考:

Uploading array as a .jpg image to Azure blob storage

文件numpy.append

Convert image to NumPy Array

相关问题 更多 >