この配列から 4095 より大きい値を除外してカウントするにはどうすればよいですか? ( http://s7.directupload.net/images/131007/uitb86ho.jpgの緑色のボックスを参照)。スクリーンショットには、441 ピクセルを含む赤いボックスがあり、これらの 441 ピクセルの平均値は 1198 mm で、x;y 15;463 の深さはわずか約 614 mm です。if 条件 (d < 4095) で除外されているはずなので、より大きな平均値がどこから来るのかわかりません。
protected void imageIR_MouseClick(object sender, System.Windows.Input.MouseEventArgs e)
{
// Get the x and y coordinates of the mouse pointer.
System.Windows.Point mousePoint = e.GetPosition(imageIR);
double xpos_IR = mousePoint.X;
double ypos_IR = mousePoint.Y;
int x = (int)xpos_IR;
int y = (int)ypos_IR;
lbCoord.Content = "x- & y- Koordinate [pixel]: " + x + " ; " + y;
int d = (ushort)pixelData[x + y * this.depthFrame.Width];
d = d >> 3;
int xpos_Content = (int)((x - 320) * 0.03501 / 2 * d/10);
int ypos_Content = (int)((240 - y) * 0.03501 / 2 * d/10);
xpos.Content = "x- Koordinate [mm]: " + xpos_Content;
ypos.Content = "y- Koordinate [mm]: " + ypos_Content;
zpos.Content = "z- Koordinate [mm]: " + (d);
// Calculate the average value of array element
int sum = 0;
int i;
i = Convert.ToInt32(gr_ordnung.Text);
i = int.Parse(gr_ordnung.Text);
int m;
int n;
int d_mw = 0;
int count = 0;
for (m = x - i; m <= x + i; m++)
{
for (n = y - i; n <= y + i; n++)
{
int d_array = (ushort)pixelData[m + n * this.depthFrame.Width];
d_array = d_array >> 3;
// With condition that if one of those values is more than 4095:
if (d_array <= 4095)
{
sum += d_array;
count++;
d_mw = sum / count;
}
tiefen_mw.Content = "Tiefen-MW [mm]: " + d_mw;
}
}
}
したがって、「if」条件は、m = xi から m = x+i および n = yi から n = y+i までのd_array (私の場合は 100 ピクセル) が 4095 未満である場合、「通常」を実行することを意味します。 ' 平均は、すべての値の合計を要素の総数で割ったものです。
「else」条件は、4095 を超えるd_array値がある場合、0 として宣言する必要があり、平均にはカウントされないことを意味します。構文を正しく記述しましたか?