如何使用 4 个通道而不是 3 个通道在 Halide 中使用 load_image()?

How to load_image() in Halide with 4 channels instead of 3?

我想在 Halide 中加载时获得 4 通道图像而不是 3 通道图像,但是 load_image() 仅提供 3 通道图像。我该如何解决?

Halide 的load_image 函数只是从磁盘加载图像文件。如果它是RGB,它将有三个通道,如果它是RGBA,它将有四个通道。这是按预期工作的。

如果你想在流水线中为你的图像添加一个通道,那么你可以这样写:

Buffer<uint8_t> input = load_image(...);

Func alpha_255;
alpha_255(x, y, c) = select(c == 3, 255, input(x, y, c));

然后您可以根据需要安排该功能。您很可能最终会将其内联到一个消费者中,该消费者的最内层通道维度已展开以摆脱 select.