public double Variance(double mean, ColorPlane plane) { int H = pixels.GetLength(0); int W = pixels.GetLength(1); double var = 0.0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { switch (plane) { case ColorPlane.eBlue: var += Math.Pow(pixels[i, j].B - mean, 2); break; case ColorPlane.eRed: var += Math.Pow(pixels[i, j].R - mean, 2); break; case ColorPlane.eGreen: var += Math.Pow(pixels[i, j].G - mean, 2); break; } } } return(var / pixels.Length); }
public double Mean(ColorPlane plane) { int H = pixels.GetLength(0); int W = pixels.GetLength(1); double mean = 0.0; for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { switch (plane) { case ColorPlane.eBlue: mean += pixels[i, j].B; break; case ColorPlane.eRed: mean += pixels[i, j].R; break; case ColorPlane.eGreen: mean += pixels[i, j].G; break; } } } return(mean / pixels.Length); }
public AdvColor(AdvColor color, ColorPlane color_plane) { alpha = color.A; red = color.R; blue = color.B; green = color.G; plane = color_plane; }
public AdvColor(int _red, int _green, int _blue, ColorPlane _plane) { red = _red; blue = _blue; green = _green; alpha = 255; plane = _plane; }
private static string CloseNestedPastelStrings(string input, Color color, ColorPlane colorPlane) { var closedString = _closeNestedPastelStringRegex1.Replace(input, _formatStringEnd); closedString = _closeNestedPastelStringRegex2.Replace(closedString, $"{_formatStringEnd}$1"); closedString = _closeNestedPastelStringRegex3[colorPlane].Replace(closedString, $"$1{string.Format($"{_formatStringStart}{_formatStringColor}", _planeFormatModifiers[colorPlane], color.R, color.G, color.B)}"); return closedString; }
private static bool[,] CreateOptimizedFaces(ColorPlanePos pos, ColorPlane plane) { plane.vertices = new List <Vector3>(); plane.triangles = new List <int>(); int count = 0; bool[,] matrix = new bool[plane.sizeX, plane.sizeY]; foreach (VOXPos dot in plane.dots) { matrix[dot.x - plane.minX, dot.y - plane.minY] = true; count++; } SplitToRects(matrix, pos, plane, count); return(matrix); }
public RGBImage(String image, ColorPlane plane) { //load the pixels directly from the image Bitmap img = new Bitmap(image); pixels = new AdvColor[img.Height, img.Width]; //walk image and load pixels for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { AdvColor clr = new AdvColor(img.GetPixel(j, i), plane); pixels[i, j] = clr;// new AdvColor(img.GetPixel(j, i), plane); } } }
private static ColorPlane GetColorPlaneFor(Dictionary <ColorPlanePos, ColorPlane> planes, int pos, byte matID, Vector3 normal) { ColorPlanePos planePos; planePos.pos = pos; planePos.matID = matID; planePos.normal = normal; if (planes.ContainsKey(planePos)) { return(planes[planePos]); } ColorPlane plane = new ColorPlane(pos, matID, normal); planes[planePos] = plane; return(plane); }
public int GetColor(ColorPlane plane) { switch (plane) { case ColorPlane.eBlue: return(B); case ColorPlane.eRed: return(R); case ColorPlane.eGreen: return(G); case ColorPlane.eAll: return(A); } return(0); }
public Histogram(AdvColor[,] pixels, ColorPlane plane) { histogram = new SortedDictionary <AdvColor, int>(); for (int i = 0; i < pixels.GetLength(0); i++) { for (int j = 0; j < pixels.GetLength(1); j++) { AdvColor val = new AdvColor(pixels[i, j], plane); if (histogram.ContainsKey(val)) { histogram[val] = histogram[val] + 1; } else { histogram[val] = 1; } } } }
public int Min(ColorPlane plane) { int min = 255; int H = pixels.GetLength(0); int W = pixels.GetLength(1); for (int i = 0; i < H; i++) { for (int j = 0; j < W; j++) { switch (plane) { case ColorPlane.eBlue: if (min > pixels[i, j].B) { min = pixels[i, j].B; } break; case ColorPlane.eRed: if (min > pixels[i, j].R) { min = pixels[i, j].R; } break; case ColorPlane.eGreen: if (min > pixels[i, j].G) { min = pixels[i, j].G; } break; } } } return(min); }
public AdvColor[,] Binzarization(double value, ColorPlane plane, AdvColor[,] source) { AdvColor[,] new_pixels = new AdvColor[pixels.GetLength(0), pixels.GetLength(1)]; for (int i = 0; i < source.GetLength(0); i++) { for (int j = 0; j < source.GetLength(1); j++) { int val = source[i, j].GetColor(plane); if (val < value) { val = 0; } else { val = pixels[i, j].GetColor(plane); } new_pixels[i, j] = new AdvColor(val, val, val, plane); } } return(new_pixels); }
public AdvColor[,] HistogramStretch(double low_percentage, double high_percentance, ColorPlane plane) { Histogram histogram = BuildHistogram(); //low bins to 0 out int low_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(GetHeight() * GetWidth() * low_percentage)); AdvColor low_color = histogram.GetBinColor(low_bins); int high_bins = histogram.GetNumBinsWithItems(Convert.ToInt32(GetHeight() * GetWidth() * high_percentance)); AdvColor high_color = histogram.GetBinColor(high_bins); return(HistogramStretch(low_color, high_color, histogram, ColorPlane.eGreen)); }
public AdvColor[,] HistogramStretch(AdvColor low, AdvColor high, Histogram histogram, ColorPlane plane) { int height = GetHeight(); int width = GetWidth(); AdvColor[,] new_pixels = new AdvColor[height, width]; int low_color = low.GetColor(plane); int high_color = high.GetColor(plane); for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int val = Convert.ToInt32((pixels[i, j].GetColor(plane) - low_color) * (255.0 / (high_color - low_color))); if (val < 0) { val = 0; } if (val > 255) { val = 255; } new_pixels[i, j] = new AdvColor(val, val, val, plane); } } return(new_pixels); }
public double StdDev(ColorPlane plane) { double var = Variance(Mean(plane), plane); return(Math.Sqrt(var)); }
private static void SplitToRects(bool[,] matrix, ColorPlanePos pos, ColorPlane plane, int count) { int[,] h, w; h = new int[plane.sizeX, plane.sizeY]; w = new int[plane.sizeX, plane.sizeY]; while (count > 0) { int minw = 0, area = 0; int maxArea = 0; int[] maxFace = new int[4] { 0, 0, 0, 0 }; for (int j = 0; j < plane.sizeX; j++) { for (int i = 0; i < plane.sizeY; i++) { if (!matrix[j, i]) { continue; } if (j == 0) { h[j, i] = 1; } else { h[j, i] = h[j - 1, i] + 1; } if (i == 0) { w[j, i] = 1; } else { w[j, i] = w[j, i - 1] + 1; } minw = w[j, i]; for (int dh = 0; dh < h[j, i]; dh++) { if (w[j - dh, i] < minw) { minw = w[j - dh, i]; } area = (dh + 1) * minw; if (area > maxArea) { maxArea = area; maxFace[0] = i - minw + 1; maxFace[1] = j - dh; maxFace[2] = i; maxFace[3] = j; } } } } // add faces int vi = allVertices.Count; bool order = true; // TODO: add minX, minY if (pos.normal.y == -1) { allVertices.Add(new Vector3(maxFace[1], pos.pos + 1, maxFace[0])); allVertices.Add(new Vector3(maxFace[3] + 1, pos.pos + 1, maxFace[0])); allVertices.Add(new Vector3(maxFace[3] + 1, pos.pos + 1, maxFace[2] + 1)); allVertices.Add(new Vector3(maxFace[1], pos.pos + 1, maxFace[2] + 1)); float x1 = maxFace[1]; float x2 = maxFace[3] + 1; float y1 = maxFace[0]; float y2 = maxFace[2] + 1; x1 /= model.sizeX; x2 /= model.sizeX; y1 /= model.sizeY; y2 /= model.sizeY; allUVs.Add(new Vector2(x2, y1)); allUVs.Add(new Vector2(x1, y1)); allUVs.Add(new Vector2(x1, y2)); allUVs.Add(new Vector2(x2, y2)); } else if (pos.normal.y == 1) { allVertices.Add(new Vector3(maxFace[1], pos.pos, maxFace[0])); allVertices.Add(new Vector3(maxFace[3] + 1, pos.pos, maxFace[0])); allVertices.Add(new Vector3(maxFace[3] + 1, pos.pos, maxFace[2] + 1)); allVertices.Add(new Vector3(maxFace[1], pos.pos, maxFace[2] + 1)); order = false; } else if (pos.normal.z == -1) { allVertices.Add(new Vector3(maxFace[1], maxFace[0], pos.pos)); allVertices.Add(new Vector3(maxFace[3] + 1, maxFace[0], pos.pos)); allVertices.Add(new Vector3(maxFace[3] + 1, maxFace[2] + 1, pos.pos)); allVertices.Add(new Vector3(maxFace[1], maxFace[2] + 1, pos.pos)); } else if (pos.normal.z == 1) { allVertices.Add(new Vector3(maxFace[1], maxFace[0], pos.pos + 1)); allVertices.Add(new Vector3(maxFace[3] + 1, maxFace[0], pos.pos + 1)); allVertices.Add(new Vector3(maxFace[3] + 1, maxFace[2] + 1, pos.pos + 1)); allVertices.Add(new Vector3(maxFace[1], maxFace[2] + 1, pos.pos + 1)); order = false; } else if (pos.normal.x == -1) { allVertices.Add(new Vector3(pos.pos, maxFace[0], maxFace[1])); allVertices.Add(new Vector3(pos.pos, maxFace[0], maxFace[3] + 1)); allVertices.Add(new Vector3(pos.pos, maxFace[2] + 1, maxFace[3] + 1)); allVertices.Add(new Vector3(pos.pos, maxFace[2] + 1, maxFace[1])); order = false; } else if (pos.normal.x == 1) { allVertices.Add(new Vector3(pos.pos + 1, maxFace[0], maxFace[1])); allVertices.Add(new Vector3(pos.pos + 1, maxFace[0], maxFace[3] + 1)); allVertices.Add(new Vector3(pos.pos + 1, maxFace[2] + 1, maxFace[3] + 1)); allVertices.Add(new Vector3(pos.pos + 1, maxFace[2] + 1, maxFace[1])); } if (pos.normal.y != -1) { allUVs.Add(new Vector2(1, 0)); allUVs.Add(new Vector2(0, 0)); allUVs.Add(new Vector2(0, 1)); allUVs.Add(new Vector2(1, 1)); } List <int> list = null; if (!allTriangles.ContainsKey(pos.matID)) { list = allTriangles[pos.matID] = new List <int>(); } else { list = allTriangles[pos.matID]; } if (order) { list.Add(vi); list.Add(vi + 2); list.Add(vi + 1); list.Add(vi + 2); list.Add(vi); list.Add(vi + 3); } else { list.Add(vi); list.Add(vi + 1); list.Add(vi + 2); list.Add(vi + 2); list.Add(vi + 3); list.Add(vi); } for (int j = maxFace[1]; j <= maxFace[3]; j++) { for (int i = maxFace[0]; i <= maxFace[2]; i++) { matrix[j, i] = false; count--; } } for (int j = 0; j < plane.sizeX; j++) { for (int i = 0; i < plane.sizeY; i++) { w[j, i] = 0; h[j, i] = 0; } } } }