MezzoNZ / crunchy

Automatically exported from code.google.com/p/crunchy
0 stars 0 forks source link

Image file anywhere #71

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
Currently, image files can only be created/displayed when there is the
appropriate vlam code.  This is similar to the approach previously used for
graphics, where a dedicated canvas was embedded following the appropriate
vlam.  

Just like we moved to the dynamic creation of a canvas, we could introduce
a dynamic creation of an image file.  The image filename could be
constructed from the uid; all we need is a button to load an image onto a
page once it is created.  The only limitation, perhaps, is that we may have
to limit the file type to a unique format (.pgn?) as the full file name
would presumably have to be known.  (adding yet another button to specify
the full path, etc., would probably clutter the ui too much).

Original issue reported on code.google.com by andre.ro...@gmail.com on 13 Dec 2007 at 8:20

GoogleCodeExporter commented 8 years ago
It seems to me that we could use the canvas in its current form for this. We 
just
need to add a couple of new functions to the graphics API - one to display an 
image
from a file, another from a string of bytes.

Original comment by johannes...@gmail.com on 19 Jan 2008 at 9:50

GoogleCodeExporter commented 8 years ago
Following suggestion from Comment 1, I implemented a simple function to do this
(revision 559).  To test: go to the graphics page (link on  left menu) and 
enter the
following code at an interpreter:

import graphics as g 
g.init_graphics()
g.display_image('ball.png')

I'm leaving this issue open as this method could be improved (for example, we 
could
have a function that does not require to call init_graphics() first.

Original comment by andre.ro...@gmail.com on 19 Jan 2008 at 10:28

GoogleCodeExporter commented 8 years ago
This method appears to work only with images normally accessible from the server
root.  We need to have a method that would work for images located on arbitrary
locations.

Original comment by andre.ro...@gmail.com on 19 Jan 2008 at 10:52

GoogleCodeExporter commented 8 years ago
It looks like a mixture of dynamic generation of an image element (like we do 
for the
canvas) and the vlam_image_file.py is likely to be a better and more flexible 
approach.

Original comment by andre.ro...@gmail.com on 19 Jan 2008 at 11:19

GoogleCodeExporter commented 8 years ago
Fixed with revision 560!!!

Here's an example that can be run from an editor (assuming matplotlib is 
installed)

import os
import image_display
chosen_path = os.path.expanduser("~")
os.chdir(chosen_path)

# assumes matplotlib is installed
import matplotlib.numerix as nx
import pylab as p

def boltzman(x, xmid, tau):
    """
    evaluate the boltzman function with midpoint 
    xmid and time constant tau over x
    """
    return 1. / (1. + nx.exp(-(x-xmid)/tau))

def fill_below_intersection(x, S, Z):
    """
    fill the region below the intersection of S and Z
    """
    #find the intersection point
    ind = nx.nonzero( nx.absolute(S-Z)==min(nx.absolute(S-Z)))[0]
    # compute a new curve which we will fill below
    Y = nx.zeros(S.shape, typecode=nx.Float)
    Y[:ind] = S[:ind]  # Y is S up to the intersection
    Y[ind:] = Z[ind:]  # and Z beyond it
    p.fill(x, Y, facecolor='blue', alpha=0.5)

x = nx.arange(-6, 6, .01)
S = boltzman(x, 0, 1)
Z = 1-boltzman(x, 0.5, 1)
p.plot(x, S, x, Z, color='red', lw=2)
fill_below_intersection(x, S, Z)

# save image and display it.
p.savefig("foo.png")

image_path = os.path.join(chosen_path, "foo.png")
image_display.show(image_path)

Original comment by andre.ro...@gmail.com on 20 Jan 2008 at 1:15