Assuming depth
is a byte array with 2 * width
bytes per row, and height
rows, try something like this:
var points = new List<Point>();
for( int y = 0; y < height; y++ )
for( int x = 0; x < width; x++ )
{
int i = y * width * 2 + x * 2;
int dist = GetDistance( depth[i], depth[i + 1] );
if( dist < z2 && dist > z1 )
points.Add( new Point( x, y ) );
}
You'll obviously have to replace Point
with some type to represent an int x/y pair!
You could also do it with a simple for (int i = 0; i < depth.Length; i += 2)
as before, and then calculate the x/y values from i
. (Hint: the modulus operator will give you the x value, and a simple integer division will get you y, more or less)