Skip to content
Snippets Groups Projects
Commit dd6c081c authored by ogueler@idiap.ch's avatar ogueler@idiap.ch
Browse files

cleanup and formatting fix

parent a139fcc3
No related branches found
No related tags found
2 merge requests!5Tbx11k,!4Moved code to lightning
...@@ -150,7 +150,7 @@ Tuberculosis multilabel dataset ...@@ -150,7 +150,7 @@ Tuberculosis multilabel dataset
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
The following dataset contains the labels healthy, sick & non-TB, active TB, 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. 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 In addition to the splits presented in the following table, 10 folds
(for cross-validation) randomly generated are available for these datasets. (for cross-validation) randomly generated are available for these datasets.
......
...@@ -60,12 +60,12 @@ ...@@ -60,12 +60,12 @@
diagnosing HIV-Associated tuberculosis in an emergency center.**, diagnosing HIV-Associated tuberculosis in an emergency center.**,
J. Acquir. Immune Defic. Syndr. 1999 81, e10–e14 (2019). 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.**, **Rethinking computer-aided tuberculosis diagnosis.**,
In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern
Recognition, pages 2646–2655. 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.**, **Rethinking computer-aided tuberculosis diagnosis.**,
In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern
Recognition, pages 2646–2655. Recognition, pages 2646–2655.
...@@ -7,7 +7,7 @@ def _maker(protocol, RGB=False): ...@@ -7,7 +7,7 @@ def _maker(protocol, RGB=False):
from torchvision import transforms from torchvision import transforms
from ....data.tbx11k_simplified import dataset as raw 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 from .. import make_dataset as mk
post_transforms = [] post_transforms = []
...@@ -19,9 +19,7 @@ def _maker(protocol, RGB=False): ...@@ -19,9 +19,7 @@ def _maker(protocol, RGB=False):
return mk( return mk(
[raw.subsets(protocol)], [raw.subsets(protocol)],
[ [RGBtoGreyscale8bit()],
RGBtoGreyscale8bit()
],
[ElasticDeformation(p=0.8)], [ElasticDeformation(p=0.8)],
post_transforms, post_transforms,
) )
...@@ -32,19 +32,21 @@ from ..loader import load_pil_baw, make_delayed ...@@ -32,19 +32,21 @@ from ..loader import load_pil_baw, make_delayed
_protocols = [ _protocols = [
importlib.resources.files(__name__).joinpath("default.json.bz2"), importlib.resources.files(__name__).joinpath("default.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_0.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_1.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_2.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_3.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_4.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_5.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_6.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_7.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_8.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_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): def _raw_data_loader(sample):
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
# #
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
"""Extended TBX11K simplified dataset for computer-aided diagnosis """Extended TBX11K simplified dataset for computer-aided diagnosis (extended
(extended with DensenetRS predictions) with DensenetRS predictions)
The TBX11K database has been established to foster research The TBX11K database has been established to foster research
in computer-aided diagnosis of pulmonary diseases with a special in computer-aided diagnosis of pulmonary diseases with a special
...@@ -31,16 +31,16 @@ from ..loader import make_delayed ...@@ -31,16 +31,16 @@ from ..loader import make_delayed
_protocols = [ _protocols = [
importlib.resources.files(__name__).joinpath("default.json.bz2"), importlib.resources.files(__name__).joinpath("default.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_0.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_1.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_2.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_3.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_4.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_5.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_6.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_7.json.bz2"),
#importlib.resources.files(__name__).joinpath("fold_8.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_9.json.bz2"),
] ]
......
...@@ -41,15 +41,16 @@ class SingleAutoLevel16to8: ...@@ -41,15 +41,16 @@ class SingleAutoLevel16to8:
).astype("uint8"), ).astype("uint8"),
).convert("L") ).convert("L")
class RGBtoGreyscale8bit: class RGBtoGreyscale8bit:
"""Converts a 24-bit RGB image to an 8-bit greyscale representation. """Converts a 24-bit RGB image to an 8-bit greyscale representation.
This transform assumes that the input image is RGB with 24 bits. 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: Converts the RGB image to a greyscale image using the well-known formula:
Y = 0.299 * R + 0.587 * G + 0.114 * B 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 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 consider such a range should be mapped to the [0,255] range of the
destination image. destination image.
""" """
...@@ -57,14 +58,23 @@ class RGBtoGreyscale8bit: ...@@ -57,14 +58,23 @@ class RGBtoGreyscale8bit:
def __call__(self, img): def __call__(self, img):
# Use the formula to convert the RGB image to a greyscale image # Use the formula to convert the RGB image to a greyscale image
img_array = numpy.array(img).astype(float) 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 # 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 # Create a new greyscale PIL image from the normalized array
return PIL.Image.fromarray(grey_array).convert("L") return PIL.Image.fromarray(grey_array).convert("L")
class RemoveBlackBorders: class RemoveBlackBorders:
"""Remove black borders of CXR.""" """Remove black borders of CXR."""
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment