Menu

[r6270]: / trunk / htdocs / screenshots / layer_images.py  Maximize  Restore  History

Download this file

37 lines (27 with data), 949 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python
"""
Layer images above one another using alpha blending
"""
from __future__ import division
from pylab import *
def func3(x,y):
return (1- x/2 + x**5 + y**3)*exp(-x**2-y**2)
# make these smaller to increase the resolution
dx, dy = 0.05, 0.05
x = arange(-3.0, 3.0, dx)
y = arange(-3.0, 3.0, dy)
X,Y = meshgrid(x, y)
# when layering multiple images, the images need to have the same
# extent. This does not mean they need to have the same shape, but
# they both need to render to the same coordinate system determined by
# xmin, xmax, ymin, ymax
xmin, xmax, ymin, ymax = min(x), max(x), min(y), max(y)
extent = xmin, xmax, ymin, ymax
Z1 = array(([0,1]*4 + [1,0]*4)*4); Z1.shape = 8,8 # chessboard
im1 = imshow(Z1, cmap=cm.gray, interpolation='nearest',
extent=extent)
hold(True)
Z2 = func3(X, Y)
im2 = imshow(Z2, cmap=cm.jet, alpha=.9, interpolation='bilinear',
extent=extent)
show()
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.