public Point[] Pickup(INEQUALITY inequality, T thr) { Func <T, T, bool> judge; List <Point> buf = new List <Point>(); switch (inequality) { case INEQUALITY.LessThan: judge = (i, j) => i.CompareTo(j) < 0; break; case INEQUALITY.GreaterThan: judge = (i, j) => i.CompareTo(j) > 0; break; case INEQUALITY.LessThanOrEqual: judge = (i, j) => i.CompareTo(j) <= 0; break; case INEQUALITY.GreaterThanOrEqual: judge = (i, j) => i.CompareTo(j) >= 0; break; case INEQUALITY.Equal: judge = (i, j) => i.CompareTo(j) == 0; break; case INEQUALITY.NotEqual: judge = (i, j) => i.CompareTo(j) != 0; break; default: judge = (i, j) => false; break; } for (int i = 0; i < Size; i++) { if (judge(pixel[i], thr)) { buf.Add(new Point(i % Width, (int)(i / Width))); } } return(buf.ToArray()); }
public Point[] Pickup(T thrUpper, INEQUALITY inequalityUpper, INEQUALITY inequalityLower, T thrLower) { Func <T, T, bool> judgeU, judgeL; List <Point> buf = new List <Point>(); switch (inequalityUpper) { case INEQUALITY.LessThan: judgeU = (i, j) => i.CompareTo(j) > 0; break; case INEQUALITY.GreaterThan: judgeU = (i, j) => i.CompareTo(j) < 0; break; case INEQUALITY.LessThanOrEqual: judgeU = (i, j) => i.CompareTo(j) >= 0; break; case INEQUALITY.GreaterThanOrEqual: judgeU = (i, j) => i.CompareTo(j) <= 0; break; case INEQUALITY.Equal: judgeU = (i, j) => i.CompareTo(j) == 0; break; case INEQUALITY.NotEqual: judgeU = (i, j) => i.CompareTo(j) != 0; break; default: judgeU = (i, j) => false; break; } switch (inequalityLower) { case INEQUALITY.LessThan: judgeL = (i, j) => i.CompareTo(j) < 0; break; case INEQUALITY.GreaterThan: judgeL = (i, j) => i.CompareTo(j) > 0; break; case INEQUALITY.LessThanOrEqual: judgeL = (i, j) => i.CompareTo(j) <= 0; break; case INEQUALITY.GreaterThanOrEqual: judgeL = (i, j) => i.CompareTo(j) >= 0; break; case INEQUALITY.Equal: judgeL = (i, j) => i.CompareTo(j) == 0; break; case INEQUALITY.NotEqual: judgeL = (i, j) => i.CompareTo(j) != 0; break; default: judgeL = (i, j) => false; break; } for (int i = 0; i < Size; i++) { T buf_pix = pixel[i]; if (judgeU(buf_pix, thrUpper) && judgeL(buf_pix, thrLower)) { buf.Add(new Point(i % Width, (int)(i / Width))); } } return(buf.ToArray()); }
public int Count(INEQUALITY inequality, T thr) { int count = 0; //NaN処理入れる? //foreach (double i in pixel) //{ // if (double.IsNaN(i)) return -1; //} //fixed (double* p = &pixel[0]) Func <T, T, bool> judge; switch (inequality) { case INEQUALITY.LessThan: judge = (i, j) => i.CompareTo(j) < 0; break; case INEQUALITY.GreaterThan: judge = (i, j) => i.CompareTo(j) > 0; break; case INEQUALITY.LessThanOrEqual: judge = (i, j) => i.CompareTo(j) <= 0; break; case INEQUALITY.GreaterThanOrEqual: judge = (i, j) => i.CompareTo(j) >= 0; break; case INEQUALITY.Equal: judge = (i, j) => i.CompareTo(j) == 0; break; case INEQUALITY.NotEqual: judge = (i, j) => i.CompareTo(j) != 0; break; default: judge = (i, j) => false; break; } foreach (T p in pixel) { if (judge(p, thr)) { count++; } } return(count); }