Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Update Changes from New Engine Design #882

Merged
merged 13 commits into from
Nov 21, 2024
Prev Previous commit
Next Next commit
✅ Fix coverage
shaneahmed committed Nov 21, 2024
commit 0812fc77d847307ed77d6b0b907b6ec70a058f71
14 changes: 13 additions & 1 deletion tests/test_annotation_tilerendering.py
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@
from tiatoolbox.annotation import Annotation, AnnotationStore, SQLiteStore
from tiatoolbox.tools.pyramid import AnnotationTileGenerator
from tiatoolbox.utils.env_detection import running_on_travis
from tiatoolbox.utils.visualization import AnnotationRenderer
from tiatoolbox.utils.visualization import AnnotationRenderer, _find_minimum_mpp_sf
from tiatoolbox.wsicore import wsireader

RNG = np.random.default_rng(0) # Numpy Random Generator
@@ -481,3 +481,15 @@ def color_fn(props: dict[str, str]) -> tuple[int, int, int]:
assert num == 50 # expect 50 green objects
_, num = label(np.array(thumb)[:, :, 2])
assert num == 0 # expect 0 blue objects


def test_minimum_mpp_sf() -> None:
"""Test minimum mpp_sf."""
mpp_sf = _find_minimum_mpp_sf((0.5, 0.5))
assert mpp_sf == 1.0

mpp_sf = _find_minimum_mpp_sf((0.20, 0.20))
assert mpp_sf == 0.20 / 0.25

mpp_sf = _find_minimum_mpp_sf(None)
assert mpp_sf == 1.0
11 changes: 8 additions & 3 deletions tiatoolbox/utils/visualization.py
Original file line number Diff line number Diff line change
@@ -559,6 +559,13 @@ def to_int_tuple(x: tuple[int, ...] | np.ndarray) -> tuple[int, ...]:
return canvas


def _find_minimum_mpp_sf(mpp: tuple[float, float]) -> float:
"""Calculates minimum mpp scale factor."""
if mpp is not None:
return np.minimum(mpp[0] / 0.25, 1)
return 1.0


class AnnotationRenderer:
"""Renders AnnotationStore to a tile.

@@ -971,9 +978,7 @@ def render_annotations(
int((bounds[2] - bounds[0]) / scale),
]

mpp_sf = 1
if self.info["mpp"] is not None:
mpp_sf = np.minimum(self.info["mpp"][0] / 0.25, 1)
mpp_sf = _find_minimum_mpp_sf(self.info["mpp"])

min_area = 0.0005 * (output_size[0] * output_size[1]) * (scale * mpp_sf) ** 2