Пример #1
0
def surf_ref(f, ref):
    fi = surf.integral(f.copy())
    points = surf.interest_points(fi, 6, 24, 1, max_points=1024, is_integral=True)
    descs = surf.descriptors(fi, points, is_integral=True, descriptor_only=True)
    if ref is None:
        return descs
    ri = surf.integral(ref.copy())
    descsref = surf.descriptors(ri, points, is_integral=True, descriptor_only=True)
    return np.hstack( (descs, descsref) )
Пример #2
0
def test_integral_descriptors():
    np.random.seed(22)
    f = np.random.rand(16, 16) * 230
    f = f.astype(np.uint8)
    f = surf.integral(f)
    points = surf.interest_points(f, is_integral=True)
    surf.descriptors(f.astype(np.int32), points, is_integral=True)
def test_integral_intested_points():
    np.random.seed(22)
    f = np.random.rand(16, 16) * 230
    f = f.astype(np.uint8)
    f = surf.integral(f)
    with pytest.raises(TypeError):
        surf.interest_points(f.astype(np.int32), is_integral=True)
Пример #4
0
def test_integral_descriptors():
    np.random.seed(22)
    f = np.random.rand(16,16)*230
    f = f.astype(np.uint8)
    f = surf.integral(f)
    points = surf.interest_points(f, is_integral=True)
    surf.descriptors(f.astype(np.int32), points, is_integral=True)
Пример #5
0
def test_sum_rect():
    f = np.arange(800 * 160).reshape((800, 160)) % 7
    fi = surf.integral(f.copy())

    np.random.seed(22)
    for i in range(100):
        y0 = np.random.randint(1, 780)
        y1 = np.random.randint(y0 + 1, 799)
        x0 = np.random.randint(1, 150)
        x1 = np.random.randint(x0 + 1, 159)
        assert _surf.sum_rect(fi, y0, x0, y1, x1) == f[y0:y1, x0:x1].sum()
Пример #6
0
def test_sum_rect():
    f = np.arange(800*160).reshape((800,160)) % 7
    fi = surf.integral(f.copy()) 

    np.random.seed(22)
    for i in xrange(100):
        y0 = np.random.randint(1,780)
        y1 = np.random.randint(y0+1,799)
        x0 = np.random.randint(1,150)
        x1 = np.random.randint(x0+1, 159)
        assert _surf.sum_rect(fi, y0, x0, y1, x1) == f[y0:y1, x0:x1].sum()
Пример #7
0
def test_interest_points_descriptors():
    np.random.seed(22)
    f = np.random.rand(256, 256) * 230
    f = f.astype(np.uint8)
    fi = surf.integral(f)
    spoints = surf.surf(f, 6, 24, 1)
    for arr, is_integral in zip([f, fi], [False, True]):
        points = surf.interest_points(arr, 6, 24, 1, is_integral=is_integral)
        points = list(points)
        points.sort(key=(lambda p: -p[3]))
        points = np.array(points, dtype=np.float64)
        descs = surf.descriptors(arr, points, is_integral)
        assert np.all(descs[:len(spoints)] == spoints)
Пример #8
0
def test_interest_points_descriptors():
    np.random.seed(22)
    f = np.random.rand(256,256)*230
    f = f.astype(np.uint8)
    fi = surf.integral(f)
    spoints = surf.surf(f, 6, 24, 1)
    for arr, is_integral in zip([f,fi], [False, True]):
        points = surf.interest_points(arr, 6, 24, 1, is_integral=is_integral)
        points = list(points)
        points.sort(key=(lambda p: -p[3]))
        points = np.array(points, dtype=np.float64)
        descs = surf.descriptors(arr, points, is_integral)
        assert np.all(descs[:len(spoints)] == spoints)
