Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions opm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,14 @@ def generate_initial_mask(slide_path, scale):
return tissue_mask(slide_thumbnail), real_scale


def get_patch_size_in_microns(input_slide_path, patch_size_from_config, verbose=False):
def get_patch_size_in_microns(input_slide_path, patch_size_from_config, selected_level=0, verbose=False):
"""
This function takes a slide path and a patch size in microns and returns the patch size in pixels.

Args:
input_slide_path (str): The input WSI path.
patch_size_from_config (str): The patch size in microns.
selected_level (int): The level of the WSI to use.
verbose (bool): Whether to provide verbose prints.

Raises:
Expand Down Expand Up @@ -327,7 +328,9 @@ def get_patch_size_in_microns(input_slide_path, patch_size_from_config, verbose=
format(size_in_microns),
)
if magnification > 0:
return_patch_size[i] = round(size_in_microns / magnification)
return_patch_size[i] = round(size_in_microns / (magnification * (2**selected_level)))
if return_patch_size[i] < 1:
raise ValueError("Patch size in microns is too small for selected level")
magnification_prev = magnification
else:
return_patch_size[i] = float(patch_size[i])
Expand Down
4 changes: 2 additions & 2 deletions patch_miner.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@
if args.label_map_path is not None:
manager.set_label_map(args.label_map_path)

## trying to handle mpp
cfg['patch_size'] = get_patch_size_in_microns(slide_path, cfg['patch_size'], True)
## handle mpp
cfg['patch_size'] = get_patch_size_in_microns(slide_path, cfg['patch_size'], cfg['scale'], True)

# Reject patch if any pixels are transparent
manager.add_patch_criteria(alpha_channel_check)
Expand Down