Skip to content

Commit ab3f4ad

Browse files
committed
Fixed a bug that annot_mask is not corrected generated; Fixed a bug that norm_annot_shapes are not normalized correctly.
1 parent 4314d43 commit ab3f4ad

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

wsidata/_accessors/iter.py

+12-12
Original file line numberDiff line numberDiff line change
@@ -281,8 +281,6 @@ def __init__(
281281
id,
282282
x,
283283
y,
284-
base_width,
285-
base_height,
286284
tissue_id,
287285
image,
288286
annot_mask=None,
@@ -292,22 +290,26 @@ def __init__(
292290
self.id = id
293291
self.x = x
294292
self.y = y
295-
self.base_width = base_width
296-
self.base_height = base_height
297293
self.tissue_id = tissue_id
298294
self.image = image
299295
self.annot_mask = annot_mask
300296
self.annot_shapes = annot_shapes
301297
self.annot_labels = annot_labels
302298

299+
@property
300+
def width(self):
301+
return self.image.shape[1]
302+
303+
@property
304+
def height(self):
305+
return self.image.shape[0]
306+
303307
@cached_property
304308
def norm_annot_shapes(self):
305309
if self.annot_shapes is not None:
306310
new_shapes = []
307311
for shape, name, label in self.annot_shapes:
308-
norm_shape = _normalize_polygon(
309-
shape, (0, 0, self.base_width, self.base_height)
310-
)
312+
norm_shape = _normalize_polygon(shape, (0, 0, self.width, self.height))
311313
new_shapes.append((norm_shape, name, self.annot_labels[name]))
312314
return new_shapes
313315

@@ -662,7 +664,7 @@ def tile_images(
662664
if create_annot_mask:
663665
annot_shapes = []
664666
sel = annot_tb.geometry.intersects(tile_bbox) # return a boolean mask
665-
anno_mask = np.zeros(mask_size, dtype=mask_dtype)
667+
annot_mask = np.zeros(mask_size, dtype=mask_dtype)
666668
if sel.sum() > 0:
667669
sel = sel.values
668670
geos = annot_tb.geometry[sel]
@@ -681,8 +683,8 @@ def tile_images(
681683
holes = [
682684
np.array(h.coords, dtype=np.int32) for h in geo.interiors
683685
]
684-
cv2.fillPoly(anno_mask, [cnt], int(label)) # noqa
685-
cv2.fillPoly(anno_mask, holes, 0) # noqa
686+
cv2.fillPoly(annot_mask, [cnt], int(label)) # noqa
687+
cv2.fillPoly(annot_mask, holes, 0) # noqa
686688
# Clip the annotation by the tile
687689
# May not be valid after clipping
688690
output_geo = clip_by_rect(geo, 0, 0, *mask_size)
@@ -699,8 +701,6 @@ def tile_images(
699701
id=ix,
700702
x=x,
701703
y=y,
702-
base_width=tile_spec.base_width,
703-
base_height=tile_spec.base_height,
704704
tissue_id=tix,
705705
image=img,
706706
annot_mask=annot_mask,

0 commit comments

Comments
 (0)