0

I am trying to define a function to generate a mask image using halide. There is a buffer

Buffer<int> bounding_box;
bounding_box(0, 0) = min_x0;
bounding_box(0, 1) = max_x0;
bounding_box(0, 2) = min_y0;
bounding_box(0, 3) = max_y0;
bounding_box(1, 0) = max_x1;
....

And I define Func Mask(x, y) equals to 0 everywhere but 255 if located in any box given in bounding_box, bounding_box is dynamic size.

Tried to use DRom but not able to success since the DRom arguments can not come be variable.

Cœur
  • 37,241
  • 25
  • 195
  • 267
UNCAL LEE
  • 23
  • 3

1 Answers1

0

Figured it out myself. It can be solved by create a function define each bounding box, and merge into a final function.

Func mask_stack(x, y, c) = select(x >= bounding_box(c, 0) && 
                               x <= bounding_box(c, 1) && 
                               y >= bounding_box(c, 2) && 
                               y <= bounding_box(c, 3), 255, 0)
RDom r(0, bounding_box.width());
Func mask(x, y) = 0;
mask(x, y) = Halide::max(mask(x, y), mask_stack(x, y, r));
Halide::Buffer<int> input_buf  = mask.realize(image_width, image_height);
UNCAL LEE
  • 23
  • 3