1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| class MyArray(numpy.ndarray):
def __new__(self, data, dtype = 'int32', copy = True):
""" Created: 2007.03.16 - Updated: 2007.03.19 """
##print data
if isinstance(data, MyArray):
res = numpy.array(data, dtype, copy = copy)
new = res.view(self)
return new
if isinstance(data, str):
im = Image.open(data).convert("L")
res = numpy.array(list(im.getdata()), dtype, copy = copy)
res.shape = (im.size[1],im.size[0])
new = res.view(self)
return new
if isinstance(data, type(cStringIO.StringIO())):
im = Image.open(data).convert("L")
res = numpy.array(list(im.getdata()), dtype, copy = copy)
res.shape = (im.size[1],im.size[0])
new = res.view(self)
return new
new = numpy.array(data, dtype, copy = copy).view(self)
return new |
Partager