1

I trying to write simple image computing program using Halide. So I start with brightness function.

I got this

Halide::ImageParam img(Halide::type_of<float>(), 3);
img.set_stride(0, 4);
img.set_stride(2, 1);
Halide::Func f;
Halide::Var x, y, c;
Halide::Param<float> brightnesMod;

f(x, y, c) = img(x,y,c) * brightnesMod;

f.vectorize(x, 16).parallel(y);

auto & obuff = f.output_buffer();
obuff.set_stride(0, 4);
obuff.set_stride(2, 1);
std::vector<Halide::Argument> arguments = { img, brightnesMod };
f.compile_to_file("function", arguments);
return 0;

but then I have a problem. My image is RGBA image so I compute algorithm with alpha. How can I skip it, and change f(x,y,c) to make c only 0-2?

2 Answers 2

1

That would mean that you want the output extent of c to be 3. It's the same as any other dimension: it has a minimum and an extent. Your input is RGBA, so 4 channels - its c extent is 4.

how many color channels will be produced, depends on the extents you request when you call the pipeline.

You could use:

obuff.set_extent(c, 3);

If you want to force the amount of channels to 3, which would result in an error if you try to request more or less than 3 channels.

0

As Sander said, you simply have to ask for the 3rd dimension to be of extent 3 instead of 4, in this case by passing in an output buffer with extent 3 in that dimension. You probably also want to set the stride over the color channels to 3 (set_stride(0,3) in your example, since you seem to want interleaved RGB data) if you only want a 3-channel output buffer. If you want an RGBA output buffer but with alpha ignored during computation, you'd leave the stride at 4 but set the extent to only 3.

Another note: using planar, rather than interleaved, storage will give much better performance for vectorizing over the x dimension like you are doing here. In general, vectorization works (by far) best over the innermost/densest storage dimension, especially for a computation this simple.

1
  • so... if i understand you correct I shoud change f.vectorize(x, 16).parallel(y); to something else? Jul 4, 2016 at 16:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.