Skip to content

Commit

Permalink
Add output_tile_size parameter to BaseWsiDataset (#193)
Browse files Browse the repository at this point in the history
- Parameter was accidently removed
  • Loading branch information
AjeyPaiK authored Nov 15, 2023
1 parent 31fe728 commit 137d7ff
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions dlup/data/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ def __init__(
crop: bool = False,
mask: MaskTypes | None = None,
mask_threshold: float | None = 0.0,
output_tile_size: tuple[int, int] | None = None,
annotations: list[_AnnotationTypes] | _AnnotationTypes | None = None,
labels: list[tuple[str, _LabelTypes]] | None = None,
backend: ImageBackend = ImageBackend.PYVIPS,
Expand All @@ -224,6 +225,9 @@ def __init__(
Threshold to check against. The foreground percentage should be strictly larger than threshold.
If None anything is foreground. If 1, the region must be completely foreground.
Other values are in between, for instance if 0.5, the region must be at least 50% foreground.
output_tile_size: tuple[int, int], optional
If this value is set, this value will be used as the tile size of the output tiles. If this value
is different from the underlying grid, this tile will be extracted around the center of the region.
annotations :
Annotation classes.
labels : list
Expand All @@ -242,6 +246,8 @@ def __init__(
self._crop = crop
self.regions = regions

self._output_tile_size = output_tile_size

self.annotations = annotations
self.labels = labels
self._backend = backend
Expand Down Expand Up @@ -307,6 +313,14 @@ def __getitem__(self, index: Union[int, slice]) -> Union[TileSample, Sequence[Ti
region_view = slide_image.get_scaled_view(scaling)
region_view.boundary_mode = BoundaryMode.crop if self.crop else BoundaryMode.zero

if self._output_tile_size is not None:
# If we have an output tile_size, we extract a region around the center of the given region.
output_tile_x, output_tile_y = self._output_tile_size
coordinates_x = x + w / 2 - output_tile_x / 2
coordinates_y = y + h / 2 - output_tile_y / 2
coordinates = (coordinates_x, coordinates_y)
region_size = self._output_tile_size

region = region_view.read_region(coordinates, region_size)

sample: TileSample = {
Expand Down Expand Up @@ -380,6 +394,7 @@ def __init__(
crop: bool = False,
mask: MaskTypes | None = None,
mask_threshold: float | None = 0.0,
output_tile_size: tuple[int, int] | None = None,
annotations: _AnnotationTypes | None = None,
labels: list[tuple[str, _LabelTypes]] | None = None,
transform: Callable[[RegionFromWsiDatasetSample], RegionFromWsiDatasetSample] | None = None,
Expand All @@ -400,6 +415,7 @@ def __init__(
crop,
mask=mask,
mask_threshold=mask_threshold,
output_tile_size=output_tile_size,
annotations=annotations,
labels=labels,
backend=backend,
Expand All @@ -418,6 +434,7 @@ def from_standard_tiling(
mpp: float | None,
tile_size: tuple[int, int],
tile_overlap: tuple[int, int],
output_tile_size: tuple[int, int] | None = None,
tile_mode: TilingMode = TilingMode.overflow,
grid_order: GridOrder = GridOrder.C,
crop: bool = False,
Expand All @@ -442,6 +459,9 @@ def from_standard_tiling(
Tuple of integers that represent the pixel size of output tiles
tile_overlap :
Tuple of integers that represents the overlap of tiles in the x and y direction
output_tile_size: tuple[int, int], optional
If this value is set, this value will be used as the tile size of the output tiles. If this value
is different from the underlying grid, this tile will be extracted around the center of the region.
tile_mode :
"skip" or "overflow". see `dlup.tiling.TilingMode` for more information
grid_order : GridOrder
Expand Down Expand Up @@ -523,6 +543,7 @@ def from_standard_tiling(
crop=crop,
mask=mask,
mask_threshold=mask_threshold,
output_tile_size=output_tile_size,
annotations=annotations,
labels=labels,
transform=transform,
Expand Down

0 comments on commit 137d7ff

Please sign in to comment.