Skip to content

Commit

Permalink
image_as_rgb correctly handles images that are already RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
Erik-White committed Jun 7, 2020
1 parent 75d51fc commit 0228400
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/colonyscanalyser/imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ def image_as_rgb(image: ndarray) -> ndarray:
return gray2rgb(image)

# Remove alpha channel if present
return rgba2rgb(image)
if image.shape[-1] == 4:
image = rgba2rgb(image)

return image


def remove_background_mask(image: ndarray, smoothing: float = 1, sigmoid_cutoff: float = 0.4, **filter_args) -> ndarray:
Expand Down
11 changes: 11 additions & 0 deletions tests/unit/test_imaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,17 @@ def test_grayscale(self, image):
assert len(result.shape) == 3
assert result.shape[-1] == 3

def test_rgb(self, image):
from numpy import empty

image = empty(image.shape + (3, ), dtype = image.dtype)
result = image_as_rgb(image)

assert len(image.shape) == 3
assert image.shape[-1] == 3
assert len(result.shape) == 3
assert result.shape[-1] == 3

def test_rgba(self, image):
from numpy import empty

Expand Down

0 comments on commit 0228400

Please sign in to comment.