這是我的第一篇文章,所以對不起,如果我做錯了什麼:)。我會盡力做到最好。使用鹵素與HDR圖像表示爲浮法陣列
我目前正在研究HDR圖像處理程序,並且我使用Halide實現了一些基礎TMO。問題是我所有的圖像被表示爲浮點數組(例如:b1,g1,r1,a1,b2,g2,r2,a2,...)。使用Halide處理圖像需要使用Halide :: Image類。問題是我不知道如何在那裏傳遞這些數據。
任何人都可以幫忙,或有同樣的問題,並知道答案?
編輯:
終於明白了!我需要在發生器中設置輸入和輸出緩衝區的大小。 THX所有的幫助:-)
編輯:
我嘗試兩種不同的方式:
int halideOperations(float data[] , int size, int width,int heighy)
{
buffer_t input_buf = { 0 };
input_buf.host = &data[0];
}
或:
int halideOperations(float data[] , int size, int width,int heighy)
{
Halide::Image(Halide::Type::Float, x, y, 0, 0, data);
}
我在想編輯Halide.h文件,並改變uint8_t *主機float_t *主機,但我不認爲這是個好主意。
編輯:
我嘗試使用下面的代碼與我的浮動圖像(RGBA):
AOT函數生成:
int main(int arg, char ** argv)
{
Halide::ImageParam img(Halide::type_of<float>(), 3);
Halide::Func f;
Halide::Var x, y, c;
f(x, y, c) = Halide::pow(img(x,y,c), 2.f);
std::vector<Halide::Argument> arguments = { img };
f.compile_to_file("function", arguments);
return 0;
}
正確的代碼調用:
int halideOperations(float data[], int size, int width, int height)
{
buffer_t output_buf = { 0 };
buffer_t buf = { 0 };
buf.host = (uint8_t *)data;
float * output = new float[width * height * 4];
output_buf.host = (uint8_t*)(output);
output_buf.extent[0] = buf.extent[0] = width;
output_buf.extent[1] = buf.extent[1] = height;
output_buf.extent[2] = buf.extent[2] = 4;
output_buf.stride[0] = buf.stride[0] = 4;
output_buf.stride[1] = buf.stride[1] = width * 4;
output_buf.elem_size = buf.elem_size = sizeof(float);
function(&buf, &output_buf);
delete output;
return 1;
}
不幸我碰到了msg:
Error: Constraint violated: f0.stride.0 (4) == 1 (1)
我覺得這行有一些錯誤:output_buf.stride [0] = buf.stride [0] = 4,但我不確定應該改變什麼。有小費嗎?
嗨,歡迎!你能告訴我們你試過的代碼嗎? – rhughes
我試圖使用buffer_t和正常的Halide :: Image,但它們都使用uint8而不是float數據:int halideOperations(float data [],int size,int x,int y) \t \t \t buffer_t input_buf = {0 }; \t \t input_buf.host =&data [0]; } or: \t \t Halide :: Image(Halide :: Type :: Float,x,y,0,0,data); –
謝謝。你可以編輯你的問題給我們看你的代碼嗎? – rhughes