曼哈顿距离
出租车距离Taxicab geometry或曼哈顿距离 city block distance, Manhattan distance, or Manhattan length
曼哈顿距离——两点在南北方向上的距离加上在东西方向上的距离,即d(i,j)=|xi-xj|+|yi-yj|。对于一个具有正南正北、正东正西方向规则布局的城镇街道,从一点到达另一点的距离正是在南北方向上旅行的距离加上在东西方向上旅行的距离,因此曼哈顿距离又称为出租车距离,曼哈顿距离不是距离不变量,当坐标轴变动时,点间的距离就会不同。
曼哈顿与欧几里得距离: 红、蓝与黄线分别表示所有曼哈顿距离都拥有一样长度(12),而绿线表示欧几里得距离有6×√2 ≈ 8.48的长度。
---------------------------------------------------------------------------------------------------------------------------------------
欧几里得距离Euclidean distance ,用尺子测量的距离
In mathematics, the Euclidean distance or Euclidean metric is the "ordinary" distance between two points that one would measure with a ruler, and is given by the Pythagorean formula
欧式距离即两项间的差是每个变量值差的平方和再平方根。
3、切比雪夫距离 Chebyshev distance
国际象棋玩过么?国王走一步能够移动到相邻的8个方格中的任意一个。那么国王从格子(x1y1)走到格子(x2y2)最少需要多少步?自己走走试试。你会发现最少步数总是max( | x2-x1 | | y2-y1 | ) 步 。有一种类似的一种距离度量方法叫切比雪夫距离。
![]() |
a | b | c | d | e | f | g | h | ![]() |
8 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
8 |
7 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
7 |
6 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
6 |
5 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
5 |
4 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
4 |
3 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
3 |
2 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
2 |
1 | ![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
1 |
![]() |
a | b | c | d | e | f | g | h | ![]() |
http://homepages.inf.ed.ac.uk/rbf/HIPR2/metric.htm
Distance Metrics
It is often useful in image processing to be able to calculate the distance between two pixels in an image, but this is not as straightforward as it seems. The presence of the pixel grid makes several so-called distance metrics possible which often give different answers to each other for the distance between the same pair of points. We consider the three most important ones.
Euclidean Distance
This is the familiar straight line distance that most people are familiar with. If the two pixels that we are considering have coordinates and
, then the Euclidean distance is given by:
City Block Distance
Also known as the Manhattan distance. This metric assumes that in going from one pixel to the other it is only possible to travel directly along pixel grid lines. Diagonal moves are not allowed. Therefore the `city block' distance is given by:
Chessboard Distance
This metric assumes that you can make moves on the pixel grid as if you were a King making moves in chess, i.e. a diagonal move counts the same as a horizontal move. This means that the metric is given by:
Note that the last two metrics are usually much faster to compute than the Euclidean metric and so are sometimes used where speed is critical but accuracy is not too important.
参考:
http://en.wikipedia.org/wiki/Distance_transform
Common metrics are: ***************
- Euclidean distance
- Taxicab geometry, also known as City block distance or Manhattan distance.
- Chessboard distance