File size: 2,996 Bytes
c2128ca
 
 
 
 
18a7cb8
c2128ca
 
 
 
 
1dae6a7
9647f45
c2128ca
1dae6a7
 
 
c2128ca
 
 
1dae6a7
55d5390
c2128ca
 
 
 
 
 
 
 
 
 
 
9647f45
1dae6a7
 
 
 
9647f45
 
18a7cb8
 
 
 
1dae6a7
18a7cb8
 
1dae6a7
 
 
18a7cb8
 
 
1dae6a7
18a7cb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dae6a7
18a7cb8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dae6a7
 
 
 
9647f45
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from pathlib import Path

import numpy as np
from PIL import Image

from vascx_models.config import OverlayColors, OverlayConfig, OverlayLayers
from vascx_models.utils import create_fundus_overlay


def test_create_fundus_overlay_draws_kept_measurement_segments(tmp_path: Path) -> None:
    rgb_path = tmp_path / "rgb.png"
    vessel_path = tmp_path / "vessel.png"
    rgb = np.full((40, 40, 3), 255, dtype=np.uint8)
    Image.fromarray(rgb).save(rgb_path)
    vessel = np.zeros((40, 40), dtype=np.uint8)
    vessel[20, 14:27] = 1
    Image.fromarray(vessel).save(vessel_path)

    output = create_fundus_overlay(
        rgb_path=str(rgb_path),
        vessel_path=str(vessel_path),
        vessel_width_measurements=[
            {
                "x": 20.0,
                "y": 20.0,
                "x_start": 10.0,
                "y_start": 20.0,
                "x_end": 30.0,
                "y_end": 20.0,
            }
        ],
    )

    assert tuple(output[20, 20]) == (0, 0, 0)
    assert tuple(output[20, 14]) == (0, 0, 0)
    assert tuple(output[20, 26]) == (0, 0, 0)
    assert tuple(output[20, 13]) == (255, 255, 255)
    assert tuple(output[20, 27]) == (255, 255, 255)
    assert tuple(output[19, 20]) == (255, 255, 255)
    assert tuple(output[21, 20]) == (255, 255, 255)


def test_create_fundus_overlay_respects_vessel_width_layer_and_color(tmp_path: Path) -> None:
    rgb_path = tmp_path / "rgb.png"
    vessel_path = tmp_path / "vessel.png"
    rgb = np.zeros((40, 40, 3), dtype=np.uint8)
    Image.fromarray(rgb).save(rgb_path)
    vessel = np.zeros((40, 40), dtype=np.uint8)
    vessel[20, 14:27] = 1
    Image.fromarray(vessel).save(vessel_path)

    hidden_output = create_fundus_overlay(
        rgb_path=str(rgb_path),
        vessel_path=str(vessel_path),
        vessel_width_measurements=[
            {
                "x": 20.0,
                "y": 20.0,
                "x_start": 10.0,
                "y_start": 20.0,
                "x_end": 30.0,
                "y_end": 20.0,
            }
        ],
        overlay_config=OverlayConfig(layers=OverlayLayers(vessel_widths=False)),
    )
    assert tuple(hidden_output[20, 20]) == (0, 0, 0)

    colored_output = create_fundus_overlay(
        rgb_path=str(rgb_path),
        vessel_path=str(vessel_path),
        vessel_width_measurements=[
            {
                "x": 20.0,
                "y": 20.0,
                "x_start": 10.0,
                "y_start": 20.0,
                "x_end": 30.0,
                "y_end": 20.0,
            }
        ],
        overlay_config=OverlayConfig(
            colors=OverlayColors(vessel_width=(1, 2, 3)),
        ),
    )
    assert tuple(colored_output[20, 20]) == (1, 2, 3)
    assert tuple(colored_output[20, 14]) == (1, 2, 3)
    assert tuple(colored_output[20, 26]) == (1, 2, 3)
    assert tuple(colored_output[20, 13]) == (0, 0, 0)
    assert tuple(colored_output[20, 27]) == (0, 0, 0)
    assert tuple(colored_output[19, 20]) == (0, 0, 0)