private List<Fragment> GetFragments() { var list = new List<Fragment>(); int XCount = width / fragmentSize; int YCount = height / fragmentSize; for (int x = 0; x < XCount; ++x) { for (int y = 0; y < YCount; ++y) { Fragment fragment = new Fragment(x * fragmentSize, y * fragmentSize, fragmentSize, fragmentSize); list.Add(fragment); } } if (XCount * fragmentSize < width) { for (int y = 0; y < YCount; ++y) { Fragment fragment = new Fragment(width - fragmentSize, y * fragmentSize, fragmentSize, fragmentSize); list.Add(fragment); } } if (YCount * fragmentSize < height) { for (int x = 0; x < XCount; ++x) { Fragment fragment = new Fragment(x * fragmentSize, height - fragmentSize, fragmentSize, fragmentSize); list.Add(fragment); } } if ((XCount * fragmentSize < width) || (YCount * fragmentSize < height)) { Fragment fragment = new Fragment(width - fragmentSize, height - fragmentSize, fragmentSize, fragmentSize); list.Add(fragment); } return list; }
private LBPFeature GetLBPFeature(Fragment fragment) { int fromX = MathHelpers.Clamp(fragment.fromX, 2, width - 2); int toX = MathHelpers.Clamp(fromX + fragment.width, 2, width - 2); int fromY = MathHelpers.Clamp(fragment.fromY, 2, height - 2); int toY = MathHelpers.Clamp(fromY + fragment.height, 2, height - 2); double[] histogramm = new double[18]; int count = 0; for (int y = fromY; y < toY; ++y) { for (int x = fromX; x < toX; ++x) { var lbpValue = GetLBPValue(x, y); histogramm[GetHistogrammValue(lbpValue)] += 1; ++count; } } for (int i = 0; i < 18; ++i) { histogramm[i] /= count; } return new LBPFeature(histogramm); }
private bool IsInFragment(int x, int y, Fragment fragment) { return((x >= fragment.fromX) && (x < fragment.fromX + fragment.width) && (y >= fragment.fromY) && (y < fragment.fromY + fragment.height)); }
private double[] GetBestScalarPropertyFeature(Fragment fragment, int dx, int dy) { var glcmList = GetGLCMList(fragment, dx, dy); var result = new double[4]; for (int i = 0; i < glcmList.Count; ++i) { var scalar = GetScalarPropertyFeature(glcmList[i]); for (int j = 0; j < 4; ++j) { if (scalar[j] > result[j]) { result[j] = scalar[j]; } } } return result; }
private bool IsInFragment(int x, int y, Fragment fragment) { return (x >= fragment.fromX) && (x < fragment.fromX + fragment.width) && (y >= fragment.fromY) && (y < fragment.fromY + fragment.height); }
private List<double[, ]> GetGLCMList(Fragment fragment, int dx, int dy) { var result = new List<double[,]>(); int toX = fragment.fromX + fragment.width; int toY = fragment.fromY + fragment.height; for (int i = 1; i < RecognitionParameters.GLCMMaxDisplacementDistance; ++i) { var glcm = new double[RecognitionParameters.GLCMSize, RecognitionParameters.GLCMSize]; for (int y = fragment.fromY; y < toY; ++y) { for (int x = fragment.fromX; x < toX; ++x) { int nx = x + dx * i; int ny = y + dy * i; if (IsInFragment(nx, ny, fragment)) { int from = data[x, y]; int to = data[nx, ny]; glcm[from, to] += 1; } } } NormalizeGLCM(glcm, dx * i, dy * i); result.Add(glcm); } return result; }
private GLCMFeature GetGLCMFeature(Fragment fragment) { var glcm0feature = GetBestScalarPropertyFeature(fragment, 1, 0); var glcm45feature = GetBestScalarPropertyFeature(fragment, 1, 1); var glcm90feature = GetBestScalarPropertyFeature(fragment, 0, 1); var glcm135feature = GetBestScalarPropertyFeature(fragment, -1, 1); var bigfeature = new double[16]; for (int i = 0; i < 4; ++i) { bigfeature[i * 4] = glcm0feature[i]; bigfeature[i * 4 + 1] = glcm45feature[i]; bigfeature[i * 4 + 2] = glcm90feature[i]; bigfeature[i * 4 + 3] = glcm135feature[i]; } return new GLCMFeature(bigfeature); }