Beispiel #1
0
def frm_fourier_constrained_vol(vf, mf, vg, mg):
    radius = vf.sizeX() / 2 - 3  # intepolation in the outer part is nonsense
    b = 32

    from pytom.basic.fourier import fft, ifft, ftshift, iftshift

    vf = ftshift(reducedToFull(fft(iftshift(vf, inplace=False))),
                 inplace=False)
    vg = ftshift(reducedToFull(fft(iftshift(vg, inplace=False))),
                 inplace=False)

    vfr = real(vf)
    vfi = imag(vf)
    vgr = real(vg)
    vgi = imag(vg)

    res = np.zeros((2 * b, 2 * b, 2 * b))
    for r in xrange(1, radius + 1):
        corr = frm_fourier_constrained_corr(vol2sf(vfr, r,
                                                   b), vol2sf(vfi, r, b), mf,
                                            vol2sf(vgr, r, b),
                                            vol2sf(vgi, r, b), mg, True)
        res += corr * (r**2)

    return res
Beispiel #2
0
    dummy4 = frm_corr(mf, mg)

    res = dummy1 / ((dummy2 * dummy3)**0.5 * dummy4)

    return res


dist = []
dist2 = []
for i in xrange(100):
    phi = np.random.randint(360)
    psi = np.random.randint(360)
    the = np.random.randint(180)
    rotateSpline(v, v2, phi, psi, the)

    sf = vol2sf(v, r, b)
    sf = sf * wedge
    sf2 = vol2sf(v2, r, b)
    sf2 = sf2 * wedge

    res = bart_way(sf2, wedge, sf, wedge)
    ang = frm_find_best_angle(res, b)
    dist.append(rotation_distance([phi, psi, the], ang))

    res = frm_constrained_corr(sf2, wedge, sf, wedge)
    ang = frm_find_best_angle(res, b)
    dist2.append(rotation_distance([phi, psi, the], ang))

    print dist[-1], dist2[-1]

print 'Diff: ', np.max(dist), np.mean(dist), np.min(dist), np.std(dist)
Beispiel #3
0
	# rotateSpline(v, v2, phi, psi, the)
	# fv2 = ftshift(reducedToFull(fft(iftshift(v2))))
	# res = frm_fourier_corr(vol2sf(real(fv2), r, b), vol2sf(imag(fv2), r, b), vol2sf(real(fv1), r, b), vol2sf(imag(fv1), r, b))

	# 2. rotate real and imag parts seperately and feed into the frm_fourier_corr
	fr = real(fv1)
	fi = imag(fv1)

	# rotateSpline(v, v2, phi, psi, the)
	# fv2 = ftshift(reducedToFull(fft(iftshift(v2))))
	# fr2 = real(fv2)
	# fi2 = imag(fv2)
	fr2 = vol(fr); rotateSpline(fr, fr2, phi, psi, the)
	fi2 = vol(fi); rotateSpline(fi, fi2, phi, psi, the)

	fr = np.array(vol2sf(fr, r, b))
	fi = np.array(vol2sf(fi, r, b))
	fr2 = np.array(vol2sf(fr2, r, b))
	fi2 = np.array(vol2sf(fi2, r, b))

	fr2 = fr2 * w
	fi2 = fi2 * w

	res = frm_fourier_corr(fr2, fi2, fr, fi, return_real=True)

	# 3. add two volumes and get the final result
	# res = frm_constrained_corr(fr2, w, fr, m) + frm_constrained_corr(fi2, w, fi, m)
	
	ang = frm_find_best_angle(res, b)
	dist.append(rotation_distance(ang, [phi, psi, the]))
import numpy as np
from sh.soft import *
from sh.frm import *
from pytom.tools.maths import rotation_distance
from pytom_volume import *
from sh.vol2sf import vol2sf

b = 16

v = read('/fs/home/ychen/matlab/template/binning/temp80SRibosome_bin2.em')
v2 = vol(v)
r = 8
for i in xrange(100):
	phi = np.random.randint(360)
	psi = np.random.randint(360)
	the = np.random.randint(180)

	f = vol2sf(v, r, b)
	rotateSpline(v, v2, phi, psi, the)
	g = vol2sf(v2, r, b)

	# 1. the soft way
	res = soft_corr(g, f)
	ang = soft_find_best_angle(res, b)

	# 2. the frm way
	# res = frm_corr(g, f)
	# ang2 = frm_find_best_angle(res, b)

	print rotation_distance(ang, [phi, psi, the]) #, rotation_distance(ang2, [phi, psi, the]), rotation_distance(ang, ang2)
Beispiel #5
0
t = timing()

t.start()

dist = []
dist2 = []
for i in xrange(100):
    phi = np.random.randint(360)
    psi = np.random.randint(360)
    the = np.random.randint(180)
    rotateSpline(
        v, v2, phi, psi, the
    )  # you cannot expect very high accuracy, since we are using spline interpolation here

    sf = np.array(vol2sf(v, r, b))
    sf = sf * wedge
    sf2 = np.array(vol2sf(v2, r, b))
    sf2 = sf2 * wedge

    res = frm_corr(sf2, sf)
    ang = frm_find_best_angle(res, b)
    dist.append(rotation_distance([phi, psi, the], ang))

    res = frm_constrained_corr(sf2, wedge, sf, wedge)
    ang = frm_find_best_angle(res, b)
    dist2.append(rotation_distance([phi, psi, the], ang))

# print 'Diff: ', np.max(dist), np.mean(dist), np.min(dist), np.std(dist)
# print 'Diff2: ', np.max(dist2), np.mean(dist2), np.min(dist2), np.std(dist2)
from sh.frm import *
from sh.vol2sf import vol2sf
import numpy as np
from pytom.tools.maths import rotation_distance
from sh.soft import *

v = read('/fs/home/ychen/matlab/template/binning/temp80SRibosome_bin2.em')
r = 8
b = 32
start = -60
end = 60
wedge = create_wedge_sf(start, end, b)
# m1 = wedge+0.001
whole = np.ones(4 * b**2)

sf = np.array(vol2sf(v, r, b))
sf = sf - np.min(sf) + 1.  # set all values above 1
# sf = sf / m1

# sf = create_wedge_sf(start, end, b, 1, 10)

sf2 = sf * wedge

res = frm_corr(sf2, sf)
ang = frm_find_best_angle(res, b)
print ang, rotation_distance([0, 0, 0], ang)
# print res.max(), res[0][b][b]

res = frm_constrained_corr(sf2, wedge, sf, whole)
ang = frm_find_best_angle(res, b)
print ang, rotation_distance([0, 0, 0], ang)
Beispiel #7
0
from sh.vol2sf import vol2sf
from pytom_volume import *
v = read('/fs/home/ychen/matlab/template/binning/temp80SRibosome_bin2.em')

r = 8
b = 32

for i in xrange(1000):
    sf = vol2sf(v, r, b)