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
6 changes: 3 additions & 3 deletions histolab/filters/image_filters_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,13 +476,13 @@ def rgb_to_hed(img: PIL.Image.Image) -> PIL.Image.Image:
if img.mode not in ["RGB", "RGBA"]:
raise Exception("Input image must be RGB.")
if img.mode == "RGBA":
img_arr = np.array(sk_color.rgba2rgb(img))
red, green, blue, _ = img.split()
img = PIL.Image.merge("RGB", (red, green, blue))
warn(
"Input image must be RGB. "
"NOTE: the image will be converted to RGB before HED conversion."
)
else:
img_arr = np.array(img)
img_arr = np.array(img)
hed_arr = sk_color.rgb2hed(img_arr)
hed = np_to_pil(hed_arr)

Expand Down
Binary file not shown.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file modified tests/expectations/pil-images-rgb/tcga-lung-rgb-dab-channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expectations/pil-images-rgba/tcga-lung-dab-channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/expectations/pil-images-rgba/tcga-lung-eosin-channel.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
48 changes: 7 additions & 41 deletions tests/integration/test_image_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,12 @@ def test_invert_filter_with_gs_image():
)


@pytest.mark.parametrize(
"pil_image, expected_image",
(
(
RGB.DIAGNOSTIC_SLIDE_THUMB_RGB,
"pil-images-rgb/diagnostic-slide-thumb-rgb-to-hed",
),
(
RGB.DIAGNOSTIC_SLIDE_THUMB_HSV,
"pil-images-rgb/diagnostic-slide-thumb-hsv-rgb-to-hed",
),
(
RGB.DIAGNOSTIC_SLIDE_THUMB_YCBCR,
"pil-images-rgb/diagnostic-slide-thumb-ycbcr-rgb-to-hed",
),
),
)
def test_rgb_to_hed_filter_with_rgb_image(pil_image, expected_image):
expected_value = load_expectation(expected_image, type_="png")
def test_rgb_to_hed_filter_with_rgb_image():
expected_value = load_expectation(
"pil-images-rgb/diagnostic-slide-thumb-rgb-to-hed", type_="png"
)

hed_img = imf.rgb_to_hed(pil_image)
hed_img = imf.rgb_to_hed(RGB.DIAGNOSTIC_SLIDE_THUMB_RGB)

np.testing.assert_array_almost_equal(np.array(hed_img), np.array(expected_value))
assert np.unique(np.array(ImageChops.difference(hed_img, expected_value)))[0] == 0
Expand Down Expand Up @@ -509,25 +494,6 @@ def test_local_equalization_raises_exception_on_rgb_images(pil_rgb_image):
assert str(err.value) == "Input must be 2D."


def test_kmeans_segmentation_filter_on_rgba_image():
rgba_img = RGBA.DIAGNOSTIC_SLIDE_THUMB
expected_value = load_expectation(
"pil-images-rgba/diagnostic-slide-thumb-kmeans-segmentation", type_="png"
)

kmeans_segmentation_img = imf.kmeans_segmentation(rgba_img, 800, 10)

np.testing.assert_array_almost_equal(
np.array(kmeans_segmentation_img), np.array(expected_value)
)
assert (
np.unique(
np.array(ImageChops.difference(kmeans_segmentation_img, expected_value))
)[0]
== 0
)


def test_kmeans_segmentation_raises_value_error_on_rgba_images():
rgba_img = RGBA.DIAGNOSTIC_SLIDE_THUMB

Expand Down Expand Up @@ -574,7 +540,7 @@ def test_kmeans_segmentation_filter_on_rgb_image(pil_image, expected_image):
def test_kmeans_segmentation_filter_on_gs_image():
gs_img = GS.DIAGNOSTIC_SLIDE_THUMB_GS
expected_value = load_expectation(
"pil-images-gs/diagnostic-slide-thumb-gs-kmeans-segmentation", type_="png"
"pil-images-rgb/diagnostic-slide-thumb-gs-kmeans-segmentation", type_="png"
)

