Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loading a blob(Google app Engine) into PIL or NumPy

I'd like to be able to load a blob(image into the Python Image Processing Library or into a numpy array for analysis(such as mean, median, standard deviation) without using the serving url.

Here is my image database the t_image_url contains the serving url for the blob

from google.appengine.ext import db, blobstore    
class ImageModel(db.Model):
    t_image = blobstore.BlobReferenceProperty(required=True)
    t_imageUrl = db.StringProperty(required = True)

here is a segment of what I tried

import numpy as np
import Image
import ImageOps
class ImageAnalysisHandler(BaseHandler):
    def get(self, imageModel_id):
        if self.user:           
            i = ImageModel.get_by_id(int(imageModel_id))
            OpenedImage = Image.open(i.t_image)
            self.render('imageAnalysis.html', imageD = i)
        else:
            self.redirect('login')

This obviously didn't work since the Image Module(from the Python Imaging Library) doesn't know how to read blobs. I was wondering if anyone knew how to read in a blob into PIL or a numpy array accurately.

like image 624
piyushg91 Avatar asked Apr 08 '26 11:04

piyushg91


1 Answers

Take a look at the BlobReader class. It let you read a file store in blobstore with a file-like interface.

like image 108
Sebastian Kreft Avatar answered Apr 10 '26 02:04

Sebastian Kreft