Reporting the second lowest value in a matrix

Beep's icon

I have been playing with jit.openni and would like to report how far away an object is from the kinect. To do this I will need to report on the lowest value in the 1 plane depth map output. My question then is how do I report the second lowest value within a matrix so that I can ignore black areas?

Any help would be appreciated! :)

Beep's icon

I've tried using jit.spill to output a list, hoping that I could run zl on it and extract the second lowest value. While this would work in theory, outputting the medium sized matrix (100x100) as a list was too much of a drain on my system. I've also looked at jit.3m which can tell me the minimum value of the matrix but not he second lowest value. Am I looking in the right places, or are their any obvious objects I should be looking at?

Wetterberg's icon

if you use jit.3m and get the lowest value, you can process that value out of your matrix, leaving you with second-lowest and above, right?

Beep's icon

Thanks for the reply Wetterberg. Your logic seems spot on to me, but I'm unsure how to do that, sadly my experience with Jitter is not comparable to my experience with Max! I know that my minimum will always be 0 within the Kinect depth map feed I am using, so how best to process out 0's from my matrix?

dtr's icon

You could make it something really large like 999999 with a jit.expr, before running it into jit.3m:

jit.expr @expr ((in[0]==0.)*999999.)+((in[0]!=0.)*in[0])

This equals to: if $f1 == 0 then 999999 else $f1

(My jit.expr 's a bit rusty so hope that's correct...)

Beep's icon

Horrah! That's nailed it! Thanks guys.