help for conversion of NUMARRAY to PIL object

Discussion in 'Python' started by A. L., Sep 15, 2005.

  1. A. L.

    A. L. Guest

    hi, everybody here,

    I am a newbie to python. I encounter a problem that how to convert
    an array of numarray to pil object. For example, the data in an image
    is extracted using Image.getdata, then the data are converted into an
    array in numarray. But when the array is needed to convert to the pil
    object, I lose my mind. Could somebody here provide some solutions to
    this problem? (In other words, all I need is the interface between
    reading/writing image data and NUMARRAY.)

    Thanks in advance.
    A. L., Sep 15, 2005
    #1
    1. Advertising

  2. A. L.

    Robert Kern Guest

    A. L. wrote:
    > hi, everybody here,
    >
    > I am a newbie to python. I encounter a problem that how to convert
    > an array of numarray to pil object. For example, the data in an image
    > is extracted using Image.getdata, then the data are converted into an
    > array in numarray. But when the array is needed to convert to the pil
    > object, I lose my mind. Could somebody here provide some solutions to
    > this problem? (In other words, all I need is the interface between
    > reading/writing image data and NUMARRAY.)


    In [11]: from numarray import *

    In [12]: import Image

    In [13]: a = zeros((256,256, 4), UInt8)

    In [14]: img = Image.frombuffer('RGBA', (256,256), a)

    --
    Robert Kern


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
    Robert Kern, Sep 15, 2005
    #2
    1. Advertising

  3. A. L.

    A. L. Guest

    Thanks. But some problems remain.

    I have known using Image.tostring/fromstring and
    numarray.tostring/fromstring can do the job. But when confronting
    multi-spectral images, e.g., RGB color images, I don't know how to do
    it. Could you give some advices on that?

    You wrote "In [14]: img = Image.frombuffer('RGBA', (256,256), a) ", but
    it seems that "a" cannot work in "frombuffer".
    A. L., Sep 16, 2005
    #3
  4. A. L.

    Robert Kern Guest

    A. L. wrote:
    > Thanks. But some problems remain.
    >
    > I have known using Image.tostring/fromstring and
    > numarray.tostring/fromstring can do the job. But when confronting
    > multi-spectral images, e.g., RGB color images, I don't know how to do
    > it. Could you give some advices on that?


    What's not working for you?

    > You wrote "In [14]: img = Image.frombuffer('RGBA', (256,256), a) ", but
    > it seems that "a" cannot work in "frombuffer".


    What do you mean that "a" cannot work in "frombuffer"? It certainly does
    on my machine. Is it raising an exception on yours? If so, please post
    the code that is causing the error and the exception that is raised and
    the versions of PIL and numarray that you are using.

    --
    Robert Kern


    "In the fields of hell where the grass grows high
    Are the graves of dreams allowed to die."
    -- Richard Harter
    Robert Kern, Sep 16, 2005
    #4
  5. A. L.

    A. L. Guest

    Sorry, I make the mistakes. I have known how to use to/fromstring
    method to interface between PIL and Numarray.
    And your code does work.

    Another question. Just like the code you provide, is it possible to
    directly load image data from PIL to Numarray array without use of
    to/fromstring method?

    Thank you very much for your kindly help.

    A.L.
    A. L., Sep 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paradox

    Python Image Conversion with PIL

    Paradox, Jul 14, 2003, in forum: Python
    Replies:
    0
    Views:
    357
    Paradox
    Jul 14, 2003
  2. Raaijmakers, Vincent (IndSys,GE Interlogix)

    PIL and jpg -> png conversion

    Raaijmakers, Vincent (IndSys,GE Interlogix), Nov 17, 2003, in forum: Python
    Replies:
    1
    Views:
    319
    Erik Max Francis
    Nov 17, 2003
  3. Raaijmakers, Vincent (IndSys,GE Interlogix)

    RE: PIL and jpg -> png conversion, do I really need java for this???

    Raaijmakers, Vincent (IndSys,GE Interlogix), Nov 19, 2003, in forum: Python
    Replies:
    3
    Views:
    360
    Tobias Pfeiffer
    Nov 20, 2003
  4. Raaijmakers, Vincent (IndSys,GE Interlogix)

    RE: PIL and jpg -> png conversion, do I really need java for this???

    Raaijmakers, Vincent (IndSys,GE Interlogix), Nov 20, 2003, in forum: Python
    Replies:
    1
    Views:
    378
  5. Sverre
    Replies:
    2
    Views:
    3,523
    Sverre
    Dec 17, 2009
Loading...

Share This Page