From dd6c081c0e07ab5799e860e9450b8baf0debd5a4 Mon Sep 17 00:00:00 2001 From: "ogueler@idiap.ch" <ogueler@vws110.idiap.ch> Date: Mon, 3 Apr 2023 03:09:41 +0200 Subject: [PATCH] cleanup and formatting fix --- doc/install.rst | 2 +- doc/references.rst | 4 ++-- .../datasets/tbx11k_simplified/__init__.py | 6 ++--- .../data/tbx11k_simplified/__init__.py | 24 ++++++++++--------- .../data/tbx11k_simplified_RS/__init__.py | 24 +++++++++---------- src/ptbench/data/transforms.py | 22 ++++++++++++----- 6 files changed, 46 insertions(+), 36 deletions(-) diff --git a/doc/install.rst b/doc/install.rst index f15aee34..940f103a 100644 --- a/doc/install.rst +++ b/doc/install.rst @@ -150,7 +150,7 @@ Tuberculosis multilabel dataset ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The following dataset contains the labels healthy, sick & non-TB, active TB, -and latent TB. The implemented tbx11k dataset in this package is based on +and latent TB. The implemented tbx11k dataset in this package is based on the simplified version, which is just a more compact version of the original. In addition to the splits presented in the following table, 10 folds (for cross-validation) randomly generated are available for these datasets. diff --git a/doc/references.rst b/doc/references.rst index 037aa8d8..5a349fa9 100644 --- a/doc/references.rst +++ b/doc/references.rst @@ -60,12 +60,12 @@ diagnosing HIV-Associated tuberculosis in an emergency center.**, J. Acquir. Immune Defic. Syndr. 1999 81, e10–e14 (2019). -.. [TBX11K-2020] *Liu, Y., Wu, Y.-H., Ban, Y., Wang, H., and Cheng, M.-*, +.. [TBX11K-2020] *Liu, Y., Wu, Y.-H., Ban, Y., Wang, H., and Cheng, M.-*, **Rethinking computer-aided tuberculosis diagnosis.**, In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 2646–2655. -.. [TBX11K-SIMPLIFIED-2020] *Liu, Y., Wu, Y.-H., Ban, Y., Wang, H., and Cheng, M.-*, +.. [TBX11K-SIMPLIFIED-2020] *Liu, Y., Wu, Y.-H., Ban, Y., Wang, H., and Cheng, M.-*, **Rethinking computer-aided tuberculosis diagnosis.**, In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition, pages 2646–2655. diff --git a/src/ptbench/configs/datasets/tbx11k_simplified/__init__.py b/src/ptbench/configs/datasets/tbx11k_simplified/__init__.py index 643625e0..277fd087 100644 --- a/src/ptbench/configs/datasets/tbx11k_simplified/__init__.py +++ b/src/ptbench/configs/datasets/tbx11k_simplified/__init__.py @@ -7,7 +7,7 @@ def _maker(protocol, RGB=False): from torchvision import transforms from ....data.tbx11k_simplified import dataset as raw - from ....data.transforms import ElasticDeformation, RemoveBlackBorders, RGBtoGreyscale8bit + from ....data.transforms import ElasticDeformation, RGBtoGreyscale8bit from .. import make_dataset as mk post_transforms = [] @@ -19,9 +19,7 @@ def _maker(protocol, RGB=False): return mk( [raw.subsets(protocol)], - [ - RGBtoGreyscale8bit() - ], + [RGBtoGreyscale8bit()], [ElasticDeformation(p=0.8)], post_transforms, ) diff --git a/src/ptbench/data/tbx11k_simplified/__init__.py b/src/ptbench/data/tbx11k_simplified/__init__.py index e21d67fc..aa5abf05 100644 --- a/src/ptbench/data/tbx11k_simplified/__init__.py +++ b/src/ptbench/data/tbx11k_simplified/__init__.py @@ -32,19 +32,21 @@ from ..loader import load_pil_baw, make_delayed _protocols = [ importlib.resources.files(__name__).joinpath("default.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_0.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_1.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_2.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_3.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_4.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_5.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_6.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_7.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_8.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_9.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_0.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_1.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_2.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_3.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_4.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_5.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_6.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_7.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_8.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_9.json.bz2"), ] -_datadir = load_rc().get("datadir.tbx11k_simplified", os.path.realpath(os.curdir)) +_datadir = load_rc().get( + "datadir.tbx11k_simplified", os.path.realpath(os.curdir) +) def _raw_data_loader(sample): diff --git a/src/ptbench/data/tbx11k_simplified_RS/__init__.py b/src/ptbench/data/tbx11k_simplified_RS/__init__.py index 956ac0a4..8e782d45 100644 --- a/src/ptbench/data/tbx11k_simplified_RS/__init__.py +++ b/src/ptbench/data/tbx11k_simplified_RS/__init__.py @@ -2,8 +2,8 @@ # # SPDX-License-Identifier: GPL-3.0-or-later -"""Extended TBX11K simplified dataset for computer-aided diagnosis -(extended with DensenetRS predictions) +"""Extended TBX11K simplified dataset for computer-aided diagnosis (extended +with DensenetRS predictions) The TBX11K database has been established to foster research in computer-aided diagnosis of pulmonary diseases with a special @@ -31,16 +31,16 @@ from ..loader import make_delayed _protocols = [ importlib.resources.files(__name__).joinpath("default.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_0.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_1.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_2.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_3.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_4.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_5.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_6.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_7.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_8.json.bz2"), - #importlib.resources.files(__name__).joinpath("fold_9.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_0.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_1.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_2.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_3.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_4.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_5.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_6.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_7.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_8.json.bz2"), + # importlib.resources.files(__name__).joinpath("fold_9.json.bz2"), ] diff --git a/src/ptbench/data/transforms.py b/src/ptbench/data/transforms.py index 993839df..031bde89 100644 --- a/src/ptbench/data/transforms.py +++ b/src/ptbench/data/transforms.py @@ -41,15 +41,16 @@ class SingleAutoLevel16to8: ).astype("uint8"), ).convert("L") + class RGBtoGreyscale8bit: """Converts a 24-bit RGB image to an 8-bit greyscale representation. - + This transform assumes that the input image is RGB with 24 bits. Converts the RGB image to a greyscale image using the well-known formula: Y = 0.299 * R + 0.587 * G + 0.114 * B This formula is based on the relative luminance of the RGB channels in the sRGB color space - + consider such a range should be mapped to the [0,255] range of the destination image. """ @@ -57,14 +58,23 @@ class RGBtoGreyscale8bit: def __call__(self, img): # Use the formula to convert the RGB image to a greyscale image img_array = numpy.array(img).astype(float) - grey_array = 0.299 * img_array[:, :, 0] + 0.587 * img_array[:, :, 1] + 0.114 * img_array[:, :, 2] - + grey_array = ( + 0.299 * img_array[:, :, 0] + + 0.587 * img_array[:, :, 1] + + 0.114 * img_array[:, :, 2] + ) + # Normalize the greyscale image to the range [0, 255] and convert it to uint8 - grey_array = numpy.round(255.0 * (grey_array - grey_array.min()) / (grey_array.max() - grey_array.min())).astype('uint8') - + grey_array = numpy.round( + 255.0 + * (grey_array - grey_array.min()) + / (grey_array.max() - grey_array.min()) + ).astype("uint8") + # Create a new greyscale PIL image from the normalized array return PIL.Image.fromarray(grey_array).convert("L") + class RemoveBlackBorders: """Remove black borders of CXR.""" -- GitLab