In order to demonstrate the functionality of the landmark package we will start by loading a couple of landmarked images using the menpo.io
package.
In [ ]:
import menpo.io as pio
images = list(pio.import_images('/vol/atlas/databases/lfpw/trainset/*.png', max_images=2))
img = images[0]
In this case, images have been automatically loaded with some landmark information attached. We can confirm that by accessing the property .landmarks on the images.
In [ ]:
print 'Is img landmarked?'
print ' - {}'.format(img.landmarks.has_landmarks)
print 'How many landmark groups does it have?'
print ' - {}'.format(img.landmarks.n_groups)
print 'What labels do these groups have?'
for g in img.landmarks.group_labels:
print ' - {}'.format(g)
The semantic meaning of landmarks is given by the different the property labels of each landmark group:
In [ ]:
print 'PTS semantic labels is?'
for l in img.landmarks['PTS'].labels:
print ' - {}'.format(l)
As a shortcut, we can use None
as a key value if it is unambiguous.
In [ ]:
l_None = img.landmarks[None]
l_PTS = img.landmarks['PTS']
print 'Does None perform the same as the explicit key if there is no ambiguity? : {}'.format(l_None is l_PTS)
In [ ]:
from menpo.landmark.labels import labeller, ibug_68_points
# Label some landmarks
images = labeller(images, 'PTS', ibug_68_points)
print 'How many landmark groups does it have?'
print ' - {}'.format(img.landmarks.n_groups)
print 'What labels do these groups have?'
for g in img.landmarks.group_labels:
print ' - {}'.format(g)
print 'ibug_68_points semantic labels are?'
for l in img.landmarks['ibug_68_points'].labels:
print ' - {}'.format(l)
We can view particular landmark groups and their particular labels.
In [ ]:
%matplotlib inline
# View a particular group
img.landmarks['PTS'].view_new()
In [ ]:
# View a particular group
a = img.landmarks['ibug_68_points']['reye'].view_new()
Note that now we can't use the None
trick
In [ ]:
try:
img.landmarks[None]
except ValueError as e:
print e
In [ ]:
from menpo.landmark.labels import ibug_68_trimesh
# Label some landmarks
images = labeller(images, 'PTS', ibug_68_trimesh)
import numpy as np
from menpo.shape import PointCloud
# Set a new set of landmarks via a PointCloud
new_points = PointCloud(np.random.random([100, 2]) * np.max(img.shape))
img.landmarks['new_points'] = new_points
img.landmarks.view()
In [ ]:
# Look at the group labels
print img.landmarks.group_labels
# Look at labels inside a group
print img.landmarks['ibug_68_trimesh'].labels
# View a particular label - a PointCloud
img.landmarks['ibug_68_trimesh']['tri'].view()
# Copy some landmarks
img.landmarks = images[1].landmarks
print img.landmarks.group_labels
img.landmarks['ibug_68_trimesh'] = images[0].landmarks['PTS']
print img.landmarks['ibug_68_trimesh']._target is img