Skip to content

Commit

Permalink
Even with check_tissue=False, the tiles will be extracted within the …
Browse files Browse the repository at this point in the history
…tissue box
  • Loading branch information
alessiamarcolini authored and nicolebussola committed Jun 23, 2020
1 parent cc417ec commit c6fd5e1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 15 deletions.
13 changes: 3 additions & 10 deletions src/histolab/tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def max_iter(self, max_iter_: int = 1e4):
def box_mask(self, slide: Slide) -> sparse._coo.core.COO:
"""Return binary mask at level 0 of the box to consider for tiles extraction.
If `check_tissue` attribute is True, the mask pixels set to True will be the
ones corresponding to the tissue box. Otherwise, all the mask pixels will be set
to True.
The mask pixels set to True will be the ones corresponding to the tissue box.
Parameters
----------
Expand All @@ -116,18 +114,13 @@ def box_mask(self, slide: Slide) -> sparse._coo.core.COO:
Extraction mask at level 0
"""

if self.check_tissue:
return slide.biggest_tissue_box_mask
else:
return sparse.ones(slide.dimensions[::-1], dtype=bool)
return slide.biggest_tissue_box_mask

@lru_cache(maxsize=100)
def box_mask_lvl(self, slide: Slide) -> sparse._coo.core.COO:
"""Return binary mask at target level of the box to consider for the extraction.
If ``check_tissue`` attribute is True, the mask pixels set to True will be the
ones corresponding to the tissue box. Otherwise, all the mask pixels will be set
to True.
The mask pixels set to True will be the ones corresponding to the tissue box.
Parameters
----------
Expand Down
8 changes: 3 additions & 5 deletions tests/unit/test_tiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ def it_can_generate_random_coordinates(self, request, tmpdir):
@pytest.mark.parametrize(
"check_tissue, expected_box",
(
(False, SparseArrayMock.ONES_500X500_BOOL),
(False, SparseArrayMock.RANDOM_500X500_BOOL),
(True, SparseArrayMock.RANDOM_500X500_BOOL),
),
)
Expand All @@ -165,14 +165,12 @@ def it_knows_its_box_mask(self, request, tmpdir, check_tissue, expected_box):
_biggest_tissue_box_mask = property_mock(
request, Slide, "biggest_tissue_box_mask"
)
if check_tissue:
_biggest_tissue_box_mask.return_value = expected_box
_biggest_tissue_box_mask.return_value = expected_box
random_tiler = RandomTiler((128, 128), 10, 0, check_tissue=check_tissue)

box_mask = random_tiler.box_mask(slide)

if check_tissue:
_biggest_tissue_box_mask.assert_called_once_with()
_biggest_tissue_box_mask.assert_called_once_with()
assert type(box_mask) == sparse._coo.core.COO
np.testing.assert_array_almost_equal(box_mask.todense(), expected_box.todense())

Expand Down

0 comments on commit c6fd5e1

Please sign in to comment.