distance_transformdistance_transformDistanceTransformDistanceTransformdistance_transform(算子)
名称
distance_transformdistance_transformDistanceTransformDistanceTransformdistance_transform — 计算区域的距离变换。
签名
Herror distance_transform(const Hobject Region, Hobject* DistanceImage, const char* Metric, const char* Foreground, const Hlong Width, const Hlong Height)
Herror T_distance_transform(const Hobject Region, Hobject* DistanceImage, const Htuple Metric, const Htuple Foreground, const Htuple Width, const Htuple Height)
void DistanceTransform(const HObject& Region, HObject* DistanceImage, const HTuple& Metric, const HTuple& Foreground, const HTuple& Width, const HTuple& Height)
HImage HRegion::DistanceTransform(const HString& Metric, const HString& Foreground, Hlong Width, Hlong Height) const
HImage HRegion::DistanceTransform(const char* Metric, const char* Foreground, Hlong Width, Hlong Height) const
HImage HRegion::DistanceTransform(const wchar_t* Metric, const wchar_t* Foreground, Hlong Width, Hlong Height) const
(
Windows only)
描述
distance_transformdistance_transformDistanceTransformDistanceTransformDistanceTransformdistance_transform computes for every point of the input
region RegionRegionRegionRegionregionregion (or its complement, respectively) the
distance of the point to the border of the region. The parameter
ForegroundForegroundForegroundForegroundforegroundforeground determines whether the distances are calculated
for all points within the region (ForegroundForegroundForegroundForegroundforegroundforeground =
'true'"true""true""true""true""true") or for all points outside the region
(ForegroundForegroundForegroundForegroundforegroundforeground = 'false'"false""false""false""false""false"). The distance is computed
for every point of the output image DistanceImageDistanceImageDistanceImageDistanceImagedistanceImagedistance_image, which
has the specified dimensions WidthWidthWidthWidthwidthwidth 和 HeightHeightHeightHeightheightheight.
The input region is always clipped to the extent of the output
image. If it is important that the distances within the entire
region should be computed, the region should be moved (see
move_regionmove_regionMoveRegionMoveRegionMoveRegionmove_region) so that it has only positive coordinates and
the width and height of the output image should be large enough to
contain the region. The extent of the input region can be obtained
with smallest_rectangle1smallest_rectangle1SmallestRectangle1SmallestRectangle1SmallestRectangle1smallest_rectangle1。
The parameter MetricMetricMetricMetricmetricmetric determines which metric is used for
the calculation of the distances. If MetricMetricMetricMetricmetricmetric =
'city-block'"city-block""city-block""city-block""city-block""city-block", the distance is calculated from the shortest
path from the point to the border of the region, where only
horizontal and vertical “movements” are allowed. They are
weighted with a weight of 1. If MetricMetricMetricMetricmetricmetric =
'chessboard'"chessboard""chessboard""chessboard""chessboard""chessboard", the distance is calculated from the shortest
path to the border, where horizontal, vertical, and diagonal
“movements” are allowed. They are weighted with a weight of 1.
If MetricMetricMetricMetricmetricmetric = 'octagonal'"octagonal""octagonal""octagonal""octagonal""octagonal", a combination of these
approaches is used, which leads to diagonal paths receiving a higher
weight. If MetricMetricMetricMetricmetricmetric = 'chamfer-3-4'"chamfer-3-4""chamfer-3-4""chamfer-3-4""chamfer-3-4""chamfer-3-4", horizontal and
vertical movements are weighted with a weight of 3, while diagonal
movements are weighted with a weight of 4. To normalize the
distances, the resulting distance image is divided by 3. Since this
normalization step takes some time, and one usually is interested in
the relative distances of the points, the normalization can be
suppressed with MetricMetricMetricMetricmetricmetric =
'chamfer-3-4-unnormalized'"chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized". Finally, if MetricMetricMetricMetricmetricmetric =
'euclidean'"euclidean""euclidean""euclidean""euclidean""euclidean", the computed distance is approximately
Euclidean.
执行信息
- 多线程类型:可重入(与非独占算子并行运行)。
- 多线程作用域:全局(可从任何线程调用)。
- 未采用并行化处理。
参数
RegionRegionRegionRegionregionregion (输入对象) region(-array) → objectHRegionHObjectHRegionHobject
用于计算与边界距离的区域。
DistanceImageDistanceImageDistanceImageDistanceImagedistanceImagedistance_image (输出对象) image → objectHImageHObjectHImageHobject * (int4)
包含距离信息的图像。
MetricMetricMetricMetricmetricmetric (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
Type of metric to be used for the distance
transformation.
默认值:
'city-block'
"city-block"
"city-block"
"city-block"
"city-block"
"city-block"
值列表:
'chamfer-3-4'"chamfer-3-4""chamfer-3-4""chamfer-3-4""chamfer-3-4""chamfer-3-4", 'chamfer-3-4-unnormalized'"chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized""chamfer-3-4-unnormalized", 'chessboard'"chessboard""chessboard""chessboard""chessboard""chessboard", 'city-block'"city-block""city-block""city-block""city-block""city-block", 'euclidean'"euclidean""euclidean""euclidean""euclidean""euclidean", 'octagonal'"octagonal""octagonal""octagonal""octagonal""octagonal"
ForegroundForegroundForegroundForegroundforegroundforeground (输入控制) string → HTuplestrHTupleHtuple (string) (string) (HString) (char*)
计算输入区域内部('true'"true""true""true""true""true")或外部('false'"false""false""false""false""false")像素的距离。
默认值:
'true'
"true"
"true"
"true"
"true"
"true"
值列表:
'false'"false""false""false""false""false", 'true'"true""true""true""true""true"
WidthWidthWidthWidthwidthwidth (输入控制) extent.x → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
输出图像的宽度。
默认值:
640
建议值:
160, 192, 320, 384, 640, 768
值范围:
1
≤
Width
Width
Width
Width
width
width
HeightHeightHeightHeightheightheight (输入控制) extent.y → HTupleintHTupleHtuple (integer) (int / long) (Hlong) (Hlong)
输出图像的高度。
默认值:
480
建议值:
120, 144, 240, 288, 480, 576
值范围:
1
≤
Height
Height
Height
Height
height
height
示例(HDevelop)
* Step towards extracting the medial axis of a shape:
gen_rectangle1 (Rectangle1, 0, 0, 200, 400)
gen_rectangle1 (Rectangle2, 200, 0, 400, 200)
union2 (Rectangle1, Rectangle2, Shape)
distance_transform (Shape, DistanceImage, 'chessboard', 'true', 640, 480)
复杂度
运行时间复杂度为 O(WidthWidthWidthWidthwidthwidth*HeightHeightHeightHeightheightheight)。
结果
distance_transformdistance_transformDistanceTransformDistanceTransformDistanceTransformdistance_transform 在所有参数正确时返回 2 (H_MSG_TRUE)。
可能的前趋
thresholdthresholdThresholdThresholdThresholdthreshold,
dyn_thresholddyn_thresholdDynThresholdDynThresholdDynThresholddyn_threshold,
regiongrowingregiongrowingRegiongrowingRegiongrowingRegiongrowingregiongrowing
可能的后继
thresholdthresholdThresholdThresholdThresholdthreshold
替代
closest_point_transformclosest_point_transformClosestPointTransformClosestPointTransformClosestPointTransformclosest_point_transform
另见
skeletonskeletonSkeletonSkeletonSkeletonskeleton
参考文献
P. Soille: “Morphological Image Analysis, Principles and
Applications”; Springer Verlag Berlin Heidelberg New York,
1999.
G. Borgefors: “Distance Transformations in Arbitrary Dimensions”;
Computer Vision, Graphics, and Image Processing, Vol. 27, pages
321--345, 1984.
P.E. Danielsson: “Euclidean Distance Mapping”; Computer Graphics
and Image Processing, Vol. 14, pages 227--248, 1980.
模块
基础