In [1]:
%matplotlib inline
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
from scipy.io import loadmat
from menpo.shape import PointDirectedGraph

dic = loadmat('/data/matlabdev/GN_DPM_code_v1/bounding_boxes_LFPW.mat')

bounding_boxes = dic['bounding_boxes']
adjacency_array = np.array([[0, 1], [1, 2], [2, 3], [3, 0]])

bbs = []
for bb in bounding_boxes:
    p0 = bb[:2]
    p1 = p0 + np.asarray([bb[2], 0])
    p2 = p0 + bb[2:]
    p3 = p0 + np.asarray([0, bb[3]])
    points = np.asarray([p0, p1, p2, p3]) 
    bbs.append(PointDirectedGraph(points, adjacency_array))

In [5]:
import menpo.io as mio

images = []
for i in mio.import_images('/data/matlabdev/GN_DPM_code_v1/test_data/LFPW/',
                           verbose=True, max_images=None):
    images.append(i)


- Loading 224 assets: [====================] 100%

In [6]:
gt_bbs = [i.landmarks['PTS'].lms.bounding_box() for i in images]

In [7]:
for (i, gt_bb, bb) in zip(images, gt_bbs, bbs):
    i.landmarks['gt_bb'] = gt_bb
    i.landmarks['bb'] = bb

In [8]:
from menpo.visualize import visualize_images

visualize_images(images)



In [38]:
from menpo.transform import AlignmentSimilarity

ss = []
tys = []
txs = []

for (bb, gt_bb) in zip(bbs, gt_bbs):
    t = AlignmentSimilarity(bb, gt_bb, rotation=False)
    s, _, ty, tx = t.as_vector()
    ry, rx = gt_bb.range()
    
    ss.append(s)
    tys.append(ty / ry)
    txs.append(tx / rx)

In [39]:
print 'Scale mean:', np.mean(ss)
print 'Trans y mean:', np.mean(tys)
print 'Trans x mean:', np.mean(txs)


Scale mean: 0.0229784982001
Trans y mean: -0.0285020482609
Trans x mean: -0.0344895493282

In [41]:
print 'Scale mean:', np.std(ss)
print 'Trans y mean:', np.std(tys)
print 'Trans x mean:', np.std(txs)


Scale mean: 0.0416550175097
Trans y mean: 0.070751121617
Trans x mean: 0.104310428729

In [45]:
from menpo.shape import mean_pointcloud

shapes = [i.landmarks['PTS'].lms for i in images]
m = mean_pointcloud(shapes)

In [77]:
from menpo.transform import AlignmentSimilarity
from menpofit.fitter import align_shape_with_bb

ss = []
tys = []
txs = []

for (bb, shape) in zip(bbs, shapes):
    m2 = align_shape_with_bb(m, np.asarray([bb.points[0, :], bb.points[3, :]])).apply(m)
    t = AlignmentSimilarity(m2, shape, rotation=False)
    s, _, ty, tx = t.as_vector()
    ry, rx = shape.range()

    ss.append(s)
    tys.append(ty / ry)
    txs.append(tx / rx)

In [78]:
print 'Scale mean:', np.mean(ss)
print 'Trans y mean:', np.mean(tys)
print 'Trans x mean:', np.mean(txs)


Scale mean: 0.404738299235
Trans y mean: 0.129202119219
Trans x mean: -0.633576658905

In [79]:
print 'Scale mean:', np.std(ss)
print 'Trans y mean:', np.std(tys)
print 'Trans x mean:', np.std(txs)


Scale mean: 0.0453847340256
Trans y mean: 0.13131545145
Trans x mean: 0.310977049885

In [80]:
print 'Trans x mean:', np.var(np.hstack((ss, tys, txs)))


Trans x mean: 0.231542260604

In [81]:
from menpofit.base import noisy_align

ss = []
tys = []
txs = []

for _ in xrange(100):
    for shape in shapes:
        t = noisy_align(m, shape, noise_std=0.04, rotation=False)
        s, _, ty, tx = t.as_vector()
        ry, rx = shape.range()

        ss.append(s)
        tys.append(ty / ry)
        txs.append(tx / rx)

In [82]:
print 'Scale mean:', np.mean(ss)
print 'Trans y mean:', np.mean(tys)
print 'Trans x mean:', np.mean(txs)


Scale mean: 0.0164996954313
Trans y mean: -0.000300302699477
Trans x mean: 0.084171695918

In [83]:
print 'Scale mean:', np.var(ss)
print 'Trans y mean:', np.var(tys)
print 'Trans x mean:', np.var(txs)


Scale mean: 0.193829508367
Trans y mean: 0.0677369793801
Trans x mean: 0.568454317208

In [84]:
print 'Trans x mean:', np.var(np.hstack((ss, tys, txs)))


Trans x mean: 0.278006630334