Ejemplo n.º 1
0
    def test_trivial_curves(self):
        im = np.r_[[[0, 3, 4, 6, 1], [3, 6, 1, 1, 8], [4, 2, 6, 0, 7],
                    [5, 5, 9, 0, 2]]]
        test = contrast(im, 0.5)
        assert_array_equal(test, contrast(im, (0.5, 0.5)))

        expected = np.array(
            [[0., 0.40824829, 0.47140452, 0.59175171, 0.23570226],
             [0.40824829, 0.59175171, 0.23570226, 0.23570226, 0.76429774],
             [0.47140452, 0.33333333, 0.59175171, 0., 0.66666667],
             [0.52859548, 0.52859548, 1., 0., 0.33333333]])

        assert_allclose(test, expected * 9)
Ejemplo n.º 2
0
def test_contrast():
    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
    z = contrast(a, 1.8)

    # Legacy slower code which should produce identical result
    p = 1.8
    m = 0.5
    ymin = np.fmin(a, m)
    ymax = np.fmax(a, m)
    w = np.arange(len(a))
    wmax = w[ymax > m]
    wmin = w[ymax <= m]
    ymin = 2 ** (p - 1) * ymin ** p
    ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
    ymin[wmax] = 0
    ymax[wmin] = 0

    assert_allclose(z, ymin + ymax)

    # Legacy slower code which should produce identical result
    p = 0.5
    m = 0.5
    z = contrast(a, 0.5)
    ymin = np.fmin(a, m)
    ymax = np.fmax(a, m)
    w = np.arange(len(a))
    wmax = w[ymax > m]
    wmin = w[ymax <= m]
    ymin = 2 ** (p - 1) * ymin ** p
    ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
    ymin[wmax] = 0
    ymax[wmin] = 0

    assert_allclose(z, ymin + ymax)

    # Legacy slower code which should produce identical result
    p = 2.
    m = 0.5
    z = contrast(a, 2.)
    ymin = np.fmin(a, m)
    ymax = np.fmax(a, m)
    w = np.arange(len(a))
    wmax = w[ymax > m]
    wmin = w[ymax <= m]
    ymin = 2 ** (p - 1) * ymin ** p
    ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
    ymin[wmax] = 0
    ymax[wmin] = 0

    assert_allclose(z, ymin + ymax)
Ejemplo n.º 3
0
    def test_contrast(self):
        a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
        z = contrast(a, 1.8)

        # Legacy slower code which should produce identical result
        p = 1.8
        m = 0.5
        ymin = np.fmin(a, m)
        ymax = np.fmax(a, m)
        w = np.arange(len(a))
        wmax = w[ymax > m]
        wmin = w[ymax <= m]
        ymin = 2**(p - 1) * ymin**p
        ymax = 1 - 2**(p - 1) * (1 - ymax)**p
        ymin[wmax] = 0
        ymax[wmin] = 0

        assert_allclose(z, ymin + ymax)

        # Legacy slower code which should produce identical result
        p = 0.5
        m = 0.5
        z = contrast(a, 0.5)
        ymin = np.fmin(a, m)
        ymax = np.fmax(a, m)
        w = np.arange(len(a))
        wmax = w[ymax > m]
        wmin = w[ymax <= m]
        ymin = 2**(p - 1) * ymin**p
        ymax = 1 - 2**(p - 1) * (1 - ymax)**p
        ymin[wmax] = 0
        ymax[wmin] = 0

        assert_allclose(z, ymin + ymax)

        # Legacy slower code which should produce identical result
        p = 2.
        m = 0.5
        z = contrast(a, 2.)
        ymin = np.fmin(a, m)
        ymax = np.fmax(a, m)
        w = np.arange(len(a))
        wmax = w[ymax > m]
        wmin = w[ymax <= m]
        ymin = 2**(p - 1) * ymin**p
        ymax = 1 - 2**(p - 1) * (1 - ymax)**p
        ymin[wmax] = 0
        ymax[wmin] = 0

        assert_allclose(z, ymin + ymax)
Ejemplo n.º 4
0
    def test_trivial_curves(self):
        im = np.r_[[[0, 3, 4, 6, 1],
                    [3, 6, 1, 1, 8],
                    [4, 2, 6, 0, 7],
                    [5, 5, 9, 0, 2]]]
        test = contrast(im, 0.5)
        assert_array_equal(test, contrast(im, (0.5, 0.5)))

        expected = np.array(
            [[0.        , 0.40824829, 0.47140452, 0.59175171, 0.23570226],
             [0.40824829, 0.59175171, 0.23570226, 0.23570226, 0.76429774],
             [0.47140452, 0.33333333, 0.59175171, 0.        , 0.66666667],
             [0.52859548, 0.52859548, 1.        , 0.        , 0.33333333]])

        assert_allclose(test, expected * 9)
Ejemplo n.º 5
0
    def test_contrast_offcenter(self):
        a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
        z = contrast(a, 1.8, 0.75)

        expected = np.r_[0, 0, 0, 0.14413493, 0.66241089, 1, 0.95195502, 0]

        assert_allclose(z, expected)
Ejemplo n.º 6
0
    def test_contrast_offcenter(self):
        a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
        z = contrast(a, 1.8, 0.75)

        expected = np.r_[0, 0, 0, 0.14413493, 0.66241089, 1, 0.95195502, 0]

        assert_allclose(z, expected)
Ejemplo n.º 7
0
def test_contrast_offcenter():
    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
    z = contrast(a, 1.8, m=0.75)

    # Legacy slower code which produces correct results
    p = 1.8
    m = 0.75
    ymin = np.fmin(a, m)
    ymax = np.fmax(a, m)
    w = np.arange(len(a))
    wmax = w[ymax > m]
    wmin = w[ymax <= m]
    ymin = 2 ** (p - 1) * ymin ** p
    ymax = 1 - 2 ** (p - 1) * (1 - ymax) ** p
    ymin[wmax] = 0
    ymax[wmin] = 0

    assert_array_equal(z, ymin + ymax)
Ejemplo n.º 8
0
def test_contrast_offcenter():
    a = np.r_[0, 0, 0, 0.3, 0.7, 1, 0.9, 0]
    z = contrast(a, 1.8, m=0.75)

    # Legacy slower code which produces correct results
    p = 1.8
    m = 0.75
    ymin = np.fmin(a, m)
    ymax = np.fmax(a, m)
    w = np.arange(len(a))
    wmax = w[ymax > m]
    wmin = w[ymax <= m]
    ymin = 2**(p - 1) * ymin**p
    ymax = 1 - 2**(p - 1) * (1 - ymax)**p
    ymin[wmax] = 0
    ymax[wmin] = 0

    assert_array_equal(z, ymin + ymax)