Similarity and distance metrics between observations play an important role in both human cognitive processes and artificial systems for recognition and categorization. How to appropriately measure the distance or similarity for the problem at hand is crucial to the performance of many machine learning and data mining methods. This tutorial provides a comprehensive introduction to metric learning, a set of techniques to automatically learn similarity and distance functions from data. In the first part, we give a general overview of metric learning through the presentation of a few key algorithms and analytical frameworks. In particular, we cover linear and nonlinear methods and how to scale them up to large datasets, metric learning for structured data as well as the derivation of formal guarantees on the generalization performance. In the second part, we show the relevance of metric learning in the very active field of computer vision. We introduce approaches specifically designed for various tasks (image retrieval, object and face recognition, hierarchical image classification) and present experimental results on real-world computer vision datasets.