Skip to content

Commit

Permalink
Fix type error for cv2.pointPolygonTest
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Dec 5, 2023
1 parent f1e1aa0 commit 2f6fe62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lazyslide/loader/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
from .dataset import FeatureExtractionDataset
from .slide_balaned_loader import SlidesBalancedLoader
from .slides_balaned_loader import SlidesBalancedLoader
File renamed without changes.
15 changes: 9 additions & 6 deletions lazyslide/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def __init__(self,

def __repr__(self):
return (f"WSI(image={self.image}, "
f"h5_file={self.h5_file})")
f"h5_file={self.h5_file.file})")

def create_mask(self, transform, name="user", level=-1, save=False):
level = self.reader.translate_level(level)
Expand Down Expand Up @@ -431,13 +431,14 @@ def create_tiles(self, tile_px,
points = rect_coords[:, [1, 0]]
is_in = []
for c in self.contours:
is_in.append(np.array([cv2.pointPolygonTest(c, point, measureDist=False) \
for point in points]) == 1)
# Coerce the point to python int and let the opencv decide the type
is_in.append(np.array([cv2.pointPolygonTest(c, (int(x), int(y)), measureDist=False) \
for x, y in points]) == 1)

if len(self.holes) > 0:
for c in self.contours:
is_in.append(np.array([cv2.pointPolygonTest(c, point, measureDist=False) \
for point in points]) == -1)
is_in.append(np.array([cv2.pointPolygonTest(c, (int(x), int(y)), measureDist=False) \
for x, y in points]) == -1)

is_tiles = np.asarray(is_in).sum(axis=0) == 1
# The number of points for each tiles inside contours
Expand All @@ -451,7 +452,9 @@ def create_tiles(self, tile_px,

def new_tiles(self, tiles_coords, height, width, level=0):
"""Supply a customized tiles"""
self.tiles_coords = tiles_coords
self.tiles_coords = np.asarray(tiles_coords, dtype=np.uint)
height = int(height)
width = int(width)
self.tile_ops = TileOps(level=level,
mpp=self.metadata.mpp,
downsample=1,
Expand Down

0 comments on commit 2f6fe62

Please sign in to comment.