Binary decoding in jit.Gen
Hello,
I have a 16 plane 256x256 jitter matrix where each cell contains and int that's either 0 or 1. Taking the value of the same cell coordinate in all 16 planes gives you a binary number. I'm trying to make a jit.gen patch that gives me the decimal value of each cell, so i can turn this into a UV map of sorts.
Any jit.gen experts that could help me with this? Been stuck on this part of my project for days:)
Assuming the bit in plane 0 is the lowest bit, here is the core of the algorithm (genexpr code inside of a jit.gen codebox):
r = 0;
for (i=0; i<16; i+=1) {
bit = swiz(in1, i);
if (bit) {
r += pow(2, i);
}
}
out1 = r;I got stuck at getting any plane above the fourth one as I'm so used to swiz x/y/z/w or a/r/g/b with the dot notation (like in1.y ). If you want to address the plane with a number the dot notation doesn't work, but fortunately you can use the swiz() function instead, and that's new to me!
But before even digging into this I should have asked: how do you find yourself with such a matrix to begin with? Don't you have any control over the way it is generated so you can format it properly without having to deal with bit to integer conversion?
if it should be done right after the matrix, it could as well be done before storing it somewhere...?
Hey, thanks for reply!
I should maybe explain a bit further what the actual project is; a concept in computer vision that's called binary encoded structured illumination, which is a bit hard to explain, but i learned about it from the video below!
So i've generated a set of 256x256 matrixes/bit maps myself wcich when decoded should give 256x256 unique numbers, now i want to first get this binary decoding working to see if it decodes each cell to the same numbers i encoded. The goal is to be able to then project these bitmaps on an object and take pictures of each of them, so i can then calculate the light transport information.
I'm not familiar with codebox, so i'm not sure i understand how your patch works, but it doesn't seem to work for this purpose as far as i understand, sadly!
Thanks for the watch, that's an interesting technique.
My patch does what it does: take single bits from each plane and give the resulting number. As a proof, here is it again, but with the two steps conversion: I start from a 1 plane matrix with numbers between 0 and 65535 (max 16bit number), convert that into a 16 planes matrix with one bit per plane, and then reuse my previous patch to convert back into integers.
Why don't you provide a patch? Would help a lot understanding your context.