#include "HxImageRep.h"
Go to the source code of this file.
Functions | |
HxImageRep L_HXIMAGEREP | HxDistanceTransform (HxImageRep img) |
Distance transform replaces each pixel of an object with an estimate of its shortest distance to the background (the distance to the nearest background pixel). More... |
|
Distance transform replaces each pixel of an object with an estimate of its shortest distance to the background (the distance to the nearest background pixel). Background is defined as all pixels with value 0.
00089 { 00090 HxString fname("HxDistanceTransform"); 00091 00092 if (img.pixelDimensionality() != 1) 00093 { 00094 HxGlobalError::instance()->reportError(fname, "operation only valid on scalar types", HxGlobalError::HX_GE_UNEQUAL_IMAGES); 00095 return HxImageRep(); 00096 } 00097 00098 HxImageRep input = BinMap(HxImageAsDouble(img), inf, 0); 00099 00100 double filterData[] = { 00101 inf, sqrt_5, inf, sqrt_5, inf, 00102 sqrt_5, sqrt_2, 1, sqrt_2, sqrt_5, 00103 inf, 1, 0, 1, inf, 00104 sqrt_5, sqrt_2, 1, sqrt_2, sqrt_5, 00105 inf, sqrt_5, inf, sqrt_5, inf 00106 }; 00107 HxImageRep kernel = HxMakeFromDoubleData(1, 2, HxSizes(5, 5, 1), filterData); 00108 00109 return input.recGenConv(kernel, "add", "minAssign"); 00110 } |