コード例 #1
0
ファイル: utils.py プロジェクト: mapbox/rio-hist
def cs_backward(arr, cs='rgb'):
    """ whatevs to RGB 8-bit
    """
    cs = cs.lower()
    if cs == 'rgb':
        return (arr * 255).astype('uint8')
    elif cs == 'lch':
        rgb = convert_arr(arr,
                          src=ColorSpace.lch,
                          dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'lab':
        rgb = convert_arr(arr,
                          src=ColorSpace.lab,
                          dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'luv':
        rgb = convert_arr(arr,
                          src=ColorSpace.luv,
                          dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'xyz':
        rgb = convert_arr(arr,
                          src=ColorSpace.xyz,
                          dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
コード例 #2
0
def test_array_bad_colorspace():
    arr = np.random.random((3, 3))
    with pytest.raises(ValueError):
        convert_arr(arr, src="FOO", dst="RGB")

    with pytest.raises(ValueError):
        convert_arr(arr, src=999, dst=999)
コード例 #3
0
ファイル: test_colorspace.py プロジェクト: mapbox/rio-color
def test_array_bad_colorspace():
    arr = np.random.random((3, 3))
    with pytest.raises(ValueError):
        convert_arr(arr, src='FOO', dst='RGB')

    with pytest.raises(ValueError):
        convert_arr(arr, src=999, dst=999)
コード例 #4
0
def test_bad_array_type():
    bad = np.random.random((3, 3, 3)).astype("uint8")
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert "dtype mismatch" in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert "dtype mismatch" in str(exc.value)
コード例 #5
0
def test_bad_array_dims():
    bad = np.random.random((3, 3))
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert "wrong number of dimensions" in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert "wrong number of dimensions" in str(exc.value)
コード例 #6
0
def test_bad_array_bands():
    bad = np.random.random((2, 3, 3))
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert "3 bands" in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert "3 bands" in str(exc.value)
コード例 #7
0
ファイル: test_colorspace.py プロジェクト: mapbox/rio-color
def test_bad_array_type():
    bad = np.random.random((3, 3, 3)).astype('uint8')
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert 'dtype mismatch' in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert 'dtype mismatch' in str(exc.value)
コード例 #8
0
ファイル: test_colorspace.py プロジェクト: mapbox/rio-color
def test_bad_array_dims():
    bad = np.random.random((3, 3))
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert 'wrong number of dimensions' in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert 'wrong number of dimensions' in str(exc.value)
コード例 #9
0
ファイル: test_colorspace.py プロジェクト: mapbox/rio-color
def test_bad_array_bands():
    bad = np.random.random((2, 3, 3))
    with pytest.raises(ValueError) as exc:
        saturate_rgb(bad, 1.1)
    assert '3 bands' in str(exc.value)

    with pytest.raises(ValueError) as exc:
        convert_arr(bad, cs.rgb, cs.lch)
    assert '3 bands' in str(exc.value)
コード例 #10
0
ファイル: utils.py プロジェクト: tqdat99/rio-hist
def cs_forward(arr, cs='rgb'):
    """ RGB (any dtype) to whatevs
    """
    arrnorm_raw = arr.astype('float64') / np.iinfo(arr.dtype).max
    arrnorm = arrnorm_raw[0:3]
    cs = cs.lower()
    if cs == 'rgb':
        return arrnorm
    elif cs == 'lch':
        return convert_arr(arrnorm, src=ColorSpace.rgb, dst=ColorSpace.lch)
    elif cs == 'lab':
        return convert_arr(arrnorm, src=ColorSpace.rgb, dst=ColorSpace.lab)
    elif cs == 'luv':
        return convert_arr(arrnorm, src=ColorSpace.rgb, dst=ColorSpace.luv)
    elif cs == 'xyz':
        return convert_arr(arrnorm, src=ColorSpace.rgb, dst=ColorSpace.xyz)
コード例 #11
0
ファイル: utils.py プロジェクト: tqdat99/rio-hist
def cs_backward(arr, cs='rgb'):
    """ whatevs to RGB 8-bit
    """
    cs = cs.lower()
    if cs == 'rgb':
        return (arr * 255).astype('uint8')
    elif cs == 'lch':
        rgb = convert_arr(arr, src=ColorSpace.lch, dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'lab':
        rgb = convert_arr(arr, src=ColorSpace.lab, dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'luv':
        rgb = convert_arr(arr, src=ColorSpace.luv, dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
    elif cs == 'xyz':
        rgb = convert_arr(arr, src=ColorSpace.xyz, dst=ColorSpace.rgb)
        return (rgb * 255).astype('uint8')
コード例 #12
0
ファイル: utils.py プロジェクト: mapbox/rio-hist
def cs_forward(arr, cs='rgb'):
    """ RGB (any dtype) to whatevs
    """
    arrnorm_raw = arr.astype('float64') / np.iinfo(arr.dtype).max
    arrnorm = arrnorm_raw[0:3]
    cs = cs.lower()
    if cs == 'rgb':
        return arrnorm
    elif cs == 'lch':
        return convert_arr(arrnorm,
                           src=ColorSpace.rgb,
                           dst=ColorSpace.lch)
    elif cs == 'lab':
        return convert_arr(arrnorm,
                           src=ColorSpace.rgb,
                           dst=ColorSpace.lab)
    elif cs == 'luv':
        return convert_arr(arrnorm,
                           src=ColorSpace.rgb,
                           dst=ColorSpace.luv)
    elif cs == 'xyz':
        return convert_arr(arrnorm,
                           src=ColorSpace.rgb,
                           dst=ColorSpace.xyz)
コード例 #13
0
def test_arr_lch(pair):
    rgb, lch = pair
    rgb = _make_array(*rgb)
    lch = _make_array(*lch)
    assert np.allclose(convert_arr(lch, cs.lch, cs.rgb), rgb, atol=0.2)
コード例 #14
0
ファイル: test_colorspace.py プロジェクト: mapbox/rio-color
def test_arr_lch(pair):
    rgb, lch = pair
    rgb = _make_array(*rgb)
    lch = _make_array(*lch)
    assert np.allclose(
        convert_arr(lch, cs.lch, cs.rgb), rgb, atol=0.2)