[Numpy-discussion] iterate along a ray: linear algebra?
Torgil Svensson
torgil.svensson at gmail.com
Mon Jul 3 16:39:04 CDT 2006
I've done something similar a few years ago (numarray,numeric). I
started roughly at the middle and did 64 points from a reference point
(xc,yc). This point together with a point at the edge of the image
(xp,yp) also defined a reference angle (a0). (ysize,xsize) is the
shape of the intensity image.
I used the following code to calculate points of interest:
na=64
xr,yr=xsize-xc,ysize-yc
a0=arctan2(yp-yr,xp-xc)
if a0<0: a0+=2*pi
ac=arctan2([yr,yr,-yc,-yc],[xr,-xc,-xc,xr])
if numarray:
ac[ac<0]+=2*pi
else:
ac=choose(ac<0,(ac,ac+2*pi))
a1,a2,a3,a4=ac
rmaxfn={
0: lambda a: a<=a1 and xr/cos(a-0.0*pi) or yr/cos(0.5*pi-a),
1: lambda a: a<=a2 and yr/cos(a-0.5*pi) or xc/cos(1.0*pi-a),
2: lambda a: a<=a3 and xc/cos(a-1.0*pi) or yc/cos(1.5*pi-a),
3: lambda a: a<=a4 and yc/cos(a-1.5*pi) or xr/cos(2.0*pi-a)
}
angles=arange(a0,a0+2*pi,2*pi/na)
if numarray:
angles[angles>=2*pi]-=2*pi
else:
angles=choose(angles>=2*pi,(angles,angles-2*pi))
nr=int(ceil(sqrt(max(yc,yr)**2+max(xc,xr)**2)))
crmax=array([int(floor(rmaxfn[floor(a*2/pi)](a))) for a in angles])
cr=outerproduct(ones(na),arange(float(nr)))
ca=outerproduct(angles,ones(nr))
x=cr*cos(ca)+xc
y=cr*sin(ca)+yc
After this I did cubic spline interpolation in the image with these
points and did something useful. I don't know how relevant this is to
you and it doesn't use the linear algebra package but it might give
you some hint.
If you find out a nifty way to do your rays please post on this thread.
Sidenote -- Watch my explicit float argument to arange and even
putting in pi there in one case. There's a discussion on this list
that floats in arange are troublesome
On 6/30/06, stephen emslie <stephenemslie at gmail.com> wrote:
> I am in the process of implementing an image processing algorithm that
> requires following rays extending outwards from a starting point and
> calculating the intensity derivative at each point. The idea is to find the
> point where the difference in intensity goes beyond a particular threshold.
>
> Specifically I'm examining an image of an eye to find the pupil, and the
> edge of the pupil is a sharp change in intensity.
>
> How does one iterate along a line in a 2d matrix, and is there a better way
> to do this? Is this a problem that linear algebra can help with?
>
> Thanks
> Stephen Emslie
>
> Using Tomcat but need to do more? Need to support web services, security?
> Get stuff done quickly with pre-integrated technology to make your job
> easier
> Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
> http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
>
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion at lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/numpy-discussion
>
>
>
More information about the Numpy-discussion
mailing list