In [1]:
%matplotlib inline
%pylab inline
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)
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)
In [41]:
print 'Scale mean:', np.std(ss)
print 'Trans y mean:', np.std(tys)
print 'Trans x mean:', np.std(txs)
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)
In [79]:
print 'Scale mean:', np.std(ss)
print 'Trans y mean:', np.std(tys)
print 'Trans x mean:', np.std(txs)
In [80]:
print 'Trans x mean:', np.var(np.hstack((ss, tys, txs)))
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)
In [83]:
print 'Scale mean:', np.var(ss)
print 'Trans y mean:', np.var(tys)
print 'Trans x mean:', np.var(txs)
In [84]:
print 'Trans x mean:', np.var(np.hstack((ss, tys, txs)))