matploblib communication problem, graphics question

17 views
Skip to first unread message

wolf

unread,
May 23, 2008, 3:13:38 PM5/23/08
to pyglet-users
matploblib communication problem, graphics question
==========================================

i've had a hard time today to drill down on some infos
about matplotlib of http://matplotlib.sourceforge.net/.
this is an sf.net-managed project, its mailing lists are
managed by <shudder/> gnu mailman in a pre-1994 version.

still there is a sf.net standard forum interface, which
however denies me to post. i've set up an account on
sourceforge---not an experience i need; boarding an
intercontinental flight is swift in comparison.

but having an account on sf.net is not enough to post to
a mailing list there, so i filled out a second longish
form to subscribe to the list thru the <horrors/>
mailman interface. i had to re-enter my email address.

now what is left to me is to try writing directly to
matplotl...@lists.sourceforge.net and then scoop
it up on http://sourceforge.net/mailarchive/forum.php?forum_name=matplotlib-users

as it is so incredibly hard to make oneself heard on
the matplotlib list, i realized that questions from
outsiders are maybe not welcome, so i do a cross-post
to reach more audience.

i need to do some raster-image scaling and i've been
hunting hi and lo for a python library that can do that.
so far choices are (in order of perceived aptness)::

imagemagick of old,

pythonware.com/products/pil,

antigrain.com,

matplotlib,

cairo of cairographics.org.

Cairo is definitely may favorite here. i know with
certainty that cairo is good at scaling images, as
firefox3 is using it to achieve a smoothness and
readability in scaled images that rivals the quality
of safari’s.

but i have been unable to uncover any information
about raster-image scaling in cairo---can’t be, right?
an open source project that becomes part of firefox3
and i can’t find out how to use their flagship
functionality?

so i went to matplotlib. i now have these methods to
open image files with matplotlib::

