I was wondering if you could give me an advice.
I have a np array with X and Y coordinates of spots that I would like
to draw as gaussians into a texture. Do you have an advice of how to
do this in glumpy?
Also, if we now make the spots 3D, is there to make them a gaussian
whose diameter is larger in the Z-axis compared to the X or Y?
I'm not sure of what you mean by "drawi as Gaussians". Do you mean
that each x,y couple is the center of Gaussian ?
Ricardo Henriques, PhD
Institut Pasteur (Paris, France).
For contact information see: https://sites.google.com/site/paxcalpt/
import numpy as np
import matplotlib.pyplot as plt
def gaussian(d, sigma=1.0):
p = 10
n = 256
xmin, xmax = -1.0, +1.0
ymin, ymax = -1.0, +1.0
dx = (xmax-xmin)/n
dy = (ymax-ymin)/n
X,Y = np.meshgrid(np.arange(xmin,xmax,dx),
Xg = np.random.uniform(xmin,xmax,p)
Yg = np.random.uniform(xmin,xmax,p)
Z = np.zeros((n,n), dtype=np.float32)
for i in range(p):
D = np.sqrt((X-Xg[i])**2+(Y-Yg[i])**2)
# Add gaussians...
# Z += gaussian(D, sigma=0.1)
# ... or take maximum
Z = np.maximum(Z, Z+gaussian(D, sigma=0.1))
Here's my options as I see them:
- Draw a gaussian into a numpy matrix, convert into texture, then
apply the texture to each spot in space.
- Use a glPoint for each spot, enlarge them via glPointSize to have
the gaussian size, but then apply some kind of intensity decay coming
from the center of the spot (don't know how to do this final part).
Currently I'm drawing million of gaussian-shaped spots into numpy
arrays then plotting them through glumpy, I do this in Cython - being
already reasonably fast, but it would even be faster if I directly
used GL to render the spots.
Here's how I'm doing it:
for p in range(nspots):
... # grab x0, x1, y0, y1 as the vicinities of the spots
... # grab xc, yc as the centers of the spot
for i in range(x0, x1):
for j in range(y0, y1):
# here comes the 2d gaussian equation
v = 10*math.exp(-((i-xc)**2+(j-yc)**2)/(2*sigma_xy**2))
#math.exp is a direct cython-c call
rec[i, j] += v
# rec is the numpy array where I draw the spot
Do you think glPoints or textures would be a good replacement?
Otherwise to draw it into a numpy array means that I have to iterate
through a large number of pixels, then render the final array in
Ok, I understand better your problem.
The best option (for 2d display) would be to draw a simple rectangle
for each gaussian center and texture it with a gaussian texture.
This also depends on the information you want to draw for each
gaussian. If each gaussian is the same, this would work. If you need a
different texture for each gaussian, that might be a bit more tricky.
For 3D display, you can do the same using billboarding (rectangle is
always facing the camera) but you would have to z-sort rectangle
because of transparency.
Another posible option is to use instanced objects and this would
require a recent video card.
Last option is to use shaders.
This depends on the level of performance you need to achieve (but a
million object is quite a lot anyway).
P.S.: Can you subscribe to the group ? (because currently I have to
moderate (=accept) all your messages).
I thought I was already registered to the group :/.
On Dec 9, 4:30 pm, Ricardo Henriques <paxca...@gmail.com> wrote:
> Perfect, thanks for the help.
> If you're curious, you can check out what I'm trying to do in the
> first video ofhttp://code.google.com/p/quickpalm/- I'm basically