def test_align3d_4():
    """
    Test alignment.
    """
    dx = numpy.array([0.1, 0.15, -0.08])
    #dx = numpy.array([0.1, 0.01, 0.001])
    image1 = dg.drawGaussiansXYZ((12,13,14),
                                 numpy.array([6.0]),
                                 numpy.array([6.5]),
                                 numpy.array([7.0]))
#    a3d = imgCorr.Align3DProductLM(image1, xy_margin = 1, z_margin = 1)
    a3d = imgCorr.Align3DProductNewtonCG(image1, xy_margin = 1, z_margin = 1)
    
    image2 = dg.drawGaussiansXYZ((12,13,14),
                                 numpy.array([6.0 - dx[0]]),
                                 numpy.array([6.5 - dx[1]]),
                                 numpy.array([7.0 - dx[2]]))    
    a3d.setOtherImage(image2)

    # Check that we find the proper alignment.
    [disp, success, fun, status] = a3d.maximize()
    assert(success)
    assert(numpy.allclose(disp, dx, rtol = 0.01, atol = 0.01))

    # Check returning an aligned other.
    [aligned, q_score, disp] = a3d.align()
    assert(q_score > 10.0)
    assert(numpy.allclose(image1, aligned, rtol = 1.0e-2, atol = 1.0e-2))
def test_align3d_4():
    """
    Test alignment.
    """
    dx = numpy.array([0.1, 0.15, -0.08])
    #dx = numpy.array([0.1, 0.01, 0.001])
    image1 = dg.drawGaussiansXYZ((12, 13, 14), numpy.array([6.0]),
                                 numpy.array([6.5]), numpy.array([7.0]))
    #    a3d = imgCorr.Align3DProductLM(image1, xy_margin = 1, z_margin = 1)
    a3d = imgCorr.Align3DProductNewtonCG(image1, xy_margin=1, z_margin=1)

    image2 = dg.drawGaussiansXYZ((12, 13, 14), numpy.array([6.0 - dx[0]]),
                                 numpy.array([6.5 - dx[1]]),
                                 numpy.array([7.0 - dx[2]]))
    a3d.setOtherImage(image2)

    # Check that we find the proper alignment.
    [disp, success, fun, status] = a3d.maximize()
    assert (success)
    assert (numpy.allclose(disp, dx, rtol=0.01, atol=0.01))

    # Check returning an aligned other.
    [aligned, q_score, disp] = a3d.align()
    assert (q_score > 10.0)
    assert (numpy.allclose(image1, aligned, rtol=1.0e-2, atol=1.0e-2))
def test_align3d_2():
    """
    Test displacement
    """
    image1 = dg.drawGaussiansXYZ((12, 13, 14), numpy.array([6.0]),
                                 numpy.array([6.5]), numpy.array([7.0]))
    a3d = imgCorr.Align3DProduct(image1, xy_margin=1, z_margin=1)
    a3d.setOtherImage(image1)
    val = a3d.func(numpy.zeros(3))

    image2 = dg.drawGaussiansXYZ((12, 13, 14), numpy.array([6.1]),
                                 numpy.array([6.6]), numpy.array([6.9]))
    a3d.setOtherImage(image2)

    assert (a3d.func(numpy.array([0.0, 0.0, 0.0])) < (val - 0.01))
    assert (a3d.func(numpy.array([0.1, 0.1, -0.1])) < (val - 0.01))
    assert (abs(a3d.func(numpy.array([-0.1, -0.1, 0.1])) - val) < 1.0e-4)
예제 #4
0
def test_dgxy_2():
    image = dg.drawGaussiansXYZ((20, 20, 20), numpy.array([10.0]),
                                numpy.array([10.0]), numpy.array([10.0]))

    dx = numpy.arange(-10.0, 10, 1.0)
    g_slice = numpy.exp(-dx * dx / 2.0)

    assert (numpy.allclose(g_slice, image[10, 10, :], atol=1.0e-4))
    assert (numpy.allclose(g_slice, image[10, :, 10], atol=1.0e-4))
    assert (numpy.allclose(g_slice, image[:, 10, 10], atol=1.0e-4))
def test_dgxy_2():
    image = dg.drawGaussiansXYZ((20,20,20),
                                numpy.array([10.0]),
                                numpy.array([10.0]),
                                numpy.array([10.0]))

    dx = numpy.arange(-10.0,10,1.0)
    g_slice = numpy.exp(-dx*dx/2.0)

    assert(numpy.allclose(g_slice, image[10,10,:], atol = 1.0e-4))
    assert(numpy.allclose(g_slice, image[10,:,10], atol = 1.0e-4))
    assert(numpy.allclose(g_slice, image[:,10,10], atol = 1.0e-4))
