RuntimeError: _image_module

John Hunter wrote:

Try installing the latest release (0.83.2),
removing your ~/.matplotlib/tex.cache, and rerunning your script.

i still get the problem:

root@...734...:~/install/matplotlib-0.83.2/examples# rm -rf /root/.matplotlib/tex.cache

root@...734...:~/install/matplotlib-0.83.2/examples# python2.4
Traceback (most recent call last):
  File "", line 31, in ?
  File "/usr/lib/python2.4/site-packages/", line 773, in savefig

  File "/usr/lib/python2.4/site-packages/matplotlib/", line 636, in savefig
    self.canvas.print_figure(*args, **kwargs)
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 179, in print_figure
    agg.print_figure(filename, dpi, facecolor, edgecolor, orientation)
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 444, in print_figure
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 381, in draw
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 511, in draw
    for a in self.axes: a.draw(renderer)
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 1387, in draw
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 552, in draw
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 151, in draw
    if self.label1On: self.label1.draw(renderer)
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 848, in draw
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 335, in draw
    bbox, info = self._get_layout(renderer)
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 184, in _get_layout
    w,h = renderer.get_text_width_height(
  File "/usr/lib/python2.4/site-packages/matplotlib/backends/", line 241, in get_text_width_height
    Z = self.texmanager.get_rgba(s, size, dpi, rgb)
  File "/usr/lib/python2.4/site-packages/matplotlib/", line 296, in get_rgba
    X = readpng(pngfile)
RuntimeError: _image_module::readpng could not open PNG file /root/.matplotlib/tex.cache/30565a8911a6bb487e3745c0ea3c8224_120.png for reading

root@...734...:~/install/matplotlib-0.83.2/examples# ls -l /root/.matplotlib/tex.cache/
total 8
-rw-r--r-- 1 root root 204 Aug 17 12:51 30565a8911a6bb487e3745c0ea3c8224.dvi
-rw-r--r-- 1 root root 160 Aug 17 12:51 30565a8911a6bb487e3745c0ea3c8224.tex

the problem -- on the surface -- appears to be that readpng is looking for an existing file, but with _120 prepended to the . extension.

les schaffer


is there a way to get an image of a patch? I'd like to use patches to display Regions Of Interest and
also use then use them as masks on the image for subsequent region based analysis.



===== code snippet ======

#!/usr/bin/env python

import wasabi, ugm
import pylab


# 22-frames * 90-slices * 128-y * 128-x
dy = ugm.ugm('dy22.img')

# grab the 20th frame
vol = dy.vol([20])

# returns a series of roi's that are defined as a set of vertices of a polygon
# eg.
# roi['cerebellum'] = numarray.array([[x0,y0], [x1,y1], ...., [xN, yN]])
# roi['caudate'] ...
roi = wasabi.roi('p2873s0_HAW_emdy22.xml')

ax = pylab.gca()
n = 0
col = 'rgbcmyk'
p = []
for fld in roi.keys() :
# draw the polygon regions as patches with transparency
     p.append(ax.fill(roi[fld][:,0], roi[fld][:,1], col[n], alpha=0.5, linewidth=0))
     n += 1
#end for
pylab.imshow(vol[45,:,:], cmap =, origin = 'lower')
print p

# is there a way to 'get' an array of pixels set in the patches p[0], p[1] so that they can be used as masks
# on the image.