Skip to content

Commit

Permalink
Fix edge case bug where grayscale image has an alpha channel, minor r…
Browse files Browse the repository at this point in the history
…td fix (#1313)

* Fix edge case bug where grayscale image has an alpha channel

* Try doc fix

* Try doc fix

* Unpin spinx

* Refactor color/alpha -> greyscale for clarity (Joshua's code

* Fix syntax typo

* Fix assignement

* Test debug cleanup

* Keep singleton dimension

* Fix casting

* Update ivadomed/loader/segmentation_pair.py

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>

* Update ivadomed/loader/segmentation_pair.py

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>

* Update ivadomed/loader/segmentation_pair.py

Co-authored-by: Kanishk Kalra <36276423+kanishk16@users.noreply.github.com>

* Revert to initial solution

* Update ivadomed/loader/segmentation_pair.py

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>

* Update ivadomed/loader/segmentation_pair.py

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>

* Update data-testing release

---------

Co-authored-by: Joshua Newton <joshuacwnewton@gmail.com>
Co-authored-by: Kanishk Kalra <36276423+kanishk16@users.noreply.github.com>
  • Loading branch information
3 people committed Jan 30, 2024
1 parent 4c95d01 commit 881dc68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions ivadomed/loader/segmentation_pair.py
Expand Up @@ -350,17 +350,19 @@ def convert_file_to_nifti(self, filename: str, extension: str, is_gt: bool = Fal
# Note: All of these are trivially true for JPEG and PNG due to limitations of these formats.

# make grayscale (treats binary as 1-bit grayscale)
colorspace_idx = 2 + int(props.is_batch)
colorspace_idx = 2
if _img.ndim <= colorspace_idx: # binary or gray
pass # nothing to do
elif _img.shape[colorspace_idx] == 2: # gray with alpha channel
_img = _img[:, :, 0]
elif _img.shape[colorspace_idx] == 3: # RGB
_img = np.sum(_img * (.299, .587, .114), axis=-1)
else: # RGBA
# discards alpha
_img = np.sum(_img * (.299, .587, .114, 0), axis=-1)
if len(_img.shape) < 3:
_img = np.expand_dims(_img, axis=-1)

img = imageio.core.image_as_uint(_img, bitdepth=8)

# Binarize ground-truth values (0-255) to 0 and 1 in uint8 with threshold 0.5
Expand Down
2 changes: 1 addition & 1 deletion ivadomed/scripts/download_data.py
Expand Up @@ -23,7 +23,7 @@
`Spine Generic <https://github.com/spine-generic/data-multi-subject>`_.
Used for Tutorial and example in Ivadomed."""},
"data_testing": {
"url": ["https://github.com/ivadomed/data-testing/archive/r20220328.zip"],
"url": ["https://github.com/ivadomed/data-testing/archive/r20240130.zip"],
"description": "Data Used for integration/unit test in Ivadomed."},
"data_multi_testing": {
"url": ["https://github.com/MotionCorrect/data_multi-sessions-contrasts/archive/refs/tags/v2022-01-06.zip"],
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Expand Up @@ -23,9 +23,9 @@
# https://github.com/readthedocs/readthedocs.org/blob/ecac31de54bbb2c100f933e86eb22b0f4389ba84/requirements/pip.txt#L16
'sphinx',
'sphinx_rtd_theme',
'sphinx-tabs==3.2.0',
'sphinx-toolbox==2.15.2',
'sphinx-jsonschema~=1.16',
'sphinx-tabs',
'sphinx-toolbox',
'sphinx-jsonschema',
'pypandoc',
],
'tests': [
Expand Down

0 comments on commit 881dc68

Please sign in to comment.