Skip to content

Commit

Permalink
Update main API
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Mar 18, 2024
1 parent ae969a6 commit fbddd04
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
1 change: 1 addition & 0 deletions lazyslide/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from .wsi import WSI
from .utils import get_reader
from .filter import SobelFilter, BlurFilter, FocusLiteFilter


def about():
Expand Down
31 changes: 22 additions & 9 deletions lazyslide/wsi.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import annotations

import warnings
from concurrent.futures import ProcessPoolExecutor
from numbers import Integral
from pathlib import Path
from typing import Sequence, Mapping
Expand Down Expand Up @@ -255,6 +256,7 @@ def create_tiles(
background_fraction=0.8,
tile_pts=3,
errors="ignore",
tile_filter=None,
save=True,
):
"""
Expand Down Expand Up @@ -404,8 +406,6 @@ def create_tiles(
points = rect_coords
is_in = []
for c in self._contours:
# Coerce the point to python int and let the opencv decide the type
# Flip x, y because it's different in opencv
polytest = [
cv2.pointPolygonTest(c, (float(x), float(y)), measureDist=False)
for x, y in points
Expand All @@ -428,6 +428,16 @@ def create_tiles(
# Select only the top_left corner
tiles_coords = rect_coords[rect_indices[good_tiles, 0]].copy()

# Run tile filter
if tile_filter is not None:
masks = []

for c in tiles_coords:
left, top = c
patch = self.get_patch(left, top, tile_w, tile_h, level=0)
masks.append(tile_filter.filter(patch))
tiles_coords = tiles_coords[masks].copy()

self.new_tiles(
tiles_coords,
width=tile_w,
Expand Down Expand Up @@ -589,13 +599,16 @@ def plot_tissue(
)

if contours:
viewer.add_contours_holes(
self.contours,
self.holes,
contour_color=contour_color,
hole_color=hole_color,
linewidth=linewidth,
)
if self.contours is None:
warnings.warn("No contours is created")
else:
viewer.add_contours_holes(
self.contours,
self.holes,
contour_color=contour_color,
hole_color=hole_color,
linewidth=linewidth,
)

if save is not None:
savefig_kws = {} if savefig_kws is None else savefig_kws
Expand Down

0 comments on commit fbddd04

Please sign in to comment.