Commit f8afa4b3 authored by narugo1992's avatar narugo1992
Browse files

dev(narugo): fix known bugs

parent 67ef8bc8
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -9,11 +9,17 @@ def _get_hwc_map(order_: str):
    return tuple(order_.index(c) for c in _DEFAULT_ORDER.upper())


_float_types = [np.float16, np.float32, np.float64]
if hasattr(np, 'float128'):
    _float_types.append(np.float128)
_float_types = tuple(_float_types)


def rgb_decode(data, order_: str = 'CHW') -> Image.Image:
    if data.dtype in (np.uint8, np.int8, np.uint16, np.int16,
                      np.uint32, np.int32, np.uint64, np.int64):
        data = data.astype(np.uint8)
    elif data.dtype in (np.float16, np.float32, np.float64, np.float128):
    elif data.dtype in _float_types:
        data = np.clip(data, 0.0, 1.0)
        data = (data * 255).astype(np.uint8)
    else:
+7 −2
Original line number Diff line number Diff line
@@ -4,17 +4,22 @@ from PIL import Image
from imgutils.data import load_image
from test.testings import get_testfile

_FILENAME = get_testfile('6125785.png')
_IMAGE = Image.open(_FILENAME)


@pytest.mark.unittest
class TestDataImage:
    @pytest.mark.parametrize(['image_', 'result'], [
        (get_testfile('6125785.png'), Image.open(get_testfile('6125785.png'))),
        (Image.open(get_testfile('6125785.png')), Image.open(get_testfile('6125785.png'))),
        (_FILENAME, _IMAGE),
        (_IMAGE, _IMAGE),
        (None, TypeError),
    ])
    def test_load_image(self, image_, result, image_diff):
        if isinstance(result, type) and issubclass(result, BaseException):
            with pytest.raises(result):
                _ = load_image(image_)
        elif isinstance(image_, Image.Image):
            assert load_image(image_) is image_
        else:
            assert image_diff(load_image(image_), result, throw_exception=False) < 1e-2