def psf_zplane(stack, dz, w0, de = 1):
'''
determine the position of the real focal plane.
Don't mistake with psf_slice!
'''
nz, ny, nx = stack.shape
cy, cx = np.unravel_index(np.argmax(gf(stack,2)), (nz,ny,nx))[1:]
zrange = (nz-1)*dz*0.5
zz = np.linspace(-zrange, zrange, nz)
center_z = stack[:,cy-de:cy+de+1,cx-de:cx+de+1]
im_z = center_z.mean(axis=2).mean(axis=1)
b = np.mean((im_z[0],im_z[-1]))
a = im_z.max() - b
p0 = (a,0,w0,b)
popt = optimize.curve_fit(gaussian, zz, im_z, p0)[0]
z_offset = popt[1] # The original version is wrong
return z_offset, zz
评论列表
文章目录