如何在 Halide 中单独修改颜色通道?

How to modify color channels individually in Halide?

我对修改 Halide 像素的各个颜色通道很感兴趣。例如,我怎样才能使红色通道变亮但保持绿色和蓝色通道不变?使所有像素的所有颜色变亮看起来像这样:

Halide::Expr value = input(x, y, c);
value = value * 2.0f;
brighter(x, y, c) = value;

但是当尝试使用以下方法调亮单个通道时,收到错误消息。

Halide::Expr value = input(x, y, c);
value(x,y,0) = value(x,y,0) * 2.0f; // brighten red
value(x,y,1) = value(x,y,2);        // keep green the same
value(x,y,2) = value(x,y,3);        // keep blue the same
brighter(x, y, c) = value;

错误:

ImgPipe_Halide.cpp:88:14: error: no match for call to ‘(Halide::Expr) (Halide::Var&, Halide::Var&, int)’

那么,如何从像素中读取各个通道值,以及如何修改它们?

一种方法是使用 halide 的 select 函数

示例:

value = Halide::select(c == 0, input(x,y,c) * 2.0f,
                       input(x,y,c));