File size: 1,426 Bytes
e04bbc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
from dataclasses import dataclass, asdict
from typing import Any


def _force_odd(n: int) -> int:
    return n if n % 2 == 1 else n + 1


@dataclass
class AnalysisParams:
    hue_low: int = 10
    hue_high: int = 35
    min_hue_fraction: float = 0.05
    shrink_factor: float = 0.95

    use_bilateral: bool = True
    bilateral_d: int = 9
    sigma_color: int = 75
    sigma_space: int = 75

    v_mode: str = "otsu"
    s_mode: str = "otsu"
    v_threshold: int = 150
    s_threshold: int = 50
    v_otsu_offset: int = 0
    s_otsu_offset: int = 0
    bright_keep_threshold: int = 180
    max_area_fraction: float = 0.30
    use_hue_filter: bool = True
    hue_filter_low: int = 8
    hue_filter_high: int = 28

    small_kernel: int = 3
    large_kernel: int = 7
    close_iters: int = 2
    open_iters: int = 1
    smooth_kernel: int = 9
    min_component_area: int = 50

    h: int = 5
    min_seed_area: int = 5

    use_merge: bool = True
    merge_area_threshold: int = 500
    proximity_threshold: int = 15
    color_similarity_threshold: int = 30

    min_area: int = 100

    def __post_init__(self) -> None:
        for f in ("bilateral_d", "small_kernel", "large_kernel", "smooth_kernel"):
            setattr(self, f, _force_odd(getattr(self, f)))

    def to_dict(self) -> dict[str, Any]:
        return asdict(self)


DEFAULT_PARAMS = AnalysisParams()