Example #1
0
def test_adjust_gamma_greater_one():
    """Verifying the output with expected results for gamma
    correction with gamma equal to two"""
    image = cp.arange(0, 255, 4, np.uint8).reshape((8, 8))
    # fmt: off
    expected = cp.asarray(
        [
            [0, 0, 0, 0, 1, 1, 2, 3],  # noqa
            [4, 5, 6, 7, 9, 10, 12, 14],  # noqa
            [16, 18, 20, 22, 25, 27, 30, 33],  # noqa
            [36, 39, 42, 45, 49, 52, 56, 60],  # noqa
            [64, 68, 72, 76, 81, 85, 90, 95],  # noqa
            [100, 105, 110, 116, 121, 127, 132, 138],
            [144, 150, 156, 163, 169, 176, 182, 189],
            [196, 203, 211, 218, 225, 233, 241, 249]
        ],
        dtype=np.uint8)
    # fmt: on

    result = exposure.adjust_gamma(image, 2)
    assert_array_equal(result, expected)
Example #2
0
def test_adjust_gamma_less_one():
    """Verifying the output with expected results for gamma
    correction with gamma equal to half"""
    image = cp.arange(0, 255, 4, np.uint8).reshape((8, 8))
    # fmt: off
    expected = cp.asarray(
        [
            [0, 31, 45, 55, 63, 71, 78, 84],  # noqa
            [90, 95, 100, 105, 110, 115, 119, 123],  # noqa
            [127, 131, 135, 139, 142, 146, 149, 153],
            [156, 159, 162, 165, 168, 171, 174, 177],
            [180, 183, 186, 188, 191, 194, 196, 199],
            [201, 204, 206, 209, 211, 214, 216, 218],
            [221, 223, 225, 228, 230, 232, 234, 236],
            [238, 241, 243, 245, 247, 249, 251, 253]
        ],
        dtype=np.uint8)
    # fmt: on

    result = exposure.adjust_gamma(image, 0.5)
    assert_array_equal(result, expected)
Example #3
0
def test_negative():
    image = cp.arange(-10, 245, 4).reshape((8, 8)).astype(np.double)
    with pytest.raises(ValueError):
        exposure.adjust_gamma(image)
Example #4
0
def test_adjust_gamma_neggative():
    image = cp.arange(0, 255, 4, np.uint8).reshape((8, 8))
    with pytest.raises(ValueError):
        exposure.adjust_gamma(image, -1)
Example #5
0
def test_adjust_gamma_zero():
    """White image should be returned for gamma equal to zero"""
    image = cp.random.uniform(0, 255, (8, 8))
    result = exposure.adjust_gamma(image, 0)
    dtype = image.dtype.type
    assert_array_almost_equal(result, dtype_range[dtype][1])
Example #6
0
def test_adjust_gamma_one():
    """Same image should be returned for gamma equal to one"""
    image = cp.random.uniform(0, 255, (8, 8))
    result = exposure.adjust_gamma(image, 1)
    assert_array_almost_equal(result, image)
Example #7
0
def test_adjust_gamma_1x1_shape():
    """Check that the shape is maintained"""
    img = cp.ones([1, 1])
    result = exposure.adjust_gamma(img, 1.5)
    assert img.shape == result.shape