|
2 | 2 | import os |
3 | 3 |
|
4 | 4 | import numpy as np |
| 5 | +import numpy.testing as npt |
5 | 6 | import pytest |
6 | 7 | from skimage.morphology import diamond |
7 | 8 |
|
8 | | -from PartSegImage import Channel, ChannelInfo, Image, ImageWriter, TiffImageReader |
| 9 | +from PartSegImage import Channel, ChannelInfo, ChannelInfoFull, Image, ImageWriter, TiffImageReader |
9 | 10 | from PartSegImage.image import FRAME_THICKNESS, _hex_to_rgb, _name_to_rgb |
10 | 11 |
|
11 | 12 |
|
@@ -728,3 +729,44 @@ def test_name_to_rgb_vispy(): |
728 | 729 | # This test check mapping not defined in fallback dictionary |
729 | 730 | pytest.importorskip("vispy", reason="vispy not installed") |
730 | 731 | assert _name_to_rgb("lime") == (0, 255, 0) |
| 732 | + |
| 733 | + |
| 734 | +class TestChannelInfoFull: |
| 735 | + RED_DEF = (255, 0, 0) |
| 736 | + RED_2D_REF = [[0, 255], [0, 0], [0, 0]] |
| 737 | + |
| 738 | + def test_str(self): |
| 739 | + obj = ChannelInfoFull(name="test", color_map="gray", contrast_limits=(0, 20)) |
| 740 | + assert obj.name == "test" |
| 741 | + assert obj.color_map == "gray" |
| 742 | + assert obj.contrast_limits == (0, 20) |
| 743 | + |
| 744 | + @pytest.mark.parametrize("color_map", [tuple(RED_DEF), np.array(RED_DEF, dtype=np.uint8), list(RED_DEF)]) |
| 745 | + def test_1d_colormap(self, color_map): |
| 746 | + obj = ChannelInfoFull(name="test", color_map=color_map, contrast_limits=(0, 20)) |
| 747 | + assert obj.name == "test" |
| 748 | + assert np.all(obj.contrast_limits == (0, 20)) |
| 749 | + assert isinstance(obj.color_map, np.ndarray) |
| 750 | + assert obj.color_map.shape == (3,) |
| 751 | + npt.assert_array_equal(obj.color_map, self.RED_DEF) |
| 752 | + |
| 753 | + @pytest.mark.parametrize("color_map", [tuple(RED_2D_REF), np.array(RED_2D_REF, dtype=np.uint8), list(RED_2D_REF)]) |
| 754 | + def test_2d_colormap(self, color_map): |
| 755 | + obj = ChannelInfoFull(name="test", color_map=color_map, contrast_limits=(0, 20)) |
| 756 | + assert obj.name == "test" |
| 757 | + assert np.all(obj.contrast_limits == (0, 20)) |
| 758 | + assert isinstance(obj.color_map, np.ndarray) |
| 759 | + assert obj.color_map.shape == (3, 2) |
| 760 | + npt.assert_array_equal(obj.color_map, self.RED_2D_REF) |
| 761 | + |
| 762 | + def test_wrong_dtype_colormap(self): |
| 763 | + with pytest.raises(ValueError, match="Colormap as array need to be uint8"): |
| 764 | + ChannelInfoFull(name="test", color_map=np.array(self.RED_DEF, dtype=np.float32), contrast_limits=(0, 20)) |
| 765 | + |
| 766 | + def test_wrong_colors_colormap(self): |
| 767 | + with pytest.raises(ValueError, match="Color map need to have 3 or 4 elements"): |
| 768 | + ChannelInfoFull(name="test", color_map=np.array([[0, 0], [0, 0]], dtype=np.uint8), contrast_limits=(0, 20)) |
| 769 | + |
| 770 | + def test_wrong_dimesnsion_colormap(self): |
| 771 | + with pytest.raises(ValueError, match="Colormap as sequence need to"): |
| 772 | + ChannelInfoFull(name="test", color_map=np.array([[[0]], [[0]]], dtype=np.uint8), contrast_limits=(0, 20)) |
0 commit comments