2017-08-01 49 views
0

函數我試圖定義一個函數來使用鹵化物生成掩碼圖像。 有一個緩衝定義緩衝區作爲邊界框參數halide

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; 
.... 

我定義Func Mask(x, y)等於0無處不在,但如果255座落在bounding_box給出任何框,bounding_box是動態的大小。

試圖使用DRom,但由於DRom參數不能變化而無法成功。

回答

0

自己想出來。 它可以通過創建一個函數來定義每個邊界框,併合併成一個最終函數。

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);