Active Appearance Model Toolkit
Active Appearance Model is computer vision algorithm providing statistical model of object (e.g. human face) shape and appearance. This module contains building blocks to create and experiment with such models
Methods and Algorithms
Procruster Analysis is shape/mesh normalization algorithm wich takes a list of shapes and normalize size and rotation to match (randomly chosen) reference shape. Function below taks as parameter a list of shapes in form of list or tuple with folowing format [(x1, y1, x2, y2, x3, y3 ...), (...)].
def test_procruster(shapes): shapes = map(Shape, shapes) f, (before, after) = plt.subplots(1, 2) for r in shapes: before.plot(r.data_x, r.data_y*-1, '+') result = procruster_analysis(shapes, 0) print type(result.shapes.data), result.shapes.data for r in result.shapes: after.plot(r.data_x, r.data_y*-1, '+') after.plot(result.mean_shape.data_x, result.mean_shape.data_y*-1, 'o') show()
Textures need also to be normalized by mapped to mean shape. The extract_texture method takes a lists of images and shapes and extract mean texture, mean texture mask to map it back to image and list of extracted texture data
def test_extract_textures(shapes, images): shapes = map(Shape, shapes) result = procruster_analysis(shapes) mean_texture, mask, textures = extract_textures(images, shapes, result.mean_shape) mapper = TextureMapper(result.mean_shape.data) dt = mapper.apply_mask(mean_texture, mask) out = Image.new('L', (dt.shape, dt.shape), 'black') out.putdata(dt.flatten().tolist()) out.show()
Principal Component Analysis
Principal Component Analysis will in short find for your data linear space defined by eigen vectors, thus maximizing viariablilty of your data set in first dimmensions. This is how you can use PCA to model your data:
data_eigv, data_var = pca(data, 3) modified = data.mean() + dot(self.data_eigv.T, [2,-2,1])
Previously described methods are binded together in AppearanceModel class to provide simple interface to model appearance of objects. After is model constructed from list of shapes and images, extract method is used to normalize exctract data. The reduce method apply PCA and reduce dimmensionality of data amd get_image render image according to provided model paramenters.
def test_model(shapes, images): shapes = map(Shape, shapes) aam = AppearanceModel(images, shapes) aam.exctract() aam.reduce(5) dt = aam.get_image([1, 1], [600, -200, 100, 0, 0]) out = Image.new('L', (dt.shape, dt.shape), 'black') out.putdata(dt.flatten().tolist()) out.show()
copyright (c) 2013, Peter Facka
permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "software"), to deal in the software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, and to permit persons to whom the software is furnished to do so, subject to the following conditions:
the above copyright notice and this permission notice shall be included in all copies or substantial portions of the software.
the software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose and noninfringement. in no event shall the authors or copyright holders be liable for any claim, damages or other liability, whether in an action of contract, tort or otherwise, arising from, out of or in connection with the software or the use or other dealings in the software.