-Sebastian
what kind of images are you trying to align ?
I was just about to send you my module, when I found that it could not
handle a simple test image that I tried -- something like this:
>>> import simplex
>>> a = F.gaussianArr(shape=(256, 256), sigma=30, peakVal=1, orig=(100,100))
>>> b = F.ringArr(shape=(256, 256), radius1=20, radius2=40, orig=(50,80))
>>> stack = [a,b]
>>> simplex.doAlign(stack, z0=0, z1=1, doAnIso=True, mexSize=0)
"simplex.py" is the module that we have been using for quite some time
.... but it seems to be "broken" right now ..... I'm very puzzled :-(
Anyway, you could also try to do the follow using scipy:
>>> from scipy import optimize
>>> x0 = 10,10,0,1,0,1
>>> zzr = N.array((a,b,b))
>>> def func(x):
tx, ty, rot, mag, gmag2_axis, gmag2 = x
U.trans2d(zzr[1], zzr[2], (tx, ty, rot, mag, gmag2_axis, gmag2))
return 1.-U.S.correlate(zzr[0], zzr[2])
>>> optimize.fmin(func, x0, args=(), xtol=0.0001, ftol=0.0001, maxiter=None, maxfun=None, full_output=0, disp=1, retall=0, callback=None)
Optimization terminated successfully.
Current function value: 0.016701
Iterations: 424
Function evaluations: 714
[ -5.903 -57.7474 0.0122 0.9248 -0.0087 1.1582]
zzr is here an array of shape 3,256,256: the idea is to align zzr[1]
to zzr[0] and putting the aligned version (tranform of zzr[1]) into
zzr[2]
This can then nicely be viewed using Y.view2(zzr)
If you don't want an anisotropic transformation (i.e. no shearing,
only translation, rotation and magnification), remove the trailing 0,1
of x0 and adjust the first two lines of func.
Note that the angle "rot" is given in degrees.
However even the scipy.optimize.fmin did not work as good as I
expected -- something is still wrong ...
Here is a small screenshot - made with these test images:
>>> a = F.gaussianArr(shape=(256, 256), sigma=30, peakVal=1)
>>> aa=a.copy()
>>> bb=a.copy()
>>> U.trans2d(a,aa, (0, 0, 0, 1, 0, 1.5))
>>> U.trans2d(b,bb, (20, 50, 0, 1, 0, 1.5));U.trans2d(bb.copy(),bb, (0, 0, 25, 1, 0, 1))
-Sebastian
Many thanks for the example. I will play around with it.
My images are cryostat-microtome brain sections, photographed (grey
scale) with normal bright light.
Thanks again,
Gabriel
On Thu, 2008-10-02 at 15:05 +0200, Sebastian Haase wrote:
> Hi Gabriel,
>