Exemplo n.º 1
0
def test_show_surf():
    np.random.seed(22)
    f = np.random.rand(256, 256) * 230
    f = f.astype(np.uint8)
    spoints = surf.surf(f, 6, 24, 1)
    f2 = surf.show_surf(f, spoints)
    assert f2.shape == (f.shape + (3, ))
Exemplo n.º 2
0
def test_show_surf():
    np.random.seed(22)
    f = np.random.rand(256,256)*230
    f = f.astype(np.uint8)
    spoints = surf.surf(f, 6, 24, 1)
    f2 = surf.show_surf(f, spoints)
    assert f2.shape == (f.shape + (3,))
Exemplo n.º 3
0
def image_SURF_kp(pil_im):
    '''
    提取图像的SURF描述子
    INPUT  -> 单张图文件
    OUTPUT -> 标识特征点的图片, SURF特征点
    '''
    pil_im = pil_im.convert('L')
    image_arr = image_to_array(pil_im)
    spoints = surf.surf(image_arr, 4, 6)
    kp_image_arr = surf.show_surf(image_arr, spoints)
    kp_image = array_to_image(kp_image_arr)
    return kp_image, spoints
from __future__ import print_function
import numpy as np
import mahotas as mh
from mahotas.features import surf
from matplotlib import pyplot as plt

f = mh.demos.load('luispedro', as_grey=True)
f = f.astype(np.uint8)
spoints = surf.surf(f, 4, 6, 2)
print("Nr points:", len(spoints))

try:
    from sklearn.cluster import KMeans
    descrs = spoints[:, 5:]
    k = 5
    values = KMeans(n_clusters=k).fit(descrs).labels_
    colors = np.array([(255 - 52 * i, 25 + 52 * i, 37**i % 101)
                       for i in range(k)])
except:
    values = np.zeros(100, int)
    colors = np.array([(255, 0, 0)])

f2 = surf.show_surf(f, spoints[:100], values, colors)
fig, ax = plt.subplots()
ax.imshow(f2)
fig.show()
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()
Exemplo n.º 6
0
from __future__ import print_function
import numpy as np
import mahotas as mh
from mahotas.features import surf
from pylab import *

from os import path

f = mh.demos.load('luispedro', as_grey=True)
f = f.astype(np.uint8)
spoints = surf.surf(f, 4, 6, 2)
print("Nr points:", len(spoints))

try:
    import milk
    descrs = spoints[:,5:]
    k = 5
    values, _  =milk.kmeans(descrs, k)
    colors = np.array([(255-52*i,25+52*i,37**i % 101) for i in range(k)])
except:
    values = np.zeros(100)
    colors = np.array([(255,0,0)])

f2 = surf.show_surf(f, spoints[:100], values, colors)
imshow(f2)
show()
Exemplo n.º 7
0
cat_surf = surf.surf(cat_mh,
                     nr_octaves=8,
                     nr_scales=16,
                     initial_step_size=1,
                     threshold=0.1,
                     max_points=50)
dog_surf = surf.surf(dog_mh,
                     nr_octaves=8,
                     nr_scales=16,
                     initial_step_size=1,
                     threshold=0.1,
                     max_points=54)

fig = plt.figure(figsize=(10, 4))
ax1 = fig.add_subplot(1, 2, 1)
ax1.imshow(surf.show_surf(cat_mh, cat_surf))
ax2 = fig.add_subplot(1, 2, 2)
ax2.imshow(surf.show_surf(dog_mh, dog_surf))

# In[14]:

cat_surf_fds = surf.dense(cat_mh, spacing=10)
dog_surf_fds = surf.dense(dog_mh, spacing=10)
cat_surf_fds.shape

# # Visual Bag of Words model

# ## Engineering features from SURF feature descriptions with clustering

# In[15]:
Exemplo n.º 8
0
import cv2
import numpy as np
from mahotas.features import surf
import milk

img = cv2.imread('img_07473.jpg')
gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)

#img = cv2.imread('fly.png',0)
# Create SURF object. You can specify params here or later.
# Here I set Hessian Threshold to 400
#surf = cv2.SURF(400)
#surf = surf.surf(400)

# Find keypoints and descriptors directly
#kp, des = surf.detectAndCompute(img,None)
des = surf.surf(gray)
kp = surf.interest_points(gray, threshold=10)

print(len(kp))
#img2 = cv2.drawKeypoints(img,kp,None,(255,0,0),4)
f2 = surf.show_surf(img, kp[:100], )

cv2.imwrite('surf_keypoints.jpg',img2)
Exemplo n.º 9
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()
Exemplo n.º 10
0
import numpy as np
import mahotas as mh
from mahotas.features import surf
from scipy.cluster import vq
import mahotas.demos
impath = mh.demos.image_path('luispedro.jpg')
f = mh.imread(impath, as_grey=True)
f = f.astype(np.uint8)
spoints = surf.surf(f, 4, 6, 2)
descrs = spoints[:,6:]
_,cids = vq.kmeans2(vq.whiten(descrs), 5)
colors = np.array([
    [ 255,  25,   1],
    [203,  77,  37],
    [151, 129,  56],
    [ 99, 181,  52],
    [ 47, 233,   5]])
f2 = surf.show_surf(f, spoints[:64], cids, colors)
from matplotlib import pyplot as plt
plt.subplot(1,2,1)
plt.imshow(np.dstack([f,f,f]))
plt.xticks([])
plt.yticks([])
plt.subplot(1,2,2)
plt.imshow(f2)
plt.xticks([])
plt.yticks([])
plt.savefig('surf-tutorial.png')