输出在模板匹配中发生了偏移 [英] output shifted in template matching
本文介绍了输出在模板匹配中发生了偏移的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个模板匹配程序,该程序使用以下公式确定模板和图像之间的适合度:
I'm trying to create a template matching program that's using the following formula to determine the fit between the template and the image:
我的代码如下:
Halide::Var x, y, xt, yt;
Halide::RDom r(0, t.width(), 0, t.height());
Halide::Func limit, compare;
limit = Halide::BoundaryConditions::constant_exterior(input,255);
compare(x, y) = limit(x,y);
compare(x, y) = Halide::cast<uint8_t>(Halide::pow(t(0 + r.x, 0 + r.y) - limit(x + r.x, y + r.y),2));
Halide::Image<uint8_t> output(input.width(),input.height());
output = compare.realize(input.width(),input.height());
执行以下代码后,结果图像将像示例中那样移位:
After executing the following code the result image is shifted like in the example:
原始图片:
模板:
结果:
如何防止图像移位?
推荐答案
不确定t和输入的类型是什么,因此以下内容可能会溢出,但我认为您需要类似的东西:
Not sure what the types of t and input are, so the following might overflow, but I think you want something like:
Halide::Var x, y, xt, yt;
Halide::RDom r(0, t.width(), 0, t.height());
Halide::Func limit, compare;
limit = Halide::BoundaryConditions::constant_exterior(input,255);
compare(x, y) = limit(x,y);
compare(x, y) = Halide::cast<uint8_t>(sum(Halide::pow(t(r.x, r.y) - limit(x + r.x - t.width()/2, y + r.y - t.height()/2),2))/(t.width()*t.height()));
Halide::Image<uint8_t> output(input.width(),input.height());
output = compare.realize(input.width(),input.height());
这篇关于输出在模板匹配中发生了偏移的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文