Пример #1
0
def make_trajectory_sequence(args):
    # Make a small circle (1 / 10 of the pixel size), so that the composite body only rotates and
    # does not translate. Put this circle in the middle of the image.
    circle = args.n / 2 * args.ps + make_circle(
        n=1024).magnitude * args.ps / 10
    traj = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    metaballs = _make_metaballs(args)
    composite = CompositeBody(traj, bodies=metaballs)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i, t in enumerate(
            np.linspace(0, traj.time.simplified.magnitude, 37) * q.s):
        # Reset transformation matrices
        composite.clear_transformation()
        # Move to the desired position, i.e. around the circle and then each metaball moves relative
        # to the composite body.
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()

    plt.show()
Пример #2
0
def make_manual_sequence(args):
    metaballs = _make_metaballs(args)
    traj = Trajectory([(args.n / 2., args.n / 2., 0)] * args.ps,
                      pixel_size=args.ps)
    composite = CompositeBody(traj, bodies=metaballs)
    # Move the sub-bodies relative to the composite body and also move the composite body to the
    # center of the image.
    composite.move(0 * q.s)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i in range(int((360 * q.deg / d_angle).magnitude) + 1):
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()
        # Rotation takes care of the relative rotation of the sub-bodies around the composite body.
        composite.rotate(d_angle, geom.Z_AX)

    plt.show()
Пример #3
0
def make_trajectory_sequence(args):
    # Make a small circle (1 / 10 of the pixel size), so that the composite body only rotates and
    # does not translate. Put this circle in the middle of the image.
    circle = args.n / 2 * args.ps + make_circle(n=1024).magnitude * args.ps / 10
    traj = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    metaballs = _make_metaballs(args)
    composite = CompositeBody(traj, bodies=metaballs)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i, t in enumerate(np.linspace(0, traj.time.simplified.magnitude, 37) * q.s):
        # Reset transformation matrices
        composite.clear_transformation()
        # Move to the desired position, i.e. around the circle and then each metaball moves relative
        # to the composite body.
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()

    plt.show()