def get_image_jpg():
import Image
from pylab import *
import numpy
print dir( numpy )
from numpy import int8, uint8
# these lines are incredible -- just open that damn jpg. can be as
simple as `load(route)` -- ALL the pertinent
# information well be in time derived from the route and the
routed resource structure (the router, and the
# routee). pls someone giveme a `MATPLOBLIB.read()`, a
`MATPLOBLIB.load()`, or a `MATPLOBLIB.get()` already.
image = Image.open( image_locator )
rgb = fromstring( image.tostring(), uint8 ).astype( float ) /
255.0
# rgb = resize( rgb,( image.size[ 1 ], image.size[ 0 ], 3 ) )
rgb = resize( rgb,( 100, 150, 3 ) )
imshow( rgb, interpolation = 'nearest' )
axis( 'off' ) # don’tdisplaytheimageaxis
show()

def get_image_png( image_locator ):
from pylab import imread as _read_png
from pylab import imshow as _show_image
from pylab import gray
from pylab import mean
a = imread( image_locator )
#generates a RGB image, so do
aa=mean(a,2) # to get a 2-D array
imshow(aa)
gray()

quite incredible, right? it can somehow be done, but
chances are you drown in an avalanche of boiler plate.
and sorry for the shoddy code, i copied it from their
website.

so they use pil to open an image file. pil’s image
scaling is 1994, and the package is hardly maintained
and not open. yuck. whenever you have a question
about imaging in python people say ‘pill’ like they
have swallowed one.

let’s face it, pil is a bad choice to do graphics.
here i did install pil, because matplotlib seemed to
be basically handling raster-images and image
transformations.

the matplotlib people have the nerve to put a short
doc to their root namespace items, as are, `axhspan`,
`cla`, `gcf`, and such more. this interface is
hardly usable. it shouldn’t be that hard to open an
image file in an image manipulation library. nobody
wants to maintain that kind of sphpaghetti.

i haven’t been succesful so far to find out how to
scale an image in cairo or matlotlib, or an other
alternative. please don’t sugggest doing it with
pil or imagemagick, i won’t answer.

is there any coherent python imaging interest group
out there? can i do it with pyglet maybe?

cheers & ~flow




Drew Smathers

unread,
May 23, 2008, 3:53:57 PM5/23/08
to pyglet...@googlegroups.com
On Fri, May 23, 2008 at 3:13 PM, wolf <wolfga...@gmail.com> wrote:
>
> matploblib communication problem, graphics question
> ==========================================
>
> i've had a hard time today to drill down on some infos
> about matplotlib of http://matplotlib.sourceforge.net/.
> this is an sf.net-managed project, its mailing lists are
> managed by <shudder/> gnu mailman in a pre-1994 version.
>
> still there is a sf.net standard forum interface, which
> however denies me to post. i've set up an account on
> sourceforge---not an experience i need; boarding an
> intercontinental flight is swift in comparison.
>
> but having an account on sf.net is not enough to post to
> a mailing list there, so i filled out a second longish
> form to subscribe to the list thru the <horrors/>
> mailman interface. i had to re-enter my email address.
>
> now what is left to me is to try writing directly to
> matplotl...@lists.sourceforge.net and then scoop
> it up on http://sourceforge.net/mailarchive/forum.php?forum_name=matplotlib-users
>
> as it is so incredibly hard to make oneself heard on
> the matplotlib list, i realized that questions from
> outsiders are maybe not welcome, so i do a cross-post
> to reach more audience.
>

I have some guesses as to why you're having trouble making yourself heard.

Is this your question? What do you mean by "coherent python imaging
interest group"?

Cheers,
-Drew

Brian Fisher

unread,
May 23, 2008, 4:21:51 PM5/23/08
to pyglet...@googlegroups.com
This isn't a very pyglet-y question at all... in fact it's rather un-pyglet-y...

Your list is missing pygame though - which may be one of the simplest options. Info on their mailing list is here:
http://www.pygame.org/wiki/info

to address how to do what you want, either this:
http://www.pygame.org/docs/ref/transform.html#pygame.transform.smoothscale
or this:
http://www.pygame.org/docs/ref/transform.html#pygame.transform.rotozoom
can do raster image scaling/resampling.

loading an image is a one liner using this:
http://www.pygame.org/docs/ref/image.html#pygame.image.load

note though that version 1.8 has a pretty annoying image saving bug where It only saves as tga or jpeg or something like that, which is fixed in the prerelease 1.8.1

wolf

unread,
May 23, 2008, 6:22:55 PM5/23/08
to pyglet-users
ok i just want to reize an image.

i have used pyglet before to write http://code.google.com/p/suimm and
i quite liked it. image handling capabilities were superior, and sound
was not so difficult either.

so can pyglet just do that? sorry for the long post but its incredible
what i am supposed to do to scale an image in python. make my post
shorter but it did take me three hours and right now i am sitting here
discussing protocols.

your docs were quite good so i'll be back to read those.

the public interfaces in python imaging tools are not very accessible.
pretty much insider stuff that. hey it's important. firefox3 scales
images with cairo, cairo has a python interface, so how do i scale an
image? you guys are using cairo as far as i remember----wrong? pyglet
is maybe the most promising python media framework so it can scale an
image, no?

cheers and ~flow

PS

> > outsiders are maybe not welcome, so i do a cross-post
> > to reach more audience.
> I have some guesses as to why you're having trouble making yourself heard.

thanks for the support and the sarcastics alike, it has been too
dificult before and it is being too difficult right now to find out
about this question. pls refrain from denouncing asking around. sorry
to post so long but you can stop reading it.

Dave LeCompte

unread,
May 23, 2008, 6:37:13 PM5/23/08
to pyglet...@googlegroups.com
On Fri, May 23, 2008 at 3:22 PM, wolf <wolfga...@gmail.com> wrote:

ok i just want to reize an image.

I have always used Python Image Library (PIL) for that sort of thing, especially for non-interactive tools.


so can pyglet just do that?

It seems like Pyglet is a poor choice for just doing image manipulation. If you're attempting to make an immersive media experience, it might be a better fit.

 
the public interfaces in python imaging tools are not very accessible.
pretty much insider stuff that. hey it's important.

I'm not sure I understand what you're saying here - are you saying that it's hard to find documentation for PIL? Or that the process for using PIL is cumbersome? I would disagree with each claim. Check out, in particular, the "Create JPEG Thumbnails" example here:
http://www.pythonware.com/library/pil/handbook/introduction.htm

Seems like a great first pass for resizing images, depending on your needs.

-Dave LeCompte

Brian Fisher

unread,
May 23, 2008, 6:39:37 PM5/23/08
to pyglet...@googlegroups.com
On Fri, May 23, 2008 at 3:22 PM, wolf <wolfga...@gmail.com> wrote:

ok i just want to reize an image.

i have used pyglet before to write http://code.google.com/p/suimm and
i quite liked it. image handling capabilities were superior, and sound
was not so difficult either.

so can pyglet just do that?
 
can pyglet resize an image?

well pyglet provides facilities to use openGL to tell the hardware to resample an image when drawing it to the screen as a texture, yes.

Is image processing and manipulation in software a part of it's feature-set, ala pyCairo or PIL? definitely not.

If you are trying to resize and save, you go through extra hoops to do it through openGL hardware vs. software based systems, but it can definitely be done with pyglet. (basically you'd upload as a texture, render to a texture, save out the texture, then save the image, and saving may be hard). But doing the same thing through pygame is pretty easy and straightforward, cause it's been made a core part of it's feature-set to load, resize and save.

Drew Smathers

unread,
May 23, 2008, 9:11:00 PM5/23/08
to pyglet...@googlegroups.com

No problem :-)

Use PIL ... or Imagemagick ... or PyGame. Done.

--
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/ \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\ /\\\ \\
/ /\\\ /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
d.p.s

wolf

unread,
May 24, 2008, 5:45:05 AM5/24/08
to pyglet-users

> Use PIL ... or Imagemagick ... or PyGame. Done.

> If you are trying to resize and save, you go through extra hoops to do it

> It seems like Pyglet is a poor choice for just doing image manipulation.

ok, for the practical part. i'm doing it with PIL right now, it works,
and it looks more decent than before since i discovered i can say
`Image.open( route ); image.thumbnail( size, 3 )` (the essential bit
of information here is to throw in a `3` for a cubic scaling algo).

thanks everyone for bearing with me, this solution helps me to make my
day. i'm happy so far.

next, if pyglet does not tackle image manipulation (and it doesn't use
cairo, right? -- had gotten that one wrong) then obviously i've landed
on the wrong helipad here. oops and desculpas las molestas. thanks for
the many fast replies on this list anyhow.

now for why i ranted, and what for.

(1) i do not especially like pil. one reason is the statement they put
up in front: "This is the PIL handbook, last updated May 6, 2005".
that's 3 x 7 = 21 years for a cat since the last update. few cats live
that long, and i'd say pil is outdated simply because public releases
are too old. what helps me a bit is that in fact there are binary
releases for python 2.5, and there is an aggdraw module on
http://effbot.org/zone/aggdraw-index.htm. however, these efforts are
seemingly one-man shows or almost so; the aggdraw thing is dated
2006-02-12 (2.25 x 7 = 15.75 cat years).

i want to move to python3 as soon as reasonably feasable, and right
now the pil library maintenance scheme does not look like it's a
terribly python-3000-savvy horse to put my money on.

(2) about interfaces:

> > the public interfaces in python imaging tools are not very accessible.

> I'm not sure I understand what you're saying here - are you saying that it's
> hard to find documentation for PIL? Or that the process for using PIL is

ok the pil experience has been somewhat lighter now than what i have
found before. my experience with pil is that you hit a hard wall
sooner or later when you use it. it's more or less unmaintained, bugs
and shortcomings have not been addresses in fifteen catlives, and
they're not likely to be addressed for many manmonths to come.

i want to transport that (a) imaging is important, (b) python imaging
is important (c) many ways to do it are too hard to use, too old, or
both.

look, i spent several hours to get my a simple question across the
fence for the matplotlib people, and i still can't see it---that's
basically a gated community. not good. their interfaces are also
incredibly convoluted:

import Image
from pylab import *
from numpy import int8, uint8
image = Image.open( image_locator )
rgb = fromstring( image.tostring(), uint8 ).astype( float ) / 255.0
rgb = resize( rgb,( image.size[ 1 ], image.size[ 0 ], 3 ) )
imshow( rgb, interpolation = 'nearest' )
axis( 'off' )
show()

this is about what you need to open a jpg image in a python charting
library (it's more charting than imaging, but they seem to have a lot
of relevant tools on board). ok, we've done loading and scaling in pil
before, and since we still rely on pil with the above example, there's
little point in doing it in this way. but hold on for the aside.

<aside>please notice that those `imshow()` and `axis()` calls are
almost certainly not threadsafe, as they lack an explicit object of
reference. brace yourselves if you want to use this in a wsgi
application. the line `resize( rgb,( image.size[ 1 ], image.size[ 0 ],
3 ) )` seems to turn around x- and y-axis, i wonder why. i saw some
code in pil that queries the machine for being small-endian or big-
endian, so maybe this line must be checked for endian-ness dependency.
the methodology of the snippet above is unacceptable; it is neither
object-oriented nor library-oriented programming nor anything else
than sphpagetthi. yuck.

ok, matplolib is out for three reasons: (1) they can't document well,
http://www.scipy.org/Cookbook/Matplotlib/AdjustingImageSize is hardly
gullible, other docs similar. (2) they can't be talked to, as they
have locked away their open-source project behind the gates of
sourceforge and mailman. sf.net is hardly reachable and hardly usable,
and mailman lists are unacceptable for the purposes of open-source
communications. a gated community as i said. try to post to their list
and you'll see what i mean. my message is still awaiting approval to
appear on the list, and i filed *two* forms to obtain *two*
memberships. (3) their interface is too weird (see above), and their
code depends on implicit globals and pil to work.</aside>

i will try to get some cairo people to talk to me. right now it's not
very accessible either, and they like to point out the C source docs.
omg. and thanx a lot for the pygame pointer, i'll have a look.

i believe that **raster (and vector) image manipulation must become
one of python's included batteries,** and it should be easy (happily
all the 'Access to Sun audio hardware'-style modules are 90% on their
way out of the standard library).

