/// <summary> /// Simple wrapper for Death Reckoning alhorithm /// </summary> /// <param name="inPixels">In pixels.</param> /// <param name="width">Width.</param> /// <param name="height">Height.</param> /// <param name="resultPixels">Result pixels.</param> /// <param name="vectorWidth">Vector width.</param> private static void ProcessDR(int[] inPixels, int width, int height, int[] resultPixels, int vectorWidth) { byte[] data = new byte[width * height]; for (int i = 0; i < data.Length; i++) { int pixel = inPixels[i]; if (((pixel >> 16) & 0xff) != 0) { data[i] = 0; } else { data[i] = 255; } } DeadReckoning dr = new DeadReckoning(data, width, height); float[] values = dr.Transform(255); for (int i = 0; i < values.Length; i++) { float nvalue = values[i] / vectorWidth; if (nvalue < -1.0f) { continue; } if (nvalue > 1.0f) { nvalue = 1.0f; } nvalue = nvalue * 0.5f + 0.5f; int ivalue = (int)(nvalue * 255.0f) & 0xff; resultPixels[i] = (int)((ivalue << 16) | (ivalue << 8) | (ivalue) | (ivalue << 24)); } }
public static float[] AnalyzeGrayscale(byte[] pixelData, int imageWidth, int imageHeight, int[][] closestPoints = null, bool extraPass = true, byte threshold = 0) { byte[] data = new byte[imageWidth * imageHeight]; for (int i = 0; i < data.Length; i++) { int pixel = pixelData[i]; if (pixel > threshold) { data[i] = 255; } else { data[i] = 0; } } DeadReckoning dr = new DeadReckoning(data, imageWidth, imageHeight); return(dr.Transform(float.MaxValue, closestPoints)); }