我的代码很简单-我对图像进行阈值处理,然后尝试将DistanceTransform
应用于它:
var source = new Mat(path, ImreadModes.AnyDepth | ImreadModes.AnyColor);
var bgr = new Mat[3];
var thresh = new Mat();
var dist = new Mat();
Cv2.Split(source, out bgr);
Cv2.AdaptiveThreshold(bgr[2], thresh, 255, AdaptiveThresholdTypes.MeanC, ThresholdTypes.Binary, 13, 2);
Cv2.ImShow("thresh", thresh);
Cv2.DistanceTransform(thresh, dist, DistanceTypes.L2, DistanceMaskSize.Mask5);
Cv2.ImShow("dist", dist);
但这好像根本没有应用过滤器:
最佳答案
事实证明,这是无法将图像从32位Normalize
降至8位(如this answer所述)。
添加以下行后,图像将达到预期效果:
Cv2.Normalize(dist, dist, 0, 1, NormTypes.MinMax);