コード例 #1
0
ファイル: test_slice5D.py プロジェクト: ilastik/ndstructs
def test_get_borders():
    slc = Slice5D.zero(x=slice(100, 200), y=slice(300, 400), c=slice(0, 4))
    thickness = Shape5D.zero(x=1, y=1)
    expected_borders = {
        slc.with_coord(x=slice(100, 101)),
        slc.with_coord(y=slice(300, 301)),
        slc.with_coord(x=slice(199, 200)),
        slc.with_coord(y=slice(399, 400)),
    }
    assert expected_borders == set(slc.get_borders(thickness))
    assert len(list(slc.get_borders(thickness))) == 4

    thickness = Shape5D.zero(x=10, y=20)
    expected_thick_borders = {
        slc.with_coord(x=slice(100, 110)),
        slc.with_coord(x=slice(190, 200)),
        slc.with_coord(y=slice(300, 320)),
        slc.with_coord(y=slice(380, 400)),
    }
    assert expected_thick_borders == set(slc.get_borders(thickness=thickness))
    assert len(list(slc.get_borders(thickness=thickness))) == 4

    z2_slc = Slice5D.zero(x=slice(100, 200), y=slice(300, 400), z=slice(8, 10))
    thickness = Shape5D.zero(x=10, z=2)
    expected_z2_borders = {
        z2_slc.with_coord(x=slice(100, 110)),
        z2_slc.with_coord(x=slice(190, 200)),
        z2_slc.with_coord(z=slice(8, 10)),
    }
    assert expected_z2_borders == set(z2_slc.get_borders(thickness=thickness))
    assert len(list(z2_slc.get_borders(thickness=thickness))) == 4
コード例 #2
0
def test_get_borders():
    slc = Slice5D.zero(x=slice(100, 200), y=slice(300, 400), c=slice(0, 4))
    thickness = Shape5D.zero(x=1, y=1)
    expected_borders = {
        slc.with_coord(x=slice(100, 101)),
        slc.with_coord(y=slice(300, 301)),
        slc.with_coord(x=slice(199, 200)),
        slc.with_coord(y=slice(399, 400)),
    }
    for border_slc in slc.get_borders(thickness):
        expected_borders.remove(border_slc)
    assert len(expected_borders) == 0

    thickness = Shape5D.zero(x=10, y=20)
    expected_thick_borders = {
        slc.with_coord(x=slice(100, 110)),
        slc.with_coord(x=slice(190, 200)),
        slc.with_coord(y=slice(300, 320)),
        slc.with_coord(y=slice(380, 400)),
    }
    for border_slc in slc.get_borders(thickness=thickness):
        expected_thick_borders.remove(border_slc)
    assert len(expected_thick_borders) == 0

    z2_slc = Slice5D.zero(x=slice(100, 200), y=slice(300, 400), z=slice(8, 10))
    thickness = Shape5D.zero(x=10, z=2)
    expected_z2_borders = {
        z2_slc.with_coord(x=slice(100, 110)),
        z2_slc.with_coord(x=slice(190, 200)),
        z2_slc.with_coord(z=slice(8, 10)),
    }
    for border_slc in z2_slc.get_borders(thickness=thickness):
        expected_z2_borders.remove(border_slc)
    assert len(expected_z2_borders) == 0
コード例 #3
0
def test_unique_border_colors():
    # fmt: off
    arr = Array5D(numpy.asarray([
        [7, 7, 0, 0, 0, 0],
        [7, 7, 0, 0, 0, 0],
        [7, 0, 0, 0, 0, 0],
        [0, 0, 0, 3, 0, 0],
        [0, 0, 3, 3, 3, 0],
        [0, 0, 0, 3, 0, 0],
        [0, 0, 0, 0, 0, 0],
        [0, 0, 0, 0, 0, 0],
        [0, 0, 5, 5, 0, 0]]), axiskeys="yx")
    # fmt: on

    border_colors = arr.unique_border_colors()
    assert border_colors.shape == Shape5D(x=len([7, 5, 0]))

    raw_colors = border_colors.raw("x")
    assert 7 in raw_colors
    assert 5 in raw_colors
    assert 0 in raw_colors

    # fmt: off
    arr_zyx = Array5D(numpy.asarray([
        [[7, 7, 0, 0, 0, 0],
         [7, 7, 0, 0, 0, 0],
         [7, 0, 0, 0, 0, 0],
         [0, 0, 0, 3, 0, 0],
         [0, 0, 3, 3, 3, 0],
         [0, 0, 0, 3, 0, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 5, 5, 0, 0]],

        [[0, 0, 0, 2, 2, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 9, 0],
         [0, 0, 0, 0, 9, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0]],
    ]), axiskeys="zyx")
    # fmt: on

    # import pydevd; pydevd.settrace()
    # get borders as if this was two separate plaes, as opposed to a single 3d block
    border_colors = arr_zyx.unique_border_colors(border_thickness=Shape5D.zero(x=1, y=1))
    print("===>>>>>", border_colors.raw("x"))
    assert border_colors.shape == Shape5D(x=len([7, 5, 0, 2]))

    raw_colors = border_colors.raw("x")
    assert 7 in raw_colors
    assert 5 in raw_colors
    assert 0 in raw_colors
    assert 2 in border_colors._data
コード例 #4
0
def test_get_borders():
    # fmt: off
    arr = Array5D(
        numpy.asarray([
            [[1, 2, 3, 4, 5], [6, 7, 8, 9, 10], [11, 12, 13, 14, 15],
             [16, 17, 18, 19, 20]],
            [[-1, -2, -3, -4, -5], [-6, -7, -8, -9, -10],
             [-11, -12, -13, -14, -15], [-16, -17, -18, -19, -20]],
            [[10, 20, 30, 40, 50], [11, 21, 31, 41, 51], [12, 22, 32, 42, 52],
             [13, 23, 33, 43, 53]],
        ]), "cyx")

    expected_thin_borders = {
        "left_border":
        Array5D(
            numpy.asarray([
                [[1], [6], [11], [16]],
                [[-1], [-6], [-11], [-16]],
                [[10], [11], [12], [13]],
            ]), "cyx"),
        "top_border":
        Array5D(
            numpy.asarray([[[1, 2, 3, 4, 5]], [[-1, -2, -3, -4, -5]],
                           [[10, 20, 30, 40, 50]]]), "cyx"),
        "right_border":
        Array5D(
            numpy.asarray([
                [[5], [10], [15], [20]],
                [[-5], [-10], [-15], [-20]],
                [[50], [51], [52], [53]],
            ]), "cyx"),
        "bottom_border":
        Array5D(
            numpy.asarray([
                [[16, 17, 18, 19, 20]],
                [[-16, -17, -18, -19, -20]],
                [[13, 23, 33, 43, 53]],
            ]), "cyx")
    }
    # fmt: on
    for border_data in arr.get_borders(thickness=Shape5D.zero(x=1, y=1)):
        for expected_border in expected_thin_borders.values():
            if (border_data.raw("cyx") == expected_border.raw("cyx")).all():
                break
        else:
            raise Exception(
                f"Could not find this border in the expected set:\n{border_data.raw('cyx')}"
            )