Пример #9
0
def _get_feature(_img):
    """docstring for fname"""
    data = []

    # R,G,B三通道的均值
    #r, g, b = _img.splitChannels()
    #r_mean = r.getNumpyCv2().mean()
    #g_mean = g.getNumpyCv2().mean()
    #b_mean = b.getNumpyCv2().mean()

    gray = _img.getGrayNumpyCv2()
    # 灰度共生矩阵
    glcm = greycomatrix(gray, [1], [np.pi/2], 256, symmetric=True, normed=True)
    # 不同的
    diss = greycoprops(glcm, 'dissimilarity')
    # 相关性
    corr = greycoprops(glcm, 'correlation')
    # 同质的
    h**o = greycoprops(glcm, 'homogeneity')
    # 熵
    energy = greycoprops(glcm, 'energy')
    # 特征
    asm = greycoprops(glcm, 'ASM')
    # 对比度
    contrast = greycoprops(glcm, 'contrast')
    # lbp特征
    lbp = mh.features.lbp(gray, 8, 6)
    integrals = surf.integral(gray)
    lbp_integrals = mh.features.lbp(integrals, 8, 6)

    # print 'lbp ---', lbp, '---'
    # print 'surf ---', surfs, '---'

    # data.extend(diss[0])
    # data.extend(corr[0])
    # data.extend(h**o[0])
    # data.extend(energy[0])
    # data.extend(asm[0])
    # data.extend(contrast[0])
    # data.extend(lbp)
    data.extend(lbp_integrals)
    #data.extend([r_mean, g_mean, b_mean])

    return data
Пример #10
0
def test_integral_intested_points():
    np.random.seed(22)
    f = np.random.rand(16, 16) * 230
    f = f.astype(np.uint8)
    f = surf.integral(f)
    surf.interest_points(f.astype(np.int32), is_integral=True)
def test_sum_rect_edge():
    # regression
    # https://github.com/luispedro/mahotas/issues/58
    f = np.arange(80 * 60).reshape((80, 60)) % 7
    fi = surf.integral(f.copy())
    _surf.sum_rect(fi, 0, 0, 81, 61)
Пример #12
0
from __future__ import print_function
import mahotas.polygon
from pylab import imshow, show
import numpy as np
from mahotas.features import surf

f = np.zeros((1024,1024))
Y,X = np.indices(f.shape)
Y -= 768
X -= 768
f += 120*np.exp(-Y**2/2048.-X**2/480.)
Y += 512
X += 512
rho = .7
f += 120*np.exp(-1./( 2*(1-rho**2)) *( Y**2/32/32.+X**2/24/24. + 2*rho*X*Y/32./24.))
fi = surf.integral(f.copy())
spoints = surf.surf(f, 6, 24, 1)

f2 = surf.show_surf(f, spoints)
imshow(f2)
show()
Пример #13
0
def test_integral():
    f = np.arange(8*16).reshape((8,16)) % 8
    fi = surf.integral(f.copy())
    assert fi[-1,-1] == f.sum()
    for y,x in np.indices(f.shape).reshape((2,-1)).T:
        assert fi[y,x] == f[:y+1,:x+1].sum()
Пример #14
0
def test_integral_intested_points():
    np.random.seed(22)
    f = np.random.rand(16,16)*230
    f = f.astype(np.uint8)
    f = surf.integral(f)
    surf.interest_points(f.astype(np.int32), is_integral=True)
Пример #15
0
def test_integral():
    f = np.arange(8 * 16).reshape((8, 16)) % 8
    fi = surf.integral(f.copy())
    assert fi[-1, -1] == f.sum()
    for y, x in np.indices(f.shape).reshape((2, -1)).T:
        assert fi[y, x] == f[:y + 1, :x + 1].sum()
from __future__ import print_function
from pylab import imshow, show
import numpy as np
from mahotas.features import surf

f = np.zeros((1024, 1024))
Y, X = np.indices(f.shape)
Y -= 768
X -= 768
f += 120 * np.exp(-Y**2 / 2048. - X**2 / 480.)
Y += 512
X += 512
rho = .7
f += 120 * np.exp(
    -1. / (2 * (1 - rho**2)) *
    (Y**2 / 32 / 32. + X**2 / 24 / 24. + 2 * rho * X * Y / 32. / 24.))
fi = surf.integral(f.copy())
spoints = surf.surf(f, 6, 24, 1)

f2 = surf.show_surf(f, spoints)
imshow(f2)
show()
Пример #17
0
def test_sum_rect_edge():
    # regression
    # https://github.com/luispedro/mahotas/issues/58
    f = np.arange(80*60).reshape((80,60)) % 7
    fi = surf.integral(f.copy())
    _surf.sum_rect(fi, 0, 0, 81, 61)