How to Color a grayscale matrix with multiple colors per thresholds

Dante's icon

So i have a grayscale image coming in, values between 0 and 1 and I want to turn it into 5 colors. Say if values below 0.2 its yellow, if between 0.2 and 0.4 purple.

I have this mess of '>' '<' and 'if' objects in a pix, but im struggling. Also another issue I am having that is probably stupid, but feeding a float32 into rgb2luma @type float32 gives an error. In trying to create a clean example for the forum I created another problem of getting a grayscale 1 plane into gl.pix lol lol

Max Patch
Copy patch and select New From Clipboard in Max.

Dante's icon

still looking for any bits of help on this.

👽'tW∆s ∆lienz👽's icon

took a look at this awhile back, but couldn't figure everything out quickly... here's a bump, though, for anyone else that might pick this up.

in the meantime, i just noticed the helpfile says jit.rgb2luma "converts a 4-plane char"... so i think it's part of its internal algorithm to remain with char(and the 'type' attribute is non-functional).

i didn't understand your problem with the 1-plane grayscale(what was the intended result there?), but jit.rgb2luma outputs 1-plane no matter what, so if you wanted more, you might need to somehow 'reconstitute'(jit.pack?) back to 3/4-plane...

the rest seems like it's actually doing what you wanted, but it probably feels unwieldy because of the visual-paradigm(codebox would make these conditional-type functions more readable and probably slightly faster to type).

Dante's icon

Thanks again for your time Raja.

I was trying to mimic a colored spectroscope in openGL land. And I think all the tiny little mistakes I was making confused me. Although I am still unsure what the best way would be to color something with compounding thresholds like i said.

I initially thought the numbers coming into gl.pix would be 0. to 1., but it turns out they are 0- 255. Which is confusing because I thought 3 float 32 matrix data was -1 - 1. ? no ?

Also using the pass operators I think is helping, eg. >p , ==p etc

The patch is a pfft~ creating the monochrome sonogram and from there I use a similar gl.pix patch. Its close, but still seems off.

Max Patch
Copy patch and select New From Clipboard in Max.

testcase's icon

you can force gl.pix to use a
specific number type using the @type attribute.

as to you main question - i think you should use a second matrix input that you use to lookup values from the greyscale image. does that make sense?

Dante's icon

Thanks testcase, but I already have the greyscale image coming in the initial matrix so i dont think i am understanding you properly.

👽'tW∆s ∆lienz👽's icon

(today is the day i +1 everyone else's posts 😂 +1 for the look-up idea! 🙌)

i think you could use the 'sample' op within jit.gl.pix... the 2nd matrix would act like a color-swatch from which the 1st would lookup values(creating something a bit like the "jit.charmap" object... you could check that helpfile for the setup of a lookup matrix)

Dante's icon

lol Thanks Raja. Yes this technique makes sense to me now. I might try to build on gpu though since i know heavy stuff will hapen down the road. cheers