From 2987af9fe3102dc335d3faa3a717a629640f4910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Roland=20N=C3=A9meth?= <93317489+rolandnemeth000@users.noreply.github.com> Date: Tue, 30 Jul 2024 15:48:56 +0200 Subject: [PATCH] Allow PointAnnotation sampling in RandomPointSampler This is needed when sampling from a mix of points and polygons, since PointAnnotations does not have triangles. --- wholeslidedata/samplers/pointsampler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/wholeslidedata/samplers/pointsampler.py b/wholeslidedata/samplers/pointsampler.py index 04fa5970..2b0124d1 100644 --- a/wholeslidedata/samplers/pointsampler.py +++ b/wholeslidedata/samplers/pointsampler.py @@ -4,7 +4,7 @@ from shapely.affinity import affine_transform from shapely.geometry import Point from wholeslidedata.samplers.sampler import Sampler - +from wholeslidedata.annotation.types import PointAnnotation class PointSampler(Sampler): @abc.abstractmethod @@ -39,6 +39,9 @@ def __init__(self, buffer=0.0, simplify=2.0, seed=123): self._simplify = simplify def sample(self, annotation): + if isinstance(annotation, PointAnnotation): + return annotation.centroid + buffer = self._buffer if isinstance(self._buffer, dict): try: @@ -64,4 +67,4 @@ def sample(self, annotation): p = affine_transform(Point(1 - x, 1 - y), transform) else: p = affine_transform(Point(x, y), transform) - return p.x, p.y \ No newline at end of file + return p.x, p.y