Thanks to visit codestin.com
Credit goes to github.com

Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 0 additions & 24 deletions src/histolab/filters/image_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,30 +953,6 @@ def __repr__(self) -> str:
return self.__class__.__name__ + "()"


class PenMarks:
"""Filter out pen marks from a diagnostic slide.

Pen marks are removed by applying Otsu threshold on the H channel of the image
converted to the HSV space.

Parameters
---------
img : PIL.Image.Image
Input RGB image

Returns
-------
np.ndarray
Boolean NumPy array representing the mask with the pen marks filtered out.
"""

def __call__(self, img: PIL.Image.Image) -> PIL.Image.Image:
return F.pen_marks(img)

def __repr__(self) -> str:
return self.__class__.__name__ + "()"


class YenThreshold:
"""Mask image based on pixel above Yen threshold.

Expand Down
25 changes: 0 additions & 25 deletions src/histolab/filters/image_filters_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -836,31 +836,6 @@ def otsu_threshold(
return threshold_to_mask(image, otsu_thresh, relate)


def pen_marks(img: PIL.Image.Image) -> np.ndarray:
"""Filter out pen marks from a diagnostic slide.

Pen marks are removed by applying Otsu threshold on the H channel of the image
converted to the HSV space.

Parameters
---------
img : PIL.Image.Image
Input RGB image

Returns
-------
np.ndarray
Boolean NumPy array representing the mask with the pen marks filtered out.
"""
if img.mode == "RGBA":
raise ValueError("Image input must be RGB, got RGBA.")
np_img = np.array(img)
np_hsv = sk_color.convert_colorspace(np_img, "RGB", "HSV")
hue = np_hsv[:, :, 0]
threshold = sk_filters.threshold_otsu(hue)
return threshold_to_mask(hue, threshold, operator.gt)


def red_filter(
img: PIL.Image.Image, red_thresh: int, green_thresh: int, blue_thresh: int
) -> np.ndarray:
Expand Down
37 changes: 1 addition & 36 deletions tests/integration/test_image_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -1282,40 +1282,6 @@ def test_green_channel_filter_with_wrong_threshold(green_threshold):
assert str(err.value) == "threshold must be in range [0, 255]"


@pytest.mark.parametrize(
"rgb_img, expectation",
(
(
RGB.DIAGNOSTIC_SLIDE_THUMB_RGB,
"mask-arrays/diagnostic-slide-thumb-rgb-pen-marks-mask",
),
(
RGB.DIAGNOSTIC_SLIDE_THUMB_HSV,
"mask-arrays/diagnostic-slide-thumb-hsv-pen-marks-mask",
),
(
RGB.DIAGNOSTIC_SLIDE_THUMB_YCBCR,
"mask-arrays/diagnostic-slide-thumb-ycbcr-pen-marks-mask",
),
(RGB.TCGA_LUNG_RGB, "mask-arrays/tcga-lung-rgb-pen-marks-mask"),
),
)
def test_pen_marks_filter_on_rgb_image(rgb_img, expectation):
pen_marks_filter = imf.pen_marks(rgb_img)

np.testing.assert_array_equal(
pen_marks_filter, load_expectation(expectation, type_="npy")
)


def test_pen_marks_filter_with_wrong_img_mode():
with pytest.raises(ValueError) as err:
imf.pen_marks(RGBA.DIAGNOSTIC_SLIDE_THUMB)

assert isinstance(err.value, ValueError)
assert str(err.value) == "Image input must be RGB, got RGBA."


@pytest.mark.parametrize(
"pil_img, red_thresh, green_thresh, blue_thresh, expected_value",
(
Expand Down Expand Up @@ -1704,8 +1670,7 @@ def test_rgb_to_lab_filter_with_rgb_image(pil_image, expected_image):


@pytest.mark.parametrize(
"pil_image",
(RGBA.DIAGNOSTIC_SLIDE_THUMB, GS.DIAGNOSTIC_SLIDE_THUMB_GS),
"pil_image", (RGBA.DIAGNOSTIC_SLIDE_THUMB, GS.DIAGNOSTIC_SLIDE_THUMB_GS),
)
def test_rgb_to_lab_raises_exception_on_gs_and_rgba_image(pil_image):
with pytest.raises(Exception) as err:
Expand Down
13 changes: 0 additions & 13 deletions tests/unit/filters/test_image_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,19 +348,6 @@ def it_calls_blue_pen_filter_functional(self, request):
F_blue_pen_filter.assert_called_once_with(image)
assert type(blue_pen_filter(image)) == np.ndarray

def it_calls_pen_marks_filter_functional(self, request):
image = PILIMG.RGBA_COLOR_500X500_155_249_240
F_pen_marks = function_mock(
request, "histolab.filters.image_filters_functional.pen_marks"
)
F_pen_marks.return_value = np.array(image)
pen_marks = imf.PenMarks()

pen_marks(image)

F_pen_marks.assert_called_once_with(image)
assert type(pen_marks(image)) == np.ndarray

def it_calls_np_to_pil(self, request):
array = NpArrayMock.ONES_30X30_UINT8
util_np_to_pil = function_mock(request, "histolab.util.np_to_pil")
Expand Down