def test_align3d_2():
    """
    Test displacement
    """
    image1 = dg.drawGaussiansXYZ((12,13,14),
                                 numpy.array([6.0]),
                                 numpy.array([6.5]),
                                 numpy.array([7.0]))
    a3d = imgCorr.Align3DProduct(image1, xy_margin = 1, z_margin = 1)
    a3d.setOtherImage(image1)
    val = a3d.func(numpy.zeros(3))
    
    image2 = dg.drawGaussiansXYZ((12,13,14),
                                 numpy.array([6.1]),
                                 numpy.array([6.6]),
                                 numpy.array([6.9]))    
    a3d.setOtherImage(image2)

    
    assert(a3d.func(numpy.array([0.0, 0.0, 0.0])) < (val - 0.01))
    assert(a3d.func(numpy.array([0.1, 0.1, -0.1])) < (val - 0.01))
    assert(abs(a3d.func(numpy.array([-0.1, -0.1, 0.1])) - val) < 1.0e-4)
예제 #7
0
def test_dgxy_2():
    image = dg.drawGaussiansXYZ((20,20,20),
                                numpy.array([10.0]),
                                numpy.array([10.0]),
                                numpy.array([10.0]))

    dx = numpy.arange(-10.0,10,1.0)
    g_slice = numpy.exp(-dx*dx/2.0)

    if True:
        with tifffile.TiffWriter("dg.tif") as tf:
            for i in range(image.shape[0]):
                tf.save(image[i,:,:].astype(numpy.float32))
        
    assert(numpy.allclose(g_slice, image[10,10,:], atol = 1.0e-4))
    assert(numpy.allclose(g_slice, image[10,:,10], atol = 1.0e-4))
    assert(numpy.allclose(g_slice, image[:,10,10], atol = 1.0e-4))
예제 #8
0
def test_align_psfs_1():
    """
    Test alignment of multiple PSFs to each other.
    """
    pos = [5.0, 6.0, 7.0]
    maxd = 3.0

    psfs = []
    for i in range(7):
        psfs.append(
            dg.drawGaussiansXYZ((12, 13, 14),
                                numpy.array([pos[0] + int(i / maxd)]),
                                numpy.array([pos[1] + int(i / maxd)]),
                                numpy.array([pos[2] + int(i / maxd)])))

    [average_psf, i_score] = mPSFUtils.alignPSFs(psfs)
    assert (i_score > 2.1)

    if False:
        with tifffile.TiffWriter("psf.tif") as tf:
            tf.save(mPSFUtils.averagePSF(psfs)[6, :, :].astype(numpy.float32))
            tf.save(average_psf[6, :, :].astype(numpy.float32))
def test_align3d_3():
    """
    Test on Gaussians.
    """
    image = dg.drawGaussiansXYZ((12,13,14),
                                numpy.array([6.0]),
                                numpy.array([6.5]),
                                numpy.array([7.0]))
    
    a3d = imgCorr.Align3DProduct(image, xy_margin = 1, z_margin = 1)
    a3d.setOtherImage(image)

    # Check X derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([elt + dx, 0.0, 0.0]))
        f2 = a3d.func(numpy.array([elt, 0.0, 0.0]))
        est = (f1-f2)/dx
        exact = a3d.jacobian(numpy.array([elt, 0.0, 0.0]))[0]
        assert(abs(est - exact) < 1.0e-3)
    
    # Check Y derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([0.0, elt + dx, 0.0]))
        f2 = a3d.func(numpy.array([0.0, elt, 0.0]))
        est = (f1-f2)/dx
        exact = a3d.jacobian(numpy.array([0.0, elt, 0.0]))[1]
        assert(abs(est - exact) < 1.0e-3)

    # Check Z derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([0.0, 0.0, elt + dx]))
        f2 = a3d.func(numpy.array([0.0, 0.0, elt]))
        est = (f1-f2)/dx
        exact = a3d.jacobian(numpy.array([0.0, 0.0, elt]))[2]
        assert(abs(est - exact) < 1.0e-3)
def test_align3d_3():
    """
    Test on Gaussians.
    """
    image = dg.drawGaussiansXYZ((12, 13, 14), numpy.array([6.0]),
                                numpy.array([6.5]), numpy.array([7.0]))

    a3d = imgCorr.Align3DProduct(image, xy_margin=1, z_margin=1)
    a3d.setOtherImage(image)

    # Check X derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([elt + dx, 0.0, 0.0]))
        f2 = a3d.func(numpy.array([elt, 0.0, 0.0]))
        est = (f1 - f2) / dx
        exact = a3d.jacobian(numpy.array([elt, 0.0, 0.0]))[0]
        assert (abs(est - exact) < 1.0e-3)

    # Check Y derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([0.0, elt + dx, 0.0]))
        f2 = a3d.func(numpy.array([0.0, elt, 0.0]))
        est = (f1 - f2) / dx
        exact = a3d.jacobian(numpy.array([0.0, elt, 0.0]))[1]
        assert (abs(est - exact) < 1.0e-3)

    # Check Z derivatives.
    for elt in [-0.1, 0.0, 0.1]:
        dx = 1.0e-6
        f1 = a3d.func(numpy.array([0.0, 0.0, elt + dx]))
        f2 = a3d.func(numpy.array([0.0, 0.0, elt]))
        est = (f1 - f2) / dx
        exact = a3d.jacobian(numpy.array([0.0, 0.0, elt]))[2]
        assert (abs(est - exact) < 1.0e-3)