removing cells of specific value from a matrix

matheus leston's icon

i'm developing a patch in which a kinect is used to generate some 3d graphics via a jit.gl.mesh. i'm clipping the kinect's image with jit.map with the @clip 1 argument (so that i can select an specific depth) and using it as the z coordinate of mesh (third plane of the matrix).

the problem with this method is that the background is also rendered in the mesh and i want it to disappear completely. so far my solution is to use the z coordinate also as the alpha channel of the color matrix, creating transparent points, but it would be better if they do not exist at all.

so, is there a way to remove those points from the matrix? I guess the solution would be to create a one row matrix with all the points and remove points bellow certain threshold, creating and matrix with variable length. is this possible?

LSka's icon

Yes, I do it using an external by Wesley Smith, http://www.mat.ucsb.edu/~whsmith/xray/xray.jit.sift.html
I use the z plane to tag all the which need to be filtered out (the ones which value is 0)

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

Unfortunately, the external is 32 bit only, but I can survive with this!

matheus leston's icon

Lska, thank you, that is exactly what I'm looking for! I will test it with the 32 bit version of Max, but unfortunately I'm using the 64 bit version Max 7 with the 64 bit port of the jit.freenect.grab. Do you know if there is another possible solution?

phiol's icon

Hello LSKA

Could you possible for you to do a small demo of how you hook up your module to mesh.
Endless thanks

phiol

phiol's icon

oops , forgot to include the patch I made.
This is how I think you're using your module. but clearly not cause this doesn't work.

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

Thanks again guys

LSka's icon

@Matheusleston: the sources are released with the externals, so I guess it could be possible to compile it for 64-bit. I tried, but obviously there are some issues with the Max7 SDK (the code is from 2006...), maybe someone with more coding knowledge than me can help..

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

@Phiol:
I directly plug it to the "vertex array" inlet of jit.gl.mesh.
Check out this example using a kinect input:

phiol's icon

thanks a lot LSKA

Here is one way I do it using gen and can stay in 64 bit :-) !
It's not perfect but works for certain situations.

Note: Notice that the little glitch that will appear in the vertices is because I accidentally record my mouse arrow
while doing a screen capture of the kinect user.

Thanks again for your patch LSKA

matheus leston's icon

@Lska Unfortunately I have no idea on how to do it. No knowledge at all on how to compile a source into something Max can understand and even less on how to change the code for 64 bits. But maybe some another good soul in the forum might help us!

@Phiol That is a great idea: jit.gen might solve the problem for me. I have never used it, but I will give it a go.

Thank you for the patch, but I don't think that this solution will work with jit.gl.mesh. In order for it to ignore the background at all, it is necessary to remove those pixels from the matrix, changing its size. In your patch, the matrix is filtered below a certain value, but those "black" pixels are still there and are rendered as 0 0 0 points in the mesh. If you change the draw mode to something like line_loop you can see it.

phiol's icon

Here is a way of slicing vertices using jit.gen and clip.
I believe it was tweak or created by Wes smith.

Below is a version tweaked by matmat/silicat.

Hope these help

phiol

slicing-vertices-in-jit.gen-with-clip.maxpat
Max Patch
slicing-vertices-silicat-in-jit.gen-with-clip.maxpat
Max Patch
matheus leston's icon

@PHIOL I think I might be missing something here. I still couldn't find out how those approach could be used in my situation. As I tested, in the patches you sent the matrix size remains constant. The values are clipped, but the amount of pixels stay the same.
Do you think it is possible to use gen to remove pixels from a 1 row matrix that are below certain threshold?

phiol's icon

I guess you're right!
I thought the vertices were being clipped as in sliced out.

>>Do you think it is possible to use gen to remove pixels from a 1 row matrix that are below certain threshold?
I guess I don't know any other way than LSKA's/Wes's xray patch .
Doesn't that work ?

I'll leave this up to more knowledgeable gen users .

sorry about that

matheus leston's icon

@PHIOL I tried to use xray, but I couldn't get it to work in Max 7, even when running in 32 bit mode. No idea why! I have written an email to Wes asking about it. Let's see! Any ideas on how to make it work?

phiol's icon

try this out and see.

Tiny mod on LSKA's nice patch

helping-matheusleston.zip
zip