编程形态学开运算 returns 输入
Programming Morphological Opening returns input
我正在编写形态学开运算,它返回的结果与输入图像相同。我误解了它的解释吗?我的代码是:
Var x, y;
Func limit, erosion, dilation;
ImageParam input(type_of<uint8_t>(), 2);
Param<int> dimension;
RDom r(-1 * dimension / 2, dimension, -1 * dimension / 2, dimension);
limit = BoundaryConditions::repeat_edge(input);
erosion(x, y) = argmin(r, limit(x + r.x, y + r.y), "erosion")[2];
dilation(x, y) = argmax(r, erosion(x + r.x, y + r.y), "dilation")[2];
erosion.compute_root();
dilation.vectorize(x, 4).parallel(y);
Target target = get_host_target();
target.set_feature(Target::NoRuntime, true);
dilation.compile_to_static_library(path, { input,dimension }, target);
对我来说,以下似乎产生了与 OpenCV 教程图像相似的结果:
#include "Halide.h"
#include "../../tools/halide_image_io.h"
using namespace Halide;
int main(int argc, char **argv) {
Var x, y;
Func limit, erosion, dilation;
ImageParam input(type_of<uint8_t>(), 2);
Param<int> dimension;
RDom r(-1 * dimension / 2, dimension, -1 * dimension / 2, dimension);
limit = BoundaryConditions::repeat_edge(input);
#if 0
erosion(x, y) = minimum(limit(x + r.x, y + r.y), "erosion");
dilation(x, y) = maximum(erosion(x + r.x, y + r.y), "dilation");
#else
erosion(x, y) = argmin(r, limit(x + r.x, y + r.y), "erosion")[2];
dilation(x, y) = argmax(r, erosion(x + r.x, y + r.y), "dilation")[2];
#endif
erosion.compute_root();
dilation.vectorize(x, 4).parallel(y);
Image<uint8_t> in = Halide::Tools::load_image("/some/path/morphology.png");
input.set(in);
dimension.set(10);
Image<uint8_t> result = dilation.realize(in.width(), in.height());
Halide::Tools::save_image(result, "/some/path/morphology_out.png");
return 0;
}
#if 0 块旨在显示仅使用最小和最大运算符而不是 argmin/argmax。 argmin/argmax 的 r 参数也是可选的。
我想问一下错误是在于您如何将图像传递给 Halide AOT 编译函数,还是在于您如何处理返回的输出。您还可以使用 debug_to_file 或在 Halide 代码中打印来调试管道的中间阶段。
我正在编写形态学开运算,它返回的结果与输入图像相同。我误解了它的解释吗?我的代码是:
Var x, y;
Func limit, erosion, dilation;
ImageParam input(type_of<uint8_t>(), 2);
Param<int> dimension;
RDom r(-1 * dimension / 2, dimension, -1 * dimension / 2, dimension);
limit = BoundaryConditions::repeat_edge(input);
erosion(x, y) = argmin(r, limit(x + r.x, y + r.y), "erosion")[2];
dilation(x, y) = argmax(r, erosion(x + r.x, y + r.y), "dilation")[2];
erosion.compute_root();
dilation.vectorize(x, 4).parallel(y);
Target target = get_host_target();
target.set_feature(Target::NoRuntime, true);
dilation.compile_to_static_library(path, { input,dimension }, target);
对我来说,以下似乎产生了与 OpenCV 教程图像相似的结果:
#include "Halide.h"
#include "../../tools/halide_image_io.h"
using namespace Halide;
int main(int argc, char **argv) {
Var x, y;
Func limit, erosion, dilation;
ImageParam input(type_of<uint8_t>(), 2);
Param<int> dimension;
RDom r(-1 * dimension / 2, dimension, -1 * dimension / 2, dimension);
limit = BoundaryConditions::repeat_edge(input);
#if 0
erosion(x, y) = minimum(limit(x + r.x, y + r.y), "erosion");
dilation(x, y) = maximum(erosion(x + r.x, y + r.y), "dilation");
#else
erosion(x, y) = argmin(r, limit(x + r.x, y + r.y), "erosion")[2];
dilation(x, y) = argmax(r, erosion(x + r.x, y + r.y), "dilation")[2];
#endif
erosion.compute_root();
dilation.vectorize(x, 4).parallel(y);
Image<uint8_t> in = Halide::Tools::load_image("/some/path/morphology.png");
input.set(in);
dimension.set(10);
Image<uint8_t> result = dilation.realize(in.width(), in.height());
Halide::Tools::save_image(result, "/some/path/morphology_out.png");
return 0;
}
#if 0 块旨在显示仅使用最小和最大运算符而不是 argmin/argmax。 argmin/argmax 的 r 参数也是可选的。
我想问一下错误是在于您如何将图像传递给 Halide AOT 编译函数,还是在于您如何处理返回的输出。您还可以使用 debug_to_file 或在 Halide 代码中打印来调试管道的中间阶段。