How to use halide operator ==

588 Views Asked by At

I'm a newbie of Halide and I'm trying to convert a RGB image to HSV format. The algorithm is below

*RGB->HSV
max=max(R,G,B):
min=min(R,G,B)
V=max(R,G,B)
S=(max-min)/max:
ifR = max,H =(G-B)/(max-min)* 60
ifG = max,H = 120+(B-R)/(max-min)* 60
ifB = max,H = 240 +(R-G)/(max-min)* 60
ifH < 0,H = H+ 360*

so I write the code like this:

Halide::Expr H,S,V,maxValue,minValue;
Halide::Expr R = input(x,y,0);
Halide::Expr G = input(x,y,1);
Halide::Expr B = input(x,y,2);

maxValue=Halide::max(R,G);
maxValue=Halide::max(maxValue,B);
minValue=Halide::min(R,G);
minValue=Halide::min(minValue,B);

V=maxValue;
S=(maxValue-minValue)/maxValue;

if(Halide::operator==(maxValue,R)){
    H=(G-B)/(maxValue-minValue)*60;
}else if(Halide::operator==(maxValue,G)){
    H=120+(B-R)/(maxValue-minValue)*60;
}else if(Halide::operator==(maxValue,B)){
H=240+(R-G)/(maxValue-minValue)*60;
}

When I try to compile the code, it report a error like this:

error: could not convert 釮alide::operator==(Halide::Expr, Halide::Expr)(Halide::Expr((*(const Halide::Expr*)(& G))))?from 釮alide::Expr?to 鈈ool?
   }else if(Halide::operator==(maxValue,G)){
                                          ^

Can anyone tell me what's wrong and how to resolve it?

1

There are 1 best solutions below

0
On

You want to use the Halide::select() function:

H = Halide::select(maxValue == R, (G-B)/(maxValue-minValue)*60,
                   maxValue == G, 120+(B-R)/(maxValue-minValue)*60,
                   maxValue == B, 240+(R-G)/(maxValue-minValue)*60,
                   /* else */     someOtherValue);