I'm brand new to Sage, and would like to follow the path of least
resistance to playing around with images.  I tried to follow these
instructions, but got tripped up.

On May 23, 7:55 am, "David Joyner" <[EMAIL PROTECTED]> wrote:
> Harald:
>
> I know this is an old question but my feeling was in wasn't really
> answered properly,
> possibly because I inadvertantly took it off track with a response
> which had an aside on
> SAGE searching.
>
> Since PIL has come up a few times on SAGE lists in vague ways, I
> thought I'd try to
> be more detailed. Here is a way using SAGE which might help. First,
> it requires some preparation.
>
> I'll assume you have installed sage in SAGEROOT (an absolute
> pathname). (I'm going
> to go into more detail that I know you need Harald since I hope to help others
> who might know less about SAGE too).
>
> You must install PIL fromhttp://www.pythonware.com/products/pil/. Here's how:
>
> (a) download the tarball from a link on the URL mentioned above, 
> sayhttp://effbot.org/downloads/Imaging-1.1.6.tar.gz;
> (b) extract it to SAGEROOT/local/lib/python/site-packages
> (c) cd SAGEROOT/local/lib/python2.5/site-packages/Imaging-1.1.6
> (d) run  ../../../../bin/python setup.py install

Instead of doing this, I ran

sage -i PIL-1.1.5.spkg

per the instructions of Simon King.  So far so good.

> (e) install ImageMagick (unless you have xv installed, which you
> probably don't);
> in ubuntu, it's
> sudo apt-get install imagemagick (or sudo apt-cache search
> imagemagick, and install
> a bunch of related packages too);
> (f) in sage, type
> sage: from PIL import Image
> sage: im = Image.open("PATH/mypic.jpg")

I'm good up to this point.  im is an object with a bunch of methods
that I can look at with tab completion.

> sage: im.show(command="display")

No dice.  I get the following Traceback:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/jm843/.sage/sage_notebook/worksheets/admin/0/code/
31.py", line 6, in <module>
    im.show(command="display")
  File "/Applications/sage/local/lib/python2.5/site-packages/sympy/
plotting/", line 1, in <module>

  File "/Applications/sage/local/lib/python2.5/site-packages/PIL/
Image.py", line 1349, in show
    _showxv(self, title, command)
  File "/Applications/sage/local/lib/python2.5/site-packages/PIL/
Image.py", line 1913, in _showxv
    file = image._dump(format=format)
  File "/Applications/sage/local/lib/python2.5/site-packages/PIL/
Image.py", line 429, in _dump
    self.load()
  File "/Applications/sage/local/lib/python2.5/site-packages/PIL/
ImageFile.py", line 180, in load
    d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
  File "/Applications/sage/local/lib/python2.5/site-packages/PIL/
Image.py", line 328, in _getdecoder
    raise IOError("decoder %s not available" % decoder_name)
IOError: decoder jpeg not available

I'm on a mac here, and I already had ImageMagick installed through
MacPorts.  Since the above didn't work, so i also installed xv.
Macports installs things into /opt/local/bin

jmerrill:~ jm843$ which xv
/opt/local/bin/xv

I have /opt/local/bin on my searchpath when I open a terminal, but I
suspect Sage just doesn't know where to find this stuff.  I tried
running

sys.path.append('/opt/local/bin')

from within a notebook, but it doesn't seem to change anything.

> Of course, im.[TAB] gives you more commands to play with and the online 
> tutorialhttp://www.pythonware.com/library/pil/handbook/introduction.htm
> helps too.
>
> Hope this is more helpful, even if it a little late.
>
> - David Joyner

I'm grateful for any suggestions.  Is PIL the easiest route to playing
around with images?  I'd really like to be able to get a grayscale
image into an array of numbers so that I can play with convolutions
and thresholding and the like.

Regards,

Jason Merrill

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/sage-support
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to