i know it can be done. **cairo does image handling for firefox3, and
there is a python interface for cairo.** should be a piece of cake,
right? ok wrong helipad here, sorry for posting so long again.

cheers and ~flow




Andrew Straw

unread,
May 24, 2008, 1:00:22 PM5/24/08
to pyglet...@googlegroups.com
wolf wrote:
> < lots snipped >

> look, i spent several hours to get my a simple question across the
> fence for the matplotlib people, and i still can't see it---that's
> basically a gated community. not good.
Yes, they have specifically chosen a highly obscure open-source hosting
website. Virtually no one has heard of SourceForge and it has only 8
years of history and 1.8 million users in the open source community.
Clearly the matplotlib developers hoped to avoid attracting users,
generating discussion, or, worst of all, forming a community. Despite
all the layers of security protecting the project, hundreds have already
subscribed and posted to the mailing list. I have no idea how those
users managed.

> their interfaces are also
> incredibly convoluted:
>
> import Image
> from pylab import *
> from numpy import int8, uint8
> image = Image.open( image_locator )
> rgb = fromstring( image.tostring(), uint8 ).astype( float ) / 255.0
> rgb = resize( rgb,( image.size[ 1 ], image.size[ 0 ], 3 ) )
> imshow( rgb, interpolation = 'nearest' )
> axis( 'off' )
> show()
>

