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/tzimiro_ICCV2013_code/')

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 [12]:
from menpo.shape import mean_pointcloud

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

In [42]:
from menpofit.base import noisy_align

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

for _ in xrange(100):
    for gt_bb in gt_bbs:
        t1 = noisy_align(m_bb, gt_bb, noise_std=0.04, rotation=False)
        t2 = AlignmentSimilarity(m_bb, gt_bb, rotation=False)
        s1, _, ty1, tx1 = t1.as_vector()
        s2, _, ty2, tx2 = t2.as_vector()
        ry, rx = gt_bb.range()
        
        ss.append(s2 - s1)
        tys.append((ty2 - ty1) / ry)
        txs.append((tx2 - tx1) / rx)

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


Scale mean: 0.000173403805129
Trans y mean: -6.52972744225e-05
Trans x mean: 0.000317789012404

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


Scale mean: 0.0175754037983
Trans y mean: 0.0400213839756
Trans x mean: 0.0399369074793