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. 4 1210
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 rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
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. 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 rk***@ucsd.edu
"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Alexander Schwaigkofler |
last post by:
Hi!
I have the following problem with numarray. I read the install.txt manual,
but it doesn't already work.
OS: Microsoft Windows 2000
python: Python 2.2.3 (#42, May 30 2003, 18:12:08) on...
|
by: Marco Bubke |
last post by:
Hi
I have tried to include numarray in Pyrex but I get allways
this error:
Traceback (most recent call last):
File "gears.py", line 9, in ?
import gl
File...
|
by: Marc Schellens |
last post by:
Following the NumPy documentation, I took over some C code,
but run into an error.
Does anybody have a suggestion?
Thanks,
marc
gdlpython.cpp:225: `PyArray_Type' undeclared (first use this...
|
by: Russell E. Owen |
last post by:
I'm writing a C extension for numarray and am puzzled about the idiom
for error handling.
The documentation seems to say one should always decref an array after
calling NA_InputArray, etc., to...
|
by: has |
last post by:
<BLUSH> Careless talk costs lives, as they say. In my case, a
throwaway comment that Python could trounce the notoriously
underpowered and undersupported AppleScript language for "serious
number...
|
by: grv |
last post by:
So it is supposed to be very fast to have an array of say 5 million
integers stored in a binary file and do
a = numarray.fromfile('filename', (2, 2, 2))
numarray.add(a, 9, a)
but how is that...
|
by: Bill Mill |
last post by:
Hello all,
I've pickled a numarray array object using cPickle like so:
pickle = cPickle.Pickler(fout, -1)
pickle.dump((myarray, list1, list2))
and this seems to work fine, until I try to...
|
by: Colin J. Williams |
last post by:
Python advertises some basic service:
C:\Python24>python
Python 2.4.1 (#65, Mar 30 2005, 09:13:57) on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
With...
|
by: Chris Smith |
last post by:
Howdy,
I'm a college student and for one of we are writing programs to
numerically compute the parameters of antenna arrays. I decided to use
Python to code up my programs. Up to now I haven't...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |