Пример #1
0
def test_slicing_atlas_along_leftright_axis_gets_correct_section_image(right, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)).swapaxes(0, 2),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(right=right, rot_axial=-90))
    assert np.all(section.image.channels == out)
Пример #2
0
def test_slicing_atlas_along_infsup_axis_gets_correct_section_image(superior, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)).swapaxes(1, 2),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(superior=superior, rot_lateral=90))
    assert np.all(section.image.channels == out)
Пример #3
0
def test_slicing_atlas_along_postant_axis_gets_correct_section_image(anterior, out):
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 16, 21]), (3, 3, 3)),
        resolution_um=1,
    )
    section = atlas.slice(AtlasTransform(anterior=anterior))
    assert np.all(section.image.channels == out)
Пример #4
0
def test_section_registration_cuts_correctly_with_diff_resolutions(case):
    volume = np.zeros((3, 3, 3))
    volume[1, 1, 1] = 1
    volume[0, 0, 0] = 2
    volume[0, 0, 0] = 2
    atlas = Atlas(
        volume=volume,
        resolution_um=case['atlas_res'],
    )
    section = Section(
        image=ImageData(
            channels=np.ones((1, 3, 3)),
            pixel_resolution_um=case["section_res"],
        ),
        plane_3d=AtlasTransform(**case["pos"]),
    )
    atlas_slice = register(section, atlas).image.channels[0]
    expected_slice = np.array(case['expected']).astype(float)
    try:
        assert np.all(np.isclose(atlas_slice, expected_slice))
    except:
        assert np.all(
            atlas_slice ==
            expected_slice)  # similar, but nicer printout of arrays in pytest


# # different dimensions
# # rotate
# # plane_2d: image origin
# # (get visibility on atlas indices)
Пример #5
0
def repo():
    repo = Mock(BaseSectionRepo)
    repo.sections = [
        Section(
            image=ImageData(channels=np.random.random((2, 3, 4)), pixel_resolution_um=12.),
            plane_3d=AtlasTransform(right=5, superior=2, anterior=20),
        )
    ]
    return repo
Пример #6
0
def test_3d_translation_gives_correct_affine_transform(right, superior,
                                                       anterior):
    expected = [
        [1, 0, 0, right],
        [0, 1, 0, superior],
        [0, 0, 1, anterior],
        [0, 0, 0, 1],
    ]
    observed = AtlasTransform(right=right,
                              superior=superior,
                              anterior=anterior).affine_transform
    assert np.all(np.isclose(observed, expected))
Пример #7
0
def test_slicing_an_atlas_gets_a_new_section_with_correct_parameters():
    atlas = Atlas(
        volume=np.broadcast_to(np.array([10, 20, 30]), (3, 3, 3)).swapaxes(0, 2),
        resolution_um=1
    )
    plane = AtlasTransform()
    section = atlas.slice(plane)
    assert isinstance(section, Section)
    assert section.plane_3d == plane
    assert section.plane_2d == Image2DTransform()
    assert section.image.pixel_resolution_um == atlas.resolution_um
    assert section.image.channels.shape == (1, 3, 3)
    assert section.thickness_um == atlas.resolution_um
Пример #8
0
def test_can_get_3d_position_from_2d_pixel_coordinate_in_section(
        i, j, right, superior, anterior, pixel_resolution):
    section = Section(
        image=ImageData(
            channels=arange(24).reshape(2, 3, 4),
            pixel_resolution_um=pixel_resolution,
        ),
        plane_3d=AtlasTransform(right=right,
                                superior=superior,
                                anterior=anterior),
    )
    x, y, z = section.pos_from_coord(i=i, j=j)  # observed 3D positions
    assert x == approx((j * pixel_resolution) + right)
    assert y == approx((-i * pixel_resolution) + superior)
    assert z == approx(anterior)
Пример #9
0
def test_3d_x_rotation_gives_correct_affine_transform(rot_lateral):
    expected = [
        [1, 0, 0, 0],
        [
            0,
            np.cos(np.radians(rot_lateral)), -np.sin(np.radians(rot_lateral)),
            0
        ],
        [
            0,
            np.sin(np.radians(rot_lateral)),
            np.cos(np.radians(rot_lateral)), 0
        ],
        [0, 0, 0, 1],
    ]
    observed = AtlasTransform(rot_lateral=rot_lateral).affine_transform
    assert np.all(np.isclose(observed, expected))
Пример #10
0
def test_section_registration_to_an_atlas_gets_a_section_that_matches_sections_parameters(
):
    section = Section(
        image=ImageData(
            channels=np.random.random((3, 4, 5)),
            pixel_resolution_um=10,
        ),
        plane_2d=Image2DTransform(i=3, j=5, theta=20),
        plane_3d=AtlasTransform(right=10, superior=-5, anterior=10),
    )
    atlas = Atlas(volume=np.random.random((5, 5, 5)), resolution_um=20)
    s2 = register(section, atlas)
    assert type(s2) is Section
    assert s2.image.pixel_resolution_um == section.image.pixel_resolution_um
    assert s2.id != section.id and s2 is not section
    assert s2.image.width == section.image.width, f"{s2.image.channels.shape}, {section.image.channels.shape}"
    assert s2.image.height == section.image.height
    assert np.all(np.isclose(s2.affine_transform, section.affine_transform))