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

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mathias

    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.imag esc() and scipy.plt.image sc() 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

  • Christopher T King

    #2
    Re: Howto display an array as an image (like imagesc in matlab)

    On Thu, 29 Jul 2004, Mathias wrote:
    [color=blue]
    > - 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...[/color]

    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_ret urn_image_data_ with_scipy()
    label['image'] = ImageTk.PhotoIm age(image)

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

    Comment

    • John Hunter

      #3
      Re: Howto display an array as an image (like imagesc in matlab)

      >>>>> "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.

      Download matplotlib for free. Matplotlib is a python library for making publication quality plots using a syntax familiar to MATLAB users. Matplotlib uses numpy for numerics.


      Here is a simple script to create and display an image

      from matplotlib.matl ab import *

      delta = 0.025
      x = y = arange(-3.0, 3.0, delta)
      X, Y = meshgrid(x, y)
      Z1 = bivariate_norma l(X, Y, 1.0, 1.0, 0.0, 0.0)
      Z2 = bivariate_norma l(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


      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


      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

      Comment

      Working...