Better option for posterization?
I have a patch (below) that works for basic posterization in Jitter. It uses jit.op to accomplish the same as:
if $i1 > 50 && $i1 < 100
It divides the matrix by ranges of brightness, then colors them using jit.op as well. Not too clean compared to similar operations in Processing, etc. I tried jit.expr but there's not much documentation for if/then statements that I could find.
In any case, it seems there must be a cleaner or more processing-efficient way to do this? JavaScript in Jitter is too slow for per-pixel processing (at least how I've accomplished it using for loops). GL shaders?
Any thoughts would be great - not really a pressing issue but I'd be interested to hear some suggestions. Thanks all!
[ jit.expr @inputs 3 @expr (in[0]>in[1])&&(in[0]
this can easily be done with shaders but you'll only benefit from that if you do all the operations like the adding and crossfade in slabs on the GPU too.
Thanks Dieter - there's no way to do much in the way of the 'then' side of 'if/then' using jit.expr, right?
Agreed about the shaders at this point. This is the first step in homemade video compression algorithms. I'm interested in per-pixel manipulation based on neighboring pixels. For example, if the neighboring pixel is different enough to the current pixel by a certain threshold, set the neighbor's color to that of the current pixel. This would be done across each frame in all four directions (up, down, left, right).
ie (in pseudo-code):
if absVal(pxLeft-pxCurrent) < threshold then pxLeft == 100,0,0
Here's an example created in Processing:
https://vimeo.com/35599989
Thoughts? Possible in real-time?
sounds like a job for jit.gen/jit.gl.gen... have a look at the samples here: https://cycling74.com/forums/gen-patch-a-day
btw, there are ways to package if/then constructs mathematically in expr. if a>b then c else d translates to:
@expr (in[0]>in[1])*in[3]+(in[0]
expr takes a bit of work to get into but once you do it's quite powerful.
Yep, Gen's looking like an interesting possibility (and looks much simpler than shaders).
Let's see if I can parse your example:
1. Test if the values from matrix 0 are greater than a certain value, which returns white (if not, then black)
2. Multiply the result by a fixed number; black (0) * anything will still stay black, while the white (1) will now be the new value
3. Same happens using a
What I can't figure out is the + operation - is that the same as && in this case?
Suggestions for a place to find good documentation on if/then statements? Seems to be a good tutorial here on basic math functions, but not much for logical comparisons.
(and thanks for the replies!)
i'm still learning gen, but maybe this will get you started:
> What I can't figure out is the + operation - is that the same as && in this case?
no, * would equal && (AND)
+ equals ⎜⎜ (OR)
in our case (in[0]>in[1])*in[3]+(in[0]
the comparisons either yield 0*in[3]+1*in[4] or 1*in[3]+0*in[4]
which equates to in[4] or in[3] (= our then and else values)
Fantastic - took me a while to figure out what you had written! :)
As I understand it, your expression returns values above or below a certain value, rather than if it falls in a range (ie: 0.5 - 0.7). If a second test value is added (in[2]) wouldn't that give the range?
"(in[0] > in[1]) * in[3] + (in[0]
It appears that the expression could then be written more traditionally as:
if (in[0] > in[1]) then output in[3]
else if (in[0]
Everything works great, but I get three colors, not two... Looks like the third color is a combination of the two.
almost there ;)
"(in[0] > in[1]) * in[2] + (in[0]
if (in[0]>in[1]) then output in[2]
else output in[3]
so if you want:
if (in[0] > in[1]) then output in[3]
else if (in[0]
you need:
(in[0] > in[1]) * in[3] + (in[0]
this function will output 0 if in[0]in[2]
Whew, ok - took about 2 hours to get my head around this. It's a matter of thinking in terms of a series of 0/1 statements - so weird and arcane compared to modern if/then/else series. In any case, for others banging their heads against this I built an example patch. Thanks Dieter for your patience! (and time to take a look at Gen)
there you have it! arcane but efficient ;)