kmeans_segmentation_img = imf.kmeans_segmentation(gs_img, 800, 10)
Expand Down Expand Up @@ -624,7 +590,7 @@ def test_rag_threshold_filter_on_rgb_image(pil_image, expected_image):
def test_rag_threshold_filter_on_gs_image():
gs_img = GS.DIAGNOSTIC_SLIDE_THUMB_GS
expected_value = load_expectation(
"pil-images-gs/diagnostic-slide-thumb-gs-rag-threshold", type_="png"
"pil-images-rgb/diagnostic-slide-thumb-gs-rag-threshold", type_="png"
)

rag_threshold_img = imf.rag_threshold(gs_img, 650, 20.6, 15)
Expand Down
114 changes: 53 additions & 61 deletions tests/integration/test_scorer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import pytest
from histolab.tile import Tile

from histolab import scorer
from histolab.tile import Tile

from ..fixtures import TILES

Expand All @@ -11,38 +11,30 @@ class Describe_Scorers:
"tile_img, expected_score",
(
# level 0
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, 4.95387907194613e-05),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, 0.011112025501054716),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, 0.018651677436394662),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, 0.39901978131493154),
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, 0.0042),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, 0.03001),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, 0.266),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, 0.008),
# level 1
(
TILES.VERY_LOW_NUCLEI_SCORE_RED_PEN_LEVEL1,
0.0017590279896743531,
), # breast - red pen
(TILES.LOW_NUCLEI_SCORE_LEVEL1, 0.019689596845556157), # breast - green pen
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, 0.009512701556682022), # aorta
(
TILES.MEDIUM_NUCLEI_SCORE_LEVEL1_2,
0.1519627864167197,
), # breast - green pen
(
TILES.MEDIUM_NUCLEI_SCORE_GREEN_PEN_LEVEL1,
0.35696740368342295,
), # breast - green pen
(
TILES.HIGH_NUCLEI_SCORE_RED_PEN_LEVEL1,
0.19867406253648537,
0.10605,
), # breast - red pen
(TILES.LOW_NUCLEI_SCORE_LEVEL1, 0.00704), # breast - green pen
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, 0.08904), # aorta
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1_2, 0.09247), # breast - green pen
(TILES.MEDIUM_NUCLEI_SCORE_GREEN_PEN_LEVEL1, 0.08088),
# breast - green pen
(TILES.HIGH_NUCLEI_SCORE_RED_PEN_LEVEL1, 0.10297), # breast - red pen
# level 2
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, 0.17959041877765877), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, 0.02165773137397028), # prostate
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, 0.00337), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, 0.00217), # prostate
# no tissue
(TILES.NO_TISSUE, 6.677516254309149e-07),
(TILES.NO_TISSUE2, 7.505964521573081e-06),
(TILES.NO_TISSUE_LINE, 0.00028575083246431935),
(TILES.NO_TISSUE_RED_PEN, 0.2051245888881937),
(TILES.NO_TISSUE_GREEN_PEN, 0.28993597176882124),
(TILES.NO_TISSUE, 0.0),
(TILES.NO_TISSUE2, 0.0),
(TILES.NO_TISSUE_LINE, 0.00026),
(TILES.NO_TISSUE_RED_PEN, 0.20831),
(TILES.NO_TISSUE_GREEN_PEN, 0.23808),
),
)
def it_knows_nuclei_score(self, tile_img, expected_score):
Expand All @@ -62,86 +54,86 @@ def it_knows_nuclei_score(self, tile_img, expected_score):
"tile_img, tissue, expected_score",
(
# level 0
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, True, 8.237973509211956e-05),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, True, 0.029559623811739984),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, True, 0.030890383076685523),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, True, 0.5452530357003211),
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, True, 0.01494),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, True, 0.13681),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, True, 0.48335),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, True, 0.01808),
# level 1
(
TILES.VERY_LOW_NUCLEI_SCORE_RED_PEN_LEVEL1,
True,
0.01610148106450298,
0.76041,
), # breast - red pen
(
TILES.LOW_NUCLEI_SCORE_LEVEL1,
True,
0.1887327689375471,
0.07103,
), # breast - green pen
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, True, 0.04807442622295907), # aorta
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, True, 0.39569), # aorta
(
TILES.MEDIUM_NUCLEI_SCORE_LEVEL1_2,
True,
0.23493428091089713,
0.15244,
), # breast - green pen
(
TILES.MEDIUM_NUCLEI_SCORE_GREEN_PEN_LEVEL1,
True,
0.6710679905294349,
0.15774,
), # breast - green pen
(
TILES.HIGH_NUCLEI_SCORE_RED_PEN_LEVEL1,
True,
0.30155274716806657,
0.21587,
), # breast - red pen
# level 2
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, True, 0.40466129363258146), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, True, 0.906540012633011), # prostate
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, True, 0.02112), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, True, 0.18165), # prostate
# no tissue
(TILES.NO_TISSUE, True, 0.05299860529986053),
(TILES.NO_TISSUE2, True, 0.003337363966142684),
(TILES.NO_TISSUE_LINE, True, 0.3471366793342943),
(TILES.NO_TISSUE_RED_PEN, True, 0.7135526324697217),
(TILES.NO_TISSUE_GREEN_PEN, True, 0.6917688745017198),
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, False, 8.168825750149552e-05),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, False, 0.024471282958984375),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, False, 0.028293456864885436),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, False, 0.5430199644432031),
(TILES.NO_TISSUE, True, 0.05021),
(TILES.NO_TISSUE2, True, 0.00203),
(TILES.NO_TISSUE_LINE, True, 0.31477),
(TILES.NO_TISSUE_RED_PEN, True, 0.72669),
(TILES.NO_TISSUE_GREEN_PEN, True, 0.56731),
(TILES.VERY_LOW_NUCLEI_SCORE_LEVEL0, False, 0.01482),
(TILES.LOW_NUCLEI_SCORE_LEVEL0, False, 0.11326),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL0, False, 0.44272),
(TILES.HIGH_NUCLEI_SCORE_LEVEL0, False, 0.01801),
# level 1
(
TILES.VERY_LOW_NUCLEI_SCORE_RED_PEN_LEVEL1,
False,
0.006328582763671875,
0.29887,
), # breast - red pen
(
TILES.LOW_NUCLEI_SCORE_LEVEL1,
False,
0.064971923828125,
0.02445,
), # breast - green pen
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, False, 0.036724090576171875),
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL1, False, 0.30227),
(
TILES.MEDIUM_NUCLEI_SCORE_LEVEL1_2,
False,
0.23455429077148438,
0.15219,
), # breast - green pen
(
TILES.MEDIUM_NUCLEI_SCORE_GREEN_PEN_LEVEL1,
False,
0.5416870117187,
0.12733,
), # breast - green pen
(
TILES.HIGH_NUCLEI_SCORE_RED_PEN_LEVEL1,
False,
0.2985572814941406,
0.21373,
), # breast - red pen
# level 2
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, False, 0.3309669494628906), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, False, 0.14234542846679688), # prostate
(TILES.MEDIUM_NUCLEI_SCORE_LEVEL2, False, 0.01728), # prostate
(TILES.HIGH_NUCLEI_SCORE_LEVEL2, False, 0.02852), # prostate
# no tissue
(TILES.NO_TISSUE, False, 0.0002899169921875),
(TILES.NO_TISSUE2, False, 0.000263214111328125),
(TILES.NO_TISSUE_LINE, False, 0.010105133056640625),
(TILES.NO_TISSUE_RED_PEN, False, 0.4020729064941406),
(TILES.NO_TISSUE_GREEN_PEN, False, 0.48259735107421875),
(TILES.NO_TISSUE, False, 0.00027),
(TILES.NO_TISSUE2, False, 0.00016),
(TILES.NO_TISSUE_LINE, False, 0.00916),
(TILES.NO_TISSUE_RED_PEN, False, 0.40948),
(TILES.NO_TISSUE_GREEN_PEN, False, 0.39577),
),
)
def it_knows_cellularity_score(self, tile_img, tissue, expected_score):
Expand Down