Forgot to reply-to-list...

---------- Forwarded message ----------
From: Anthony Floyd <[EMAIL PROTECTED]>
Date: Wed, Mar 26, 2008 at 4:54 PM
Subject: Re: [Matplotlib-users] load data from string or array to Image
To: sa6113 <[EMAIL PROTECTED]>


On Wed, Mar 26, 2008 at 1:33 AM, sa6113 <[EMAIL PROTECTED]> wrote:
 >
 >
 >  I have a problem to load data from string or array to Image but without
 >  using PIL , because I have to check the application in 6 different platforms
 >  like Windows 32bit, Windows X64 (64bit version), Linux 32bit, Linux 64bit
 >  x86_64, Linux IPF (Itanium Processor Family) and HP-UX 64.
 >
 >  There is a code but I don't want to use PIL :
 >  http://mail.python.org/pipermail/image-sig/1998-October/000572.html
 >
 >  Can I accomplish the same thing using the modules that are already on the
 >  system, or those that are pure Python (not requiring any compilation or
 >  binary download)?

 I went through this just a few weeks ago.  Now, mind you I'm using wx
 and numpy already.

 My solution was to turn my .png into a Python string using img2py.py
 in the wx/tools directory.

 With the string, I then used the following code to return the image (a
 watermark) as an array that figimage() or imshow() can use directly.
 I'm sure the code can be optimized, but it works fast enough for me...

 def getWatermarkArray():
    rows = 28
    columns = 200
    dimensions = 3

    image = getWatermarkImage()
    # image array is a string of hex values
    imageString = image.GetData()

    imageList = [ord(item) for item in imageString]

    imageArray = numpy.zeros(shape=(28,200,3), dtype=numpy.float32)

    imageCounter = 0

    for rowCounter in range(rows):
        for columnCounter in range(columns):
            for dimCounter in range(dimensions):
                imageArray[rowCounter][columnCounter][dimCounter] =
 imageList[imageCounter]/255.
                imageCounter += 1

    return imageArray

 HTH,
 A>

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Matplotlib-users mailing list
Matplotlib-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/matplotlib-users

Reply via email to