Reporting the second lowest value in a matrix

Jun 18, 2013 at 10:20am

Reporting the second lowest value in a matrix

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! :)

#253103
Jun 19, 2013 at 2:02am

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 (100×100) 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?

#253223
Jun 19, 2013 at 4:09am

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?

#253234
Jun 19, 2013 at 4:55am

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?

#253240
Jun 19, 2013 at 5:13am

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…)

#253243
Jun 19, 2013 at 7:12am

Horrah! That’s nailed it! Thanks guys.

#253263

You must be logged in to reply to this topic.