diff --git a/tests/test_image_utils.py b/tests/test_image_utils.py index e02273f9747e9a310a0c17594b92834f3070e8de..420fdf043bc9fe7bba1ee223b685698ee3010e03 100644 --- a/tests/test_image_utils.py +++ b/tests/test_image_utils.py @@ -6,7 +6,7 @@ import numpy import PIL.Image -from ptbench.data.image_utils import RemoveBlackBorders +from ptbench.data.image_utils import remove_black_borders def test_remove_black_borders(datadir): @@ -15,8 +15,7 @@ def test_remove_black_borders(datadir): raw_with_black_border = PIL.Image.open(data_file) # Remove the black border - rbb = RemoveBlackBorders() - raw_rbb_removed = rbb(raw_with_black_border) + raw_rbb_removed = remove_black_borders(raw_with_black_border) # Get the same sample without black border data_file_2 = str(datadir / "raw_without_black_border.png") @@ -29,23 +28,13 @@ def test_remove_black_borders(datadir): numpy.testing.assert_array_equal(raw_without_black_border, raw_rbb_removed) -# def test_load_pil_16bit(datadir): -# # If the ratio is higher 0.5, image is probably clipped -# Level16to8 = SingleAutoLevel16to8() -# -# data_file = str(datadir / "16bits.png") -# image = numpy.array(Level16to8(load_pil(data_file))) -# -# count_pixels = numpy.count_nonzero(image) -# count_max_value = numpy.count_nonzero(image == image.max()) -# -# assert count_max_value / count_pixels < 0.5 -# -# # It should not do anything to an image already in 8 bits -# data_file = str(datadir / "raw_without_black_border.png") -# img_loaded = load_pil(data_file) -# -# original_8bits = numpy.array(img_loaded) -# leveled_8bits = numpy.array(Level16to8(img_loaded)) -# -# numpy.testing.assert_array_equal(original_8bits, leveled_8bits) +def test_load_pil_16bit(datadir): + # If the ratio is higher 0.5, image is probably clipped + + image = PIL.Image.open(datadir / "16bits.png") + array = numpy.array(image).astype(numpy.float32) / 65535 + + count_pixels = numpy.count_nonzero(array) + count_max_value = numpy.count_nonzero(array == array.max()) + + assert count_max_value / count_pixels < 0.5