示例#1
0
        def test_slice_plate_image(self, image_circle):
            plates = PlateCollection(shape=(1, 1))
            plates.add(id=1, diameter=180, edge_cut=20, center=(102, 102))

            images = plates.slice_plate_image(image_circle)

            assert len(images) == 1
            assert images[1].shape == (141, 141)
示例#2
0
        def test_centers(self):
            centers = list()
            collection = PlateCollection()
            for i in range(1, 10):
                center = (i, i)
                centers.append(center)
                collection.add(id=i, diameter=1, center=center)

            assert collection.count == len(centers)
            assert collection.centers == centers
示例#3
0
        def test_plates_from_image(self, image_circle):
            label = "label"
            plates = PlateCollection(shape=(1, 1))
            plates.plates_from_image(image=image_circle,
                                     diameter=180,
                                     labels={1: label})

            assert plates.count == 1
            assert plates.centers == [(102, 102)]
            assert plates.items[0].diameter == 160
            assert plates.items[0].name == label
示例#4
0
        def test_from_image(self, image_circle):
            plates = PlateCollection.from_image(
                shape=(1, 1),
                image=image_circle,
                diameter=180,
            )

            assert plates is not None
            assert isinstance(plates, PlateCollection)
示例#5
0
        def test_plates_to_csv(self, image_circle, tmp_path):
            import csv

            plates = PlateCollection.from_image(
                shape=(1, 1),
                image=image_circle,
                diameter=180,
            )
            result = plates.plates_to_csv(tmp_path)

            # Check all rows were written correctly
            with open(result, 'r') as csvfile:
                reader = list(csv.reader(csvfile))

                assert len(reader) == plates.count + 1
                assert reader[1] == [
                    "1", "", "(102, 102)", "160", "0", "0", "0", "0.0", "0.0",
                    "0.0", "0.0", "0.0", "0.0", "0.0", "0.0"
                ]
示例#6
0
 def test_coordinate_to_index_invalid(self, coordinate):
     with pytest.raises(ValueError):
         PlateCollection.coordinate_to_index(coordinate)
示例#7
0
        def test_coordinate_to_index(self, coordinate, expected):
            result = PlateCollection.coordinate_to_index(coordinate)

            assert result == expected
示例#8
0
        def test_index_to_coordinate_invalid(self, index, shape):
            with pytest.raises(ValueError):
                PlateCollection.index_to_coordinate(index, shape)

            with pytest.raises(IndexError):
                PlateCollection.index_to_coordinate(100, (1, 1))
示例#9
0
        def test_index_to_coordinate(self, index, shape, expected):
            result = PlateCollection.index_to_coordinate(index, shape)

            assert result == expected
示例#10
0
        def test_plates_from_image_invalid(self, image_circle):
            plates = PlateCollection()

            with pytest.raises(ValueError):
                plates.plates_from_image(image=image_circle, diameter=180)
示例#11
0
        def test_add(self, id, diameter):
            collection = PlateCollection()
            item_new = collection.add(id=id, diameter=diameter)

            assert collection.count == 1
            assert item_new in collection.items
示例#12
0
 def test_init_invalid(self, shape):
     with pytest.raises(ValueError):
         PlateCollection(shape=shape)
示例#13
0
        def test_init(self, shape):
            collection = PlateCollection(shape=shape)

            assert collection.shape == shape
# Output a plate image with plate locations outlined
image_files = [
    ["./images/outlined/3_1_95.tif", (3, 1), 95],
    ["./images/outlined/3_2_35_empty.tif", (3, 2), 35],
    ["./images/outlined/3_2_35.tif", (3, 2), 35],
    ["./images/outlined/3_2_90_empty.tif", (3, 2), 90],
    ["./images/outlined/3_2_90.tif", (3, 2), 90],
    ["./images/outlined/6_4_35_empty.tif", (6, 4), 35],
    ["./images/outlined/6_4_35.tif", (6, 4), 35],
]

for image in image_files:
    image_file, lattice, size = image
    size = int(mm_to_pixels(size, dots_per_inch = 300))

    # Load the image
    img = imread(image_file, as_gray = False, plugin = "pil")

    # Locate plates in the image and store as Plate instances
    plates = PlateCollection.from_image(
        shape = lattice,
        image = rgb2gray(img),
        diameter = size,
        search_radius = size // 20,
        edge_cut = int(round(size * (5 / 100))),
        labels = []
    )

    # Plot the locations on the plate image
    plot_plate_map(img, plates.items, Path(image_file))