Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pillow requirement from <9.0.0,>=8.4.0 to >=8.4.0,<10.0.0 #376

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
numpy >=1.18.4,<1.22.4
Pillow >=8.4.0,<9.0.0
Pillow >=9.1.0,<10.0.0
scikit-image >=0.19.0,<0.19.3
scipy >=1.5.0,<1.8.1
openslide-python
Expand Down
Binary file modified tests/expectations/mask-arrays/polygon-to-mask-array-1020.npy
Binary file not shown.
59 changes: 22 additions & 37 deletions tests/unit/test_masks.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from histolab.filters.image_filters import Compose, ImageFilter
from histolab.filters.morphological_filters import RemoveSmallObjects
from histolab.masks import BiggestTissueBoxMask, TissueMask
from histolab.slide import Slide
from histolab.tile import Tile
from histolab.types import CP, Region

Expand Down Expand Up @@ -75,32 +76,20 @@ def but_it_raises_exception_when_number_of_regions_is_wrong(

assert str(e.value) == expected_message

def it_knows_its_mask(
self,
request,
tmpdir,
RgbToGrayscale_,
OtsuThreshold_,
BinaryDilation_,
RemoveSmallHoles_,
RemoveSmallObjects_,
):
def it_knows_its_mask(self, request, tmpdir):
thumb_ = property_mock(request, Slide, "thumbnail")
thumb_.return_value = PILIMG.RGBA_COLOR_500X500_155_249_240
slide, _ = base_test_slide(tmpdir, PILIMG.RGBA_COLOR_500X500_155_249_240)
regions = [
Region(index=0, area=33, bbox=(0, 0, 2, 2), center=(0.5, 0.5), coords=None)
]
main_tissue_areas_mask_filters_ = property_mock(
request, _SlideFiltersComposition, "tissue_mask_filters"
)
main_tissue_areas_mask_filters_.return_value = Compose(
[
RgbToGrayscale_,
OtsuThreshold_,
BinaryDilation_,
RemoveSmallHoles_,
RemoveSmallObjects_,
]
)
RemoveSmallObjects_call = method_mock(request, RemoveSmallObjects, "__call__")
expected_mask = np.array([[True, True], [False, True]])
RemoveSmallObjects_call.return_value = expected_mask
main_tissue_areas_mask_filters_.return_value = Compose([RemoveSmallObjects()])
regions_from_binary_mask = function_mock(
request, "histolab.masks.regions_from_binary_mask"
)
Expand All @@ -112,36 +101,35 @@ def it_knows_its_mask(
region_coordinates_ = function_mock(
request, "histolab.masks.region_coordinates"
)
region_coordinates_.return_values = CP(0, 0, 2, 2)
rectangle_to_mask_ = function_mock(request, "histolab.util.rectangle_to_mask")
rectangle_to_mask_((1000, 1000), CP(0, 0, 2, 2)).return_value = [
[True, True],
[False, True],
]
region_coordinates_.return_value = CP(0, 0, 2, 2)
rectangle_to_mask_ = function_mock(request, "histolab.masks.rectangle_to_mask")
rectangle_to_mask_.return_value = expected_mask
biggest_mask_tissue_box = BiggestTissueBoxMask()

binary_mask = biggest_mask_tissue_box(slide)

np.testing.assert_almost_equal(binary_mask, np.zeros((500, 500)))
np.testing.assert_almost_equal(binary_mask, expected_mask)
region_coordinates_.assert_called_once_with(regions[0])
biggest_regions_.assert_called_once_with(regions, n=1)
rectangle_to_mask_.assert_called_once_with(
(1000, 1000), CP(x_ul=0, y_ul=0, x_br=2, y_br=2)
(500, 500), CP(x_ul=0, y_ul=0, x_br=2, y_br=2)
)

def it_knows_its_mask_and_supports_custom_filters(self, request, tmpdir):
thumb_ = property_mock(request, Slide, "thumbnail")
thumb_.return_value = PILIMG.RGBA_COLOR_500X500_155_249_240
slide, _ = base_test_slide(tmpdir, PILIMG.RGBA_COLOR_500X500_155_249_240)
regions = [
Region(index=0, area=33, bbox=(0, 0, 2, 2), center=(0.5, 0.5), coords=None)
]
custom_filter_composition_filters_ = property_mock(
request, _CustomFiltersComposition, "tissue_mask_filters"
)
custom_filters = [CustomFilterForTest()]
custom_filter_call_ = method_mock(request, CustomFilterForTest, "__call__")
expected_mask = np.array([[True, True], [False, True]])
custom_filter_composition_filters_.return_value = Compose(custom_filters)
custom_filter_call_.return_value = expected_mask
custom_filters = [CustomFilterForTest()]
custom_filter_composition_filters_.return_value = Compose(custom_filters)
regions_from_binary_mask = function_mock(
request, "histolab.masks.regions_from_binary_mask"
)
Expand All @@ -153,24 +141,21 @@ def it_knows_its_mask_and_supports_custom_filters(self, request, tmpdir):
region_coordinates_ = function_mock(
request, "histolab.masks.region_coordinates"
)
region_coordinates_.return_values = CP(0, 0, 2, 2)
rectangle_to_mask_ = function_mock(request, "histolab.util.rectangle_to_mask")
rectangle_to_mask_((1000, 1000), CP(0, 0, 2, 2)).return_value = [
[True, True],
[False, True],
]
region_coordinates_.return_value = CP(0, 0, 2, 2)
rectangle_to_mask_ = function_mock(request, "histolab.masks.rectangle_to_mask")
rectangle_to_mask_.return_value = expected_mask
biggest_mask_tissue_box = BiggestTissueBoxMask(*custom_filters)

binary_mask = biggest_mask_tissue_box(slide)

np.testing.assert_almost_equal(binary_mask, np.zeros((500, 500)))
np.testing.assert_almost_equal(binary_mask, expected_mask)
np.testing.assert_array_almost_equal(
regions_from_binary_mask.call_args_list[0][0][0], expected_mask
)
region_coordinates_.assert_called_once_with(regions[0])
biggest_regions_.assert_called_once_with(regions, n=1)
rectangle_to_mask_.assert_called_once_with(
(1000, 1000), CP(x_ul=0, y_ul=0, x_br=2, y_br=2)
(500, 500), CP(x_ul=0, y_ul=0, x_br=2, y_br=2)
)


Expand Down