예제 #1
0
def test_save_cell_images(tmp_path):
    cells = segment_cells(locate_module_and_cells(datasets.poly10x6(1)[0]))
    save_images(tmp_path, cells)

    for cell in cells:
        p = tmp_path / "{}_row{:02d}_col{:02d}{}".format(
            cell.path.stem, cell.row, cell.col, cell.path.suffix)
        img_read = read_module_image(p, EL_IMAGE)
예제 #2
0
def test_segment_cells_single_image():
    seq = data.datasets.poly10x6(1)
    seq = detection.locate_module_and_cells(seq, True)
    cells = detection.segment_cells(seq[0])

    assert isinstance(cells, CellImageSequence)
    assert len(cells) == 60
    assert isinstance(cells[0], CellImage)
예제 #3
0
def test_save_images_filename_hook(tmp_path: Path):
    cells = segment_cells(locate_module_and_cells(datasets.poly10x6(1)[0]))
    hook = lambda x: "{}_{:02d}{:02d}{}".format(x.path.stem, x.row, x.col, x.
                                                path.suffix)
    save_images(tmp_path, cells)

    for cell in cells:
        p = tmp_path / "{}_{:02d}{:02d}{}".format(cell.path.stem, cell.row,
                                                  cell.col, cell.path.suffix)
        # try read
        img_read = read_module_image(p, EL_IMAGE)
예제 #4
0
def test_segment_cells():
    seq = data.datasets.poly10x6(2)
    seq = detection.locate_module_and_cells(seq, True)
    cells = detection.segment_cells(seq)

    assert isinstance(cells, CellImageSequence)
    assert len(cells) == 120
    assert isinstance(cells[0], CellImage)
    assert cells[0].row == 0
    assert cells[0].col == 0
    assert cells[1].col == 1
    assert cells[11].row == 1
    assert cells[0].has_meta("segment_module_original")
    assert (cells[0].get_meta("segment_module_original").has_meta(
        "segment_module_original_box"))
예제 #5
0
def test_single_segmentation():
    # load images
    img = datasets.poly10x6(N=1)[0]

    # perform detection
    module = locate_module_and_cells(img)

    # check result
    assert module.has_meta("transform")

    # check that show result does not fail
    module.show()

    # perform segmentation into cells
    cells = segment_cells(module)

    # check
    assert len(cells) == 60
예제 #6
0
def test_multi_segmentation():
    # load images
    _, imgs = datasets.multi_module_detection(N=2)

    # perform multi module segmentation
    modules = locate_multiple_modules(imgs, rows=6, cols=10)

    # check result
    assert len(modules) == 12
    assert isinstance(modules[0].get_meta("multimodule_original"), Image)
    assert modules[0].get_meta("multimodule_original").path == imgs[0].path

    # check that plotting does not fail
    modules[0].get_meta("multimodule_original").show()

    # perform precise module localization and segmentation
    modules = locate_module_and_cells(modules)
    modules_crop = segment_modules(modules)

    # check result
    assert len(modules) == 12
    assert_equal(
        modules_crop[0].get_meta("transform")(np.array([[0.0, 0.0]])),
        np.array([0.0, 0.0]),
    )

    # make sure that original is preserved
    assert isinstance(modules_crop[0].get_meta("multimodule_original"), Image)
    assert modules_crop[0].get_meta(
        "multimodule_original").path == imgs[0].path

    # check show
    modules_crop.head()

    # check segmentation into cells
    cells = segment_cells(modules_crop[0])
    assert len(cells) == 60

    # make sure that original is preserved
    assert isinstance(cells[0].get_meta("multimodule_original"), Image)
    assert cells[0].get_meta("multimodule_original").path == imgs[0].path