473,406 Members | 2,843 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,406 software developers and data experts.

Howto display an array as an image (like imagesc in matlab)

Dear NG,

I currently ty to switch from matlab to python/scipy but have a lot of
trouble with images. What I need is a function for subsequently
displaying a number of 2D-matrices as an image.
I tried:
- Image.show() which is nice but slow and I don't seem to be
able to either close the window nor draw again to the same
window, so I end up with 100 pictures on the screen...
- scipy.xplt.imagesc() and scipy.plt.imagesc() crash
consistently even with fresh installs of wxPython and scipy and
python2.3 on Linux (RH 9) as well as on Win XP.
- Use Tkinter to display the matrix (but then I need to store
the matrix as a gif file first... don't I?)

Are the scipy image/imagesc routines really so increadibly unstable? Are
there alternatives?

Thanks a lot,
Mathias

Jul 18 '05 #1
2 16865
On Thu, 29 Jul 2004, Mathias wrote:
- Image.show() which is nice but slow and I don't seem to be
able to either close the window nor draw again to the same
window, so I end up with 100 pictures on the screen...


I'm not too familiar with SciPy, but is this Image class the PIL Image
class? Because if that's the case, PIL images can be trivially integrated
with Tkinter by using PIL's ImageTk module:

from Tkinter import Label
import ImageTk

mylabel = Label()
mylabel.pack()

while True:
image = process_and_return_image_data_with_scipy()
label['image'] = ImageTk.PhotoImage(image)

I'm not sure how fast this is though (whether ImageTk.PhotoImage() creates
a copy of the original image, etc.).

Jul 18 '05 #2
>>>>> "Mathias" == Mathias <no_sp@m_please.cc> writes:

Mathias> Dear NG, I currently ty to switch from matlab to
Mathias> python/scipy but have a lot of trouble with images. What

matplotlib (by yours truly) is designed as a matlab compatible
plotting library for python. It has 'imshow' to display images. You
can manage several figures, axes, and images as in matlab with the
matlab compatible commands figure / subplot / axes / gcf / gca / close
/ clf / cla / hold.

http://matplotlib.sf.net

Here is a simple script to create and display an image

from matplotlib.matlab import *

delta = 0.025
x = y = arange(-3.0, 3.0, delta)
X, Y = meshgrid(x, y)
Z1 = bivariate_normal(X, Y, 1.0, 1.0, 0.0, 0.0)
Z2 = bivariate_normal(X, Y, 1.5, 0.5, 1, 1)

# difference of Gaussians
im = imshow(Z2-Z1, interpolation='bilinear')
axis('off')
show()

Additional matlab compatible functions for color mapping are provided
(colorbar, jet, gray) and a variety of interpolation methods are
available (nearest neighbor, bilinear, bicubic, much more).

In addition, it supports features I don't believe matlab has, like the
ability to automatically blend multiple images with different alpha
values while 'hold' is on - see for example
http://matplotlib.sourceforge.net/sc...l#layer_images

Outputs to png, ps, svg (image support for svg only in CVS). Also in
CVS is imread to load images into arrays.

If you are very familiar with matlab, matplotlib will be a breeze -
there is a brief tutorial at
http://matplotlib.sourceforge.net/tutorial.html

On win32, if you are using the enthought edition of python
(recommended!), you can use matplotlib out of the box with either the
tkinter or wxpython backends.

JDH

Jul 18 '05 #3

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

Similar topics

2
by: N. Graves | last post by:
Thanks for your help and reading my note! I would like to display an image that would let the user know that more information was stored in a comments field. If the comments field is empty I...
1
by: bborden | last post by:
Novice Access programmer here. I would like to display an image using the Toolbox Image object by calling the images file name using: =fPictureFiles(!!,1) in the Picture control. Below...
1
by: Dev | last post by:
Dear Friends, I am passing the image name, size (in bytes) and imgaeformat (like jpg or bmp or pdf) through the network. I want display the image into picturebox without saving image...
1
by: Thubaiti | last post by:
Hi, I have an image web control with other web controls.. <asp:Image id="itemImage" runat="server"></asp:Image> <asp:Label id="itemNameLabel" runat="server"></asp:Label> <asp:Label...
18
by: Auto | last post by:
Hello, I would like to know how do display an image into a Gridview (ASP.NET 2.0) taken directly from a DataBase, NOT using an URL, like described in this article: ...
6
by: Wijaya Edward | last post by:
Hi, How can I pass Array, Hash, and a plain variable in to a function at the same time. I come from Perl. Where as you probably know it is done like this: sub myfunc {
3
by: computer_guy | last post by:
Hi Everyone, I run into a problem. I am trying to write an aspx that can dynamically generate an image based on some input parameters. Things are very simple if the size of the parameters is...
2
by: NishCA | last post by:
Hello.. I have got finger image data as raw pixel data scan lines from the top, left to the bottom, right. Also, have image height & width in pixels; BPP is avail. I need to display this image...
0
by: adilzcool | last post by:
Hi All , I am New to this Form i am working on project to consume Java Webservice from PHP (front end). So i need to display an image sent from JWS (WSDL) mode in PHP. I have used diff...
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: 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
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: 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
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
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...
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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.