This source file includes following definitions.
- build
#include "Halide.h"
namespace {
class EdgeDetect : public Halide::Generator<EdgeDetect> {
public:
ImageParam input{ UInt(8), 2, "input" };
Func build() {
Var x, y;
Func clamped = Halide::BoundaryConditions::repeat_edge(input);
Func in16;
in16(x, y) = cast<int16_t>(clamped(x, y));
Func gx;
Func gy;
gx(x, y) = (in16(x + 1, y) - in16(x - 1, y)) / 2;
gy(x, y) = (in16(x, y + 1) - in16(x, y - 1)) / 2;
Func grad_mag;
grad_mag(x, y) = (gx(x, y) * gx(x, y) + gy(x, y) * gy(x, y));
Func result;
result(x, y) = cast<uint8_t>(clamp(grad_mag(x, y), 0, 255));
result
.compute_root()
.vectorize(x, 8)
.parallel(y, 8);
input.dim(0).set_stride(Expr());
result.specialize(input.dim(0).stride() == 1);
result.specialize(input.dim(0).stride() == -1);
return result;
}
};
Halide::RegisterGenerator<EdgeDetect> register_edge_detect{ "edge_detect" };
}