ffmpeg lutrgb to create zebras I'm trying to display zebras (colorize totally black pixels one color and totally white pixels a second color) on a selected frame from a video using ffmpeg.  Using an rgb lookup table expression I'm getting a workable solution: 

lutrgb=r='if(eq(val,0),0,val)':g='if(eq(val,0),153,val)':b='if(eq(val,0),254,val)',lutrgb=r='if(eq(val,255),254,val)':g='if(eq(val,255),102,val)':b='if(eq(val,255),0,val)'


The problem with this expression is that it's testing each pixel for clipping by color, then modding only if that color component = 0 or 255.  My video is largely black and white, but a slight pixel level color shift results in a two toned zebra pattern.  You can see the two shades of blue in this sample zebra frame:



If I could test for the maxval for clipping into 0 and minval for 255 I would think this problem would be solved, but this code below doesn't work:

lutrgb=r='if(eq(maxval,0),0,val)':g='if(eq(maxval,0),153,val)':b='if(eq(maxval,0),254,val)',lutrgb=r='if(eq(minval,255),254,val)':g='if(eq(minval,255),102,val)':b='if(eq(minval,255),0,val)'


The if/then code for filters is poorly documented on the ffmpeg wiki.  Any LUT experts out there?
Assuming your input is full range RGB when fed to the filter, then something like

geq=r='if(between(st(1,r(X,Y)+g(X,Y)+b(X,Y)),15,750),p(X,Y),if(lt(ld(1),15),C1R,C2R))':
    g='if(between(st(1,r(X,Y)+g(X,Y)+b(X,Y)),15,750),p(X,Y),if(lt(ld(1),15),C1G,C2G))':
    b='if(between(st(1,r(X,Y)+g(X,Y)+b(X,Y)),15,750),p(X,Y),if(lt(ld(1),15),C1B,C2B))'


Here the two colors are (C1R,C1G,C1B) and (C2R,C2G,C2B). with each component range being 0-255.

The 15 and 750 are the thresholds for selecting black and white pixels. The sum of the values of the three components for each pixel is compared to those values.

The st and ld functions are store and load functions with the first argument being the 'register no.'.

You can also try the colorkey filter.