That is convoluted. The following isn't (modified from the
image_demo3.py example script distributed with matplotlib for years):

import Image
import pylab
im=Image.open('/Users/astraw/Desktop/PC040235.jpg')
pylab.imshow(im)
pylab.axis('off')
pylab.show()

wolf

unread,
May 25, 2008, 7:16:17 AM5/25/08
to pyglet-users

On May 24, 7:00 pm, Andrew Straw <ast...@caltech.edu> wrote:
> website. Virtually no one has heard of SourceForge and
> it has only 8 years of history and 1.8 million users
> in the open source community. Clearly the matplotlib
> developers hoped to avoid attracting users, generating
> discussion, or, worst of all, forming a community.
> Despite all the layers of security protecting the
> project, hundreds have already subscribed and posted
> to the mailing list. I have no idea how those

andrew, your points are valid, but i know what i’ve done
countless times, like sifting through mailing lists on
sf.net, dealing with <shudder/> mailman subscriptions
etc. -- mailman was great in the nineties, but now we have
google groups who set the standard in mailing list
accessibility. not suggesting everyone now move to big
brother google, but there are alternatives.

anyhow, thanks for going through the trouble to find
the example code for me. i immediately went to sf.net to
download the source *.tgz separately (i don't think the
examples are installed when doing easy_install *.egg).

ok so this is image_demo3.py, ever so slightly edited to
preserve the original’s intent:

from pylab import *
import Image

pyl_image = Image.open('c:/temp/Guilloche.jpg')
dpi = rcParams['figure.dpi']
figsize = ( pyl_image.size[0] / dpi, pyl_image.size[1] / dpi, )
figure( figsize = figsize )
mpl_image = imshow(pyl_image, origin='lower')
savefig( 'c:/temp/Guilloche-modified.jpg' )

thanks for shortening this for me (here for comparison your much
leaner
code):

> import Image
> import pylab
> im=Image.open('/Users/astraw/Desktop/PC040235.jpg')
> pylab.imshow(im)
> pylab.axis('off')
> pylab.show()

