c# - Excluding value from array & Counting it -


how exclude , count values bigger 4095 array: edit: final code have, works on mousepoints, there exceptions difference between depth , neighbouring values big (see green marked box on http://s7.directupload.net/images/131007/uitb86ho.jpg). in screenshot there red box, contains 441 pixels, , average value of 441 pixels 1198 mm, depth on x;y 15;463 614 mm. have no idea bigger average values come from, since should have been excluded if-condition (d < 4095).

    protected void imageir_mouseclick(object sender, system.windows.input.mouseeventargs e)     {         // x , y coordinates of 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 average value of array element         int sum = 0;         int i;         = convert.toint32(gr_ordnung.text);         = int.parse(gr_ordnung.text);         int m;         int n;         int d_mw = 0;         int count = 0;          (m = x - i; m <= x + i; m++)         {             (n = y - i; n <= y + i; n++)             {                 int d_array = (ushort)pixeldata[m + n * this.depthframe.width];                 d_array = d_array >> 3;                  // condition if 1 of values more 4095:                 if (d_array <= 4095)                 {                     sum += d_array;                     count++;                     d_mw = sum / count;                 }                  tiefen_mw.content = "tiefen-mw [mm]: " + d_mw;             }         }     } 

so, 'if' condition means if have d_array (in case 100 pixels) m = x-i m = x+i , n = y-i n = y+i less 4095 'normal' calculation average sum of values divided number of total elements.

now 'else' condition means: if have d_array value more 4095, should declared 0 , doesn't count in average. did write syntax correctly?

you use linq quite easily:

using system.linq; ... int[] values = new int[10]; // fill array ... int[] usefulvalues = values.where(i => <= 4095).toarray(); int numberofuselessvalues = values.length - usefulvalues.length; 

update >>>

try instead:

int count_useful = 0; // <<< important initialise here  (m = x - i; m <= x + i; m++) {     (n = y - i; n <= y + i; n++)     {         int d_array = (ushort)pixeldata[m + n * this.depthframe.width];         d_array = d_array >> 3;          if (d_array <= 4095)          {             sum += d_array;             count_useful++;         }     } }  d_mw = sum / count_useful; // <<< perform these sums outside of loop tiefen_mw.content = "tiefen-mw [mm]: " + d_mw; 

Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -