Somu p
Somu p

Reputation: 21

Store and append numpy array in azure blob

I want to iterate through list of image convert it to numpy.darray and store it in azure blob storage. Every loop i want to append np.array to azure blob. The over all goal is to imerge all images in y axis through azure blob.

Upvotes: 0

Views: 1266

Answers (1)

unknown
unknown

Reputation: 7483

The simple demo could help. For converting image to an array, install Pillow to use PIL by pip install Pillow first.

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())

I tried this, and upload them to the blob.

enter image description here

enter image description here

Reference:

Uploading array as a .jpg image to Azure blob storage

Doc numpy.append

Convert image to NumPy Array

Upvotes: 1

Related Questions