I am currently evaluating if Halide is a good choice for my programmes. As a short Hello Halide example, I wanted to convert an rgb image to hsl space. However, when trying, I got stuck at the first stage.
In order to convert to hsl, I would need to calculate the chroma image first. This is the difference between the maximum and minimum channel value for a given pixel. I tried to find something similar in the documentation, but I was not able to. How would I do this in Halide?
In C++ it would be something like:
for (auto y = 0; y < image.height(); ++y)
for (auto x = 0; x < image.width(); ++x)
{
auto maximum = 0;
auto minimum = 255;
for (auto c = 0; c < image.channels(); ++c)
{
if (image(x, y, c) < minimum)
minimum = image(x, y, c);
if (image(x, y, c) > maximum)
maximum = image(x, y, c);
}
chroma(x, y) = maximum - minimum;
}