Skip to content

Commit

Permalink
Use pre-allocate array for chunk mask creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Milk committed Dec 1, 2023
1 parent 3480aec commit 1cd55fa
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions lazyslide/wsi.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,18 +195,14 @@ def create_tissue_mask(self, name="tissue", level=0,
# If the image is too large, we will run segmentation by chunk
split_indices = get_split_image_indices(img_height, img_width, min_side=chunk_at)
if chunk & (split_indices is not None):
masks = []
mask = np.zeros((img_height, img_width), dtype=np.uint8)
for row in split_indices:
row_mask = []
for ixs in row:
h1, h2, w1, w2 = ixs
img_chunk = self.reader.get_patch(w1, h1, w2 - w1, h2 - h1, level=level)
mask = seg.apply(img_chunk)
row_mask.append(mask)
chunk_mask = seg.apply(img_chunk)
mask[h1:h2, w1:w2] = chunk_mask
del img_chunk # Explicitly release memory
masks.append(row_mask)
mask = np.block(masks)
del masks # Explicitly release memory
else:
image = self.reader.get_level(level)
mask = seg.apply(image)
Expand Down

0 comments on commit 1cd55fa

Please sign in to comment.