you did manage to take out some complexities. there's no scaling
operation involved in your example, and no saving of the image. i have
to load, scale, and save a raster image, that's the task. the original
example fails with:

Traceback (most recent call last):
File "C:\temp\try-matplotlib.py", line 9, in <module>
savefig( 'c:/temp/Guilloche-modified.jpg' )
...
ValueError: Format "jpg" is not supported.
Supported formats: emf, eps, pdf, png, ps, raw, rgba, svg, svgz.

ah yeah, was a bad idea right from the start to believe a math
plotting library would supply saving to *.jpg. well i now do it
in pil (`import Image`) altogether, includeing the image sacaling,
so i sidestepped that part.

but pls. observe that the data flow in both our examples is
at the least unintuitive: basically we both do

image = Image.open( '/foo/bar.jpg ) #1
pylab.imshow( image ) #2
pylab.axis('off') #3a
savefig( '/foo/baz.jpg' ) #3b

stepa #1 and #2 are ok so far. but steps #3a and #3b
both lack an explicit mention of the image at hand.

it remains obscure where the context is
derived from. my schoolmarm always warned me against
introducing this kind of hidden (global?) states, and
matplotlib uses a lot of it. the suspicion is that 1) i’ll run
into difficulties as soon as i handle more than one image
at any one given time, and that 2) this code is not threadsafe,
and can never be.

because of point 2, threadsafeness, if i want to use
this approch inside a web application, i will have to
take care any image processing is done only one
at any given time. barb.

ah, wrong place for this discussion, this is pyglet, not
matplotlib. not going to bother you guys no more with
that.

it's just so disappointing when you try to find
packages that bring accessible, no-nonsense image
handling capabilities to python, and you find a lot of
code, but little of it being readily usable, actively
maintained and so on. pygame was pointed out earlier,
cairo too, so that's the next things for me to look to.

the pyglet library did impress me for one. keep up the
good work. thx for the support.

cheers & ~flow


PS. ah yes someone suggested imagemagick to me earlier.

i have written a webservice for our company where you
can obtain images of headlines. works with imagemagick.

the headaches incurred in absorbing the relevant
documentation have been tremendous so far. imagemagick’s
(command-line) interface has wholly gone overboard. you
never know whether to put a minus, or a plus, or what
else, in front of your option letter, and whether to
quote your argument or not, and exactly what ‘special’
characters will be allowed and interpreted correctly:

convert -gravity South
caption:'Caption'
text:-'[0]'
-size 320x100 xc:lightblue
-trim +repage
-draw "fill tomato circle 250,30 310,30 text 0,0 'TEXT'"
-resize 64x64\!

(you see they have designed a drawing primitives sub-
language that goes into a string passed to `-draw`.
weird stuff that. overboard.)

to say something nice about this package, the example @
http://www.imagemagick.org/Usage/resize/#liquid-rescale
is a bit impressive: content-aware scaling, wow. but a
command-line interface convoluted as this is definietly
not the way to go. not me.


infinite8s

unread,
May 26, 2008, 11:16:24 AM5/26/08
to pyglet-users

This is completely the wrong forum for most of this post, but anyway I
would just like to correct a misunderstanding about the pylab
interface in matplotlib (since I use it to great effect for making
graphs of my research).

> but pls. observe that the data flow in both our examples is
> at the least unintuitive: basically we both do
>
> image = Image.open( '/foo/bar.jpg ) #1
> pylab.imshow( image ) #2
> pylab.axis('off') #3a
> savefig( '/foo/baz.jpg' ) #3b
>
> stepa #1 and #2 are ok so far. but steps #3a and #3b
> both lack an explicit mention of the image at hand.
>
> [lots of complaints about threadsafeness]

Talk about trying to use a hammer to screw a screw. The pylab
interface was designed to help people familiar with Matlab move over
to using matplotlib. A lot of it is simple syntactic sugar over the
matplotlib graphing system. There are many examples of building
specialized GUI's using matplotlib widgets. Now one valid complaint is
that the object oriented class structure isn't well documented, but
then being an opensource project, people work on what they need. But
the pylab interface (combined with scipy) is very good for interactive
exploration and graphing of data.

> [Stuff about imagemagick]

This is what I don't get about people who want to use open-source
software. If it doesn't fit your needs, complaining won't do anything.
Either contribute it yourself, or pay someone to add what you need!

Sorry for the rant. Hopefully this thread can end here.
Reply all
Reply to author
Forward
0 new messages