Пример #1
0
def test_complete_inference2():

    dcrf = densecrf.DenseCRF(100, 2)
    pcrf = pycrf.DenseCRF(100, 2)

    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    dcrf.setUnaryEnergy(-np.log(unary))
    pcrf.set_unary_energy(-np.log(unary))

    feats = utils.create_pairwise_gaussian(sdims=(1.5, 1.5),
                                           shape=img.shape[:2])

    dcrf.addPairwiseEnergy(feats, compat=3)
    pcrf.add_pairwise_energy(feats, compat=3)

    feats = utils.create_pairwise_bilateral(sdims=(2, 2), schan=2,
                                            img=img, chdim=2)

    dcrf.addPairwiseEnergy(feats, compat=3)
    pcrf.add_pairwise_energy(feats, compat=3)
    # d.addPairwiseBilateral(2, 2, img, 3)
    res1 = np.argmax(dcrf.inference(10), axis=0).reshape(10, 10)
    res2 = np.argmax(pcrf.inference(10), axis=0).reshape(10, 10)

    if False:
        # Save the result for visual inspection

        import scipy as scp
        import scipy.misc

        scp.misc.imsave("test.png", res1)

    assert(np.all(res1 == res2))
Пример #2
0
def test_pairwise():
    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()
    feats = utils.create_pairwise_bilateral(sdims=(2, 2),
                                            schan=2,
                                            img=img,
                                            chdim=2)
    pairwise = pair.PairwisePotentials(feats, compat=3)
    out = pairwise.apply(unary)

    return out
Пример #3
0
def test_call_dcrf2d():

    d = dcrf.DenseCRF2D(10, 10, 2)

    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    d.setUnaryEnergy(-np.log(unary))
    # d.setUnaryEnergy(PyConstUnary(-np.log(Up)))

    d.addPairwiseBilateral(sxy=2, srgb=2, rgbim=img, compat=3)
    # d.addPairwiseBilateral(2, 2, img, 3)
    res = np.argmax(d.inference(10), axis=0).reshape(10, 10)

    np.all(res == img[:, :, 0] / 255)
Пример #4
0
def test_call_dcrf():

    d = dcrf.DenseCRF(100, 2)

    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    d.setUnaryEnergy(-np.log(unary))
    # d.setUnaryEnergy(PyConstUnary(-np.log(Up)))

    feats = utils.create_pairwise_bilateral(sdims=(2, 2), schan=2,
                                            img=img, chdim=2)

    d.addPairwiseEnergy(feats, compat=3)
    # d.addPairwiseBilateral(2, 2, img, 3)
    res = np.argmax(d.inference(10), axis=0).reshape(10, 10)

    np.all(res == img[:, :, 0] / 255)
Пример #5
0
def test_complete_inference():

    dcrf = densecrf.DenseCRF(100, 2)
    pcrf = pycrf.DenseCRF(100, 2)

    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    dcrf.setUnaryEnergy(-np.log(unary))
    pcrf.set_unary_energy(-np.log(unary))

    feats = utils.create_pairwise_bilateral(sdims=(2, 2), schan=2,
                                            img=img, chdim=2)

    dcrf.addPairwiseEnergy(feats, compat=3)

    pcrf.add_pairwise_energy(feats, compat=3)
    # d.addPairwiseBilateral(2, 2, img, 3)
    res1 = np.argmax(dcrf.inference(10), axis=0).reshape(10, 10)
    res2 = np.argmax(pcrf.inference(10), axis=0).reshape(10, 10)

    assert(np.all(res1 == res2))
Пример #6
0
def test_call_dcrf_eq_dcrf2d():

    d = dcrf.DenseCRF(100, 2)
    d2 = dcrf.DenseCRF2D(10, 10, 2)

    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    d.setUnaryEnergy(-np.log(unary))
    d2.setUnaryEnergy(-np.log(unary))

    feats = utils.create_pairwise_bilateral(sdims=(2, 2), schan=2,
                                            img=img, chdim=2)

    d.addPairwiseEnergy(feats, compat=3)

    d2.addPairwiseBilateral(sxy=2, srgb=2, rgbim=img, compat=3)
    # d.addPairwiseBilateral(2, 2, img, 3)
    res1 = np.argmax(d.inference(10), axis=0).reshape(10, 10)
    res2 = np.argmax(d2.inference(10), axis=0).reshape(10, 10)

    assert(np.all(res1 == res2))
Пример #7
0
def test_pairwise_inference():

    dcrf = densecrf.DenseCRF(100, 2)
    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    dcrf.setUnaryEnergy(-np.log(unary))
    lg_unary = -np.log(unary)

    feats = utils.create_pairwise_bilateral(sdims=(2, 2),
                                            schan=2,
                                            img=img,
                                            chdim=2)

    dcrf.addPairwiseEnergy(feats, compat=3)
    pairwise = pair.PairwisePotentials(feats, compat=3)

    dres = np.argmax(dcrf.inference(10), axis=0).reshape(10, 10)
    out = compute_inference_with_pair([pairwise], lg_unary, 10)
    pres = np.argmax(out, axis=0).reshape(10, 10)

    assert (np.all(dres == pres))
Пример #8
0
def test_dkernel_inference():

    dcrf = densecrf.DenseCRF(100, 2)
    unary = test_utils._get_simple_unary()
    img = test_utils._get_simple_img()

    dcrf.setUnaryEnergy(-np.log(unary))
    lg_unary = -np.log(unary)

    feats = utils.create_pairwise_bilateral(sdims=(2, 2),
                                            schan=2,
                                            img=img,
                                            chdim=2)

    dcrf.addPairwiseEnergy(feats, compat=3)
    klist = [pair.DenseKernel(feats)]
    clist = [pair.PottsComp(3)]

    dres = np.argmax(dcrf.inference(10), axis=0).reshape(10, 10)
    out = compute_inference_with_dkernel(klist, clist, lg_unary, 10)
    pres = np.argmax(out, axis=0).reshape(10, 10)

    assert (np.all(dres == pres))