The following code is adapted from the Halide tutorials.
Func blurX(Func continuation)
{ Var x("x"), y("y"), c("c");
Func input_16("input_16");
input_16(x, y, c) = cast<uint16_t>(continuation(x, y, c));
Func blur_x("blur_x");
blur_x(x, y, c) = (input_16(x-1, y, c) +
2 * input_16(x, y, c) +
input_16(x+1, y, c)) / 4;
Func output("outputBlurX");
output(x, y, c) = cast<uint8_t>(blur_x(x, y, c));
return output;
}
int main()
{ Var x("x"), y("y"), c("c");
Image<uint8_t> input = load_image("input.png");
Func clamped("clamped");
clamped = BoundaryConditions::repeat_edge(input);
Func img1Fun("img1Fun");
Func img2Fun = blurX(clamped);
Func outputFun("outputFun");
/* carry on */
}
I've three questions:
Casting Is the cast
cast<uint16_t>(clamped(x, y, c))casting the 8bit R G and B values at every (x,y) position to a 16bit integer i.e. what the cast returns is an RGB image that can be indexed e.g img1Fun(x, y, 0) to access its R value? Or is this casting every RGB pixel in the image to its luminance value between [0..1] for the RGB pixel at every (x,y) position, i.e.r*0.3 + g*0.59 + b*0.11?Overloading RGB blur are arithmetic operations on
(x,y,c)overloaded on all indexes? E.g.
(input_16(x-1, y, c) + 2 * input_16(x, y, c) + input_16(x+1, y, c)) / 4;
Is this an overloading of:
(input_16(x-1, y, 0) + 2 * input_16(x, y, 0) + input_16(x+1, y, 0)) / 4;
(input_16(x-1, y, 1) + 2 * input_16(x, y, 1) + input_16(x+1, y, 1)) / 4;
(input_16(x-1, y, 2) + 2 * input_16(x, y, 2) + input_16(x+1, y, 2)) / 4;
- Parallelising how could I parallelise
blurX? Based on thebrighten.cppexample from CVPR'15 here, I could useblur_x.vectorize(x, 4).parallel(y);to vectorise row wise in the X direction, parallelising across threads in the Y direction.. like this?
Func blurX(Func continuation)
{ Var x("x"), y("y"), c("c");
Func input_16("input_16");
input_16(x, y, c) = cast<uint16_t>(continuation(x, y, c));
Func blur_x("blur_x");
blur_x(x, y, c) = (input_16(x-1, y, c) +
2 * input_16(x, y, c) +
input_16(x+1, y, c)) / 4;
blur_x.vectorize(x, 4).parallel(y);
Func output("outputBlurX");
output(x, y, c) = cast<uint8_t>(blur_x(x, y, c));
return output;
}