Skip to content

Commit

Permalink
update transform
Browse files Browse the repository at this point in the history
  • Loading branch information
eugene123tw committed Dec 12, 2024
1 parent f147039 commit 704a13c
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/otx/core/data/dataset/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import operator
import warnings
from copy import deepcopy
from functools import partial
from itertools import product
from typing import TYPE_CHECKING, Callable

Expand Down Expand Up @@ -92,7 +93,7 @@ def __init__(
)
self._tile_size = tile_size
self._tile_ann_func_map[AnnotationType.polygon] = OTXTileTransform._tile_polygon
self._tile_ann_func_map[AnnotationType.ellipse] = OTXTileTransform._tile_polygon
self._tile_ann_func_map[AnnotationType.ellipse] = partial(OTXTileTransform._tile_polygon, num_points=10)
self.with_full_img = with_full_img

@staticmethod
Expand All @@ -101,9 +102,10 @@ def _tile_polygon(
roi_box: sg.Polygon,
threshold_drop_ann: float = 0.8,
*args, # noqa: ARG004
**kwargs, # noqa: ARG004
**kwargs,
) -> Polygon | None:
polygon = sg.Polygon(ann.get_points())
num_points = kwargs["num_points"] if kwargs.get("num_points") else 720
polygon = sg.Polygon(ann.get_points(num_points=num_points))

# NOTE: polygon may be invalid, e.g. self-intersecting
if not roi_box.intersects(polygon) or not polygon.is_valid:
Expand All @@ -128,9 +130,10 @@ def _tile_polygon(

inter = _apply_offset(inter, roi_box)

return ann.wrap(
return Polygon(
points=[p for xy in inter.exterior.coords for p in xy],
attributes=deepcopy(ann.attributes),
label=ann.label,
)

def _extract_rois(self, image: Image) -> list[BboxIntCoords]:
Expand Down

0 comments on commit 704a13c

Please sign in to comment.