Пример #4
0
def make_complex_trajectory_sequence(args):
    edge = 20
    x = np.linspace(0, args.n / 2 - args.n / 4 - edge - 5, num=10)
    y = z = np.zeros(x.shape)
    # Move along x axis
    traj_x = Trajectory(zip(x, y, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Move along y axis
    traj_y = Trajectory(zip(y, x, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Move along both x and y axes
    traj_xy = Trajectory(zip(x, x, z) * args.ps, velocity=args.ps / q.s, pixel_size=args.ps)
    # Circular trajectory of the composite body rotates around the image center and with radius
    # n / 4 pixels.
    circle = args.n / 2 * args.ps + make_circle().magnitude * args.n / 4 * args.ps
    traj_circle = Trajectory(circle, velocity=args.ps / q.s, pixel_size=args.ps)
    # Make the trajectory of the circle the same duration as the simple linear one.
    traj_circle = Trajectory(circle, velocity=traj_circle.length / traj_xy.length * args.ps / q.s)
    # three cubes in the same height and depth, shifted only along the x axis.
    traj_stationary = Trajectory([(0, 0, 0)] * args.ps)
    traj_stationary_1 = Trajectory([(-2 * edge, 0, 0)] * args.ps)
    traj_stationary_2 = Trajectory([(2 * edge, 0, 0)] * args.ps)

    cube = make_cube() / q.m * edge * args.ps
    # The cubes are elongated along y axis.
    cube[::2, :] /= 3

    mesh = Mesh(cube, traj_x, orientation=geom.Y_AX)
    mesh_2 = Mesh(cube, traj_y, orientation=geom.Y_AX)
    mesh_3 = Mesh(cube, traj_xy, orientation=geom.Y_AX)
    mesh_stationary = Mesh(cube, traj_stationary, orientation=geom.Y_AX)
    mesh_stationary_1 = Mesh(cube, traj_stationary_1, orientation=geom.Y_AX)
    mesh_stationary_2 = Mesh(cube, traj_stationary_2, orientation=geom.Y_AX)
    bodies = [mesh, mesh_2, mesh_3, mesh_stationary, mesh_stationary_1, mesh_stationary_2]
    composite = CompositeBody(traj_circle, bodies=bodies, orientation=geom.Y_AX)
    composite.bind_trajectory(args.ps)

    total_time = composite.time
    if args.t is None:
        times = np.linspace(0, 1, 100)
    else:
        if args.t < 0 or args.t > 1:
            raise ValueError('--t must be in the range [0, 1]')
        times = [args.t]

    im = None
    for index, i in enumerate(times):
        t = i * total_time
        composite.clear_transformation()
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title='Projection')
        else:
            im.set_data(p)
            plt.draw()

    plt.show()
Пример #5
0
def main():
    syris.init()
    args = parse_args()
    n = 256
    shape = (n, n)
    ps = 1 * q.um
    num_projections = None
    cube_edge = n / 4 * ps
    fmt = os.path.join(args.output, "projection_{:04}.tif")

    x = np.linspace(n // 4 + n // 8, 3 * n // 4 + n // 8, num=10)
    y = z = np.zeros(x.shape)
    cube_0 = make_cube_body(n, ps, cube_edge)
    cube_1 = make_cube_body(n, ps, cube_edge, phase_shift=np.pi * q.rad)
    # Vertical motion component has such velocity that the cubes are displaced by their edge length
    # 1 pixel for making sure we have one "complete" sinogram
    velocity = (cube_edge - ps) / cube_0.trajectory.time
    traj_y = geom.Trajectory(list(zip(y, x, z)) * ps,
                             pixel_size=ps,
                             velocity=velocity)
    composite = CompositeBody(traj_y, bodies=[cube_0, cube_1])
    # Total time is the rotation time because we want one tomographic data set
    total_time = cube_0.trajectory.time

    dt = composite.get_next_time(0 * q.s, ps)
    if num_projections is None:
        num_projections = int(np.ceil((total_time / dt).simplified.magnitude))

    print("              num_projs:", num_projections)
    print("          rotation time:", cube_0.trajectory.time)
    print("   vertical motion time:", traj_y.time)
    print("        simulation time:", total_time)

    for i in range(num_projections):
        t = total_time / num_projections * i
        composite.move(t)
        projection = composite.project(shape, ps).get()
        imageio.imwrite(fmt.format(i), projection)

    show(projection)
    plt.show()
Пример #6
0
def main():
    syris.init()
    args = parse_args()
    n = 256
    shape = (n, n)
    ps = 1 * q.um
    num_projections = None
    cube_edge = n / 4 * ps
    fmt = os.path.join(args.output, 'projection_{:04}.tif')

    x = np.linspace(n / 4 + n / 8, 3 * n / 4 + n / 8, num=10)
    y = z = np.zeros(x.shape)
    cube_0 = make_cube_body(n, ps, cube_edge)
    cube_1 = make_cube_body(n, ps, cube_edge, phase_shift=np.pi * q.rad)
    # Vertical motion component has such velocity that the cubes are displaced by their edge length
    # 1 pixel for making sure we have one "complete" sinogram
    velocity = (cube_edge - ps) / cube_0.trajectory.time
    traj_y = geom.Trajectory(zip(y, x, z) * ps, pixel_size=ps, velocity=velocity)
    composite = CompositeBody(traj_y, bodies=[cube_0, cube_1])
    # Total time is the rotation time because we want one tomographic data set
    total_time = cube_0.trajectory.time

    dt = composite.get_next_time(0 * q.s, ps)
    if num_projections is None:
        num_projections = int(np.ceil((total_time / dt).simplified.magnitude))

    print '              num_projs:', num_projections
    print '          rotation time:', cube_0.trajectory.time
    print '   vertical motion time:', traj_y.time
    print '        simulation time:', total_time

    for i in range(num_projections):
        t = total_time / num_projections * i
        composite.move(t)
        projection = composite.project(shape, ps).get()
        tifffile.imsave(fmt.format(i), projection)

    show(projection)
    plt.show()
Пример #7
0
def main():
    args = parse_args()
    syris.init(device_index=0)
    n = 512
    shape = (n, n)
    ps = 1 * q.um

    x = np.linspace(0, n, num=10)
    y = z = np.zeros(x.shape)
    traj_x = Trajectory(zip(x, y, z) * ps, velocity=ps / q.s)
    traj_y = Trajectory(zip(y, x, z) * ps, velocity=ps / q.s)
    traj_xy = Trajectory(zip(n - x, x, z) * ps, velocity=ps / q.s)
    mb = MetaBall(traj_x, n * ps / 16)
    cube = make_cube() / q.m * 16 * ps
    mesh = Mesh(cube, traj_xy)
    composite = CompositeBody(traj_y, bodies=[mb, mesh])
    composite.bind_trajectory(ps)
    t = args.t * n * q.s

    composite.move(t)
    p = composite.project(shape, ps).get()
    show(p, title='Projection')

    plt.show()
Пример #8
0
    def test_project_composite(self):
        n = 64
        shape = (n, n)
        ps = 1 * q.um
        x = np.linspace(0, n, num=10)
        y = z = np.zeros(x.shape)
        traj_x = Trajectory(zip(x, y, z) * ps, velocity=ps / q.s)
        traj_y = Trajectory(zip(y, x, z) * ps, velocity=ps / q.s)
        traj_xy = Trajectory(zip(n - x, x, z) * ps, velocity=ps / q.s)
        mb = MetaBall(traj_x, n * ps / 16)
        cube = make_cube() / q.m * 16 * ps / 4
        mesh = Mesh(cube, traj_xy)
        composite = CompositeBody(traj_y, bodies=[mb, mesh])
        composite.bind_trajectory(ps)

        composite.move(n / 2 * q.s)
        p = composite.project(shape, ps).get()
        composite.clear_transformation()

        # Compute
        composite.move(n / 2 * q.s)
        p_separate = (mb.project(shape, ps) + mesh.project(shape, ps)).get()

        np.testing.assert_almost_equal(p, p_separate)
Пример #9
0
def make_manual_sequence(args):
    metaballs = _make_metaballs(args)
    traj = Trajectory([(args.n / 2., args.n / 2., 0)] * args.ps, pixel_size=args.ps)
    composite = CompositeBody(traj, bodies=metaballs)
    # Move the sub-bodies relative to the composite body and also move the composite body to the
    # center of the image.
    composite.move(0 * q.s)

    im = None
    d_angle = 10 * q.deg
    fmt = 'Projection at rotation {:>9}'
    # Rotate around 360 deg
    for i in range(int((360 * q.deg / d_angle).magnitude) + 1):
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title=fmt.format(i * d_angle))
        else:
            im.axes.set_title(fmt.format(i * d_angle))
            im.set_data(p)
        plt.draw()
        # Rotation takes care of the relative rotation of the sub-bodies around the composite body.
        composite.rotate(d_angle, geom.Z_AX)

    plt.show()
Пример #10
0
def make_complex_trajectory_sequence(args):
    edge = 20
    x = np.linspace(0, args.n / 2 - args.n / 4 - edge - 5, num=10)
    y = z = np.zeros(x.shape)
    # Move along x axis
    traj_x = Trajectory(zip(x, y, z) * args.ps,
                        velocity=args.ps / q.s,
                        pixel_size=args.ps)
    # Move along y axis
    traj_y = Trajectory(zip(y, x, z) * args.ps,
                        velocity=args.ps / q.s,
                        pixel_size=args.ps)
    # Move along both x and y axes
    traj_xy = Trajectory(zip(x, x, z) * args.ps,
                         velocity=args.ps / q.s,
                         pixel_size=args.ps)
    # Circular trajectory of the composite body rotates around the image center and with radius
    # n / 4 pixels.
    circle = args.n / 2 * args.ps + make_circle(
    ).magnitude * args.n / 4 * args.ps
    traj_circle = Trajectory(circle,
                             velocity=args.ps / q.s,
                             pixel_size=args.ps)
    # Make the trajectory of the circle the same duration as the simple linear one.
    traj_circle = Trajectory(circle,
                             velocity=traj_circle.length / traj_xy.length *
                             args.ps / q.s)
    # three cubes in the same height and depth, shifted only along the x axis.
    traj_stationary = Trajectory([(0, 0, 0)] * args.ps)
    traj_stationary_1 = Trajectory([(-2 * edge, 0, 0)] * args.ps)
    traj_stationary_2 = Trajectory([(2 * edge, 0, 0)] * args.ps)

    cube = make_cube() / q.m * edge * args.ps
    # The cubes are elongated along y axis.
    cube[::2, :] /= 3

    mesh = Mesh(cube, traj_x, orientation=geom.Y_AX)
    mesh_2 = Mesh(cube, traj_y, orientation=geom.Y_AX)
    mesh_3 = Mesh(cube, traj_xy, orientation=geom.Y_AX)
    mesh_stationary = Mesh(cube, traj_stationary, orientation=geom.Y_AX)
    mesh_stationary_1 = Mesh(cube, traj_stationary_1, orientation=geom.Y_AX)
    mesh_stationary_2 = Mesh(cube, traj_stationary_2, orientation=geom.Y_AX)
    bodies = [
        mesh, mesh_2, mesh_3, mesh_stationary, mesh_stationary_1,
        mesh_stationary_2
    ]
    composite = CompositeBody(traj_circle,
                              bodies=bodies,
                              orientation=geom.Y_AX)
    composite.bind_trajectory(args.ps)

    total_time = composite.time
    if args.t is None:
        times = np.linspace(0, 1, 100)
    else:
        if args.t < 0 or args.t > 1:
            raise ValueError('--t must be in the range [0, 1]')
        times = [args.t]

    im = None
    for index, i in enumerate(times):
        t = i * total_time
        composite.clear_transformation()
        composite.move(t)
        p = composite.project(args.shape, args.ps).get()
        if im is None:
            im = show(p, title='Projection')
        else:
            im.set_data(p)
            plt.draw()

    plt.show()