473,396 Members | 2,092 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Image to numeric array

Hello,

I suspect that there is a quite straight forward answer to this, but I can't
find it... I want to import an image and extract a matrix (or array) from it
with elements showing the RGB value of each pixel. But I want to be able to do
this with all types of image formats. It was suggested that a function such as
'B = numeric.from_image(A)' was used but I can't find it in any of the
libraries. I was hoping you could help me on this.

Thank you,
Dimitris

Feb 13 '06 #1
4 7185
Dimitrios Charitatos wrote:
Hello,

I suspect that there is a quite straight forward answer to this, but I
can't find it... I want to import an image and extract a matrix (or array)
from it with elements showing the RGB value of each pixel. But I want to
be able to do this with all types of image formats. It was suggested that
a function such as 'B = numeric.from_image(A)' was used but I can't find
it in any of the libraries. I was hoping you could help me on this.


You have to install the numeric library for that. Googling numeric python
will bring you there pretty quick.

Diez
Feb 13 '06 #2
Diez B. Roggisch wrote:
Dimitrios Charitatos wrote:

Hello,

I suspect that there is a quite straight forward answer to this, but I
can't find it... I want to import an image and extract a matrix (or array)
from it with elements showing the RGB value of each pixel. But I want to
be able to do this with all types of image formats. It was suggested that
a function such as 'B = numeric.from_image(A)' was used but I can't find
it in any of the libraries. I was hoping you could help me on this.

You have to install the numeric library for that. Googling numeric python
will bring you there pretty quick.

Diez

Is there a difference between the 'Numeric' and 'numeric' module?
I have on my system only Numeric... And this has no function like
'from_image'.

The usual way of doing such things is to use PIL (Python Image Library)
to load the image from file, then export it from PIL to a Python string
in order to import from this string to an array of the targeted
numerical module.

Really curious if there is a direct way in any of the numerical
packages, as it would save the time and effort of unnecessary
conversions from PIL, ImageMagick or from other image libraries.

Claudio
Feb 13 '06 #3
> Is there a difference between the 'Numeric' and 'numeric' module?
I have on my system only Numeric... And this has no function like
'from_image'.
I actually didn't check that - I just wanted to point the OP to the
numeric-module(s) available, as he suggested that
The usual way of doing such things is to use PIL (Python Image Library)
to load the image from file, then export it from PIL to a Python string
in order to import from this string to an array of the targeted
numerical module.
I'd go for the getdata() method instead.
Really curious if there is a direct way in any of the numerical
packages, as it would save the time and effort of unnecessary
conversions from PIL, ImageMagick or from other image libraries.


Whatever module is capable of converting needs to know how to read images -
either by itself, or by means of another module.
I know for sure that pygame supports retrieving pixel-data as array.

Diez
Feb 13 '06 #4
Diez B. Roggisch wrote:
Is there a difference between the 'Numeric' and 'numeric' module?
I have on my system only Numeric... And this has no function like
'from_image'.

I actually didn't check that - I just wanted to point the OP to the
numeric-module(s) available, as he suggested that

The usual way of doing such things is to use PIL (Python Image Library)
to load the image from file, then export it from PIL to a Python string
in order to import from this string to an array of the targeted
numerical module.

I'd go for the getdata() method instead.

Yes, you are right.
Sorry, I should have checked it in source code before posting just from
my memory. Usage of .tostring() was my first approach - I have replaced
it later by .getdata() because of speed issues (we are speaking here
about methods of the Image module available after installation of PIL).
As I have experience with numarray only, I can't help here directly with
a code example for Numeric.

Claudio
Really curious if there is a direct way in any of the numerical
packages, as it would save the time and effort of unnecessary
conversions from PIL, ImageMagick or from other image libraries.

Whatever module is capable of converting needs to know how to read images -
either by itself, or by means of another module.
I know for sure that pygame supports retrieving pixel-data as array.

Diez

Feb 13 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Phil | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
1
by: Philippe Grosse | last post by:
Hi, I don't understand this strange behaviour: I compile this code : #include <Python.h> #include"Numeric/arrayobject.h" static PyObject *
0
by: Travis Oliphant | last post by:
Numarray is making great progress and is quite usable for many purposes. An idea that was championed by some is that the Numeric code base would stay static and be replaced entirely by Numarray. ...
6
by: Edwin Young | last post by:
Hi, I'm writing a fractal-generating program in a mixture of C and Python. Python handles all the GUI parts using PyGTK. After finishing the calculations, I have a buffer containing the RGB data...
6
by: Gaubitzer Erwin | last post by:
Hi there I wrote a short program which reads scientific data from a file and stores its values in a Numeric array. At the same time it reads the names of its dimensions which are then in the...
2
by: tjv | last post by:
Hi all, I am working with images in python using PIL. I come from a MATLAB background so I am finding it to be sometimes frustrating to do things correctly and quickly. All I need to do is load an...
5
by: bandw | last post by:
I am having a problem using Numeric-24.0b2 in conjunction with the NetCDF module from ScientificPython (version 2.4.9). This problem does not surface using Numeric-23.8. The problem arises in...
3
by: success_ny | last post by:
Does anyone have a code snippet to compare those values so I can sort the array of alpha-numeric values that include both characters and integers in it? I.e., if we have values like 4236 and...
7
by: Sheldon | last post by:
Hi, I have the following loop that I think can be written to run faster in Numeric. I am currently using Numeric. range_va = main.xsize= 600 main.ysize= 600 #msgva is an (600x600) Numeric...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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...
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.