public void createMatrix() { int N = 159; similarityMatrix = new double[N, N]; Quantize q = new Quantize(); for (int index1 = 0; index1 < N; index1++) { for (int index2 = 0; index2 < N; index2++) { LUVClass luv1 = q.getLUVfromIndex(index1); LUVClass luv2 = q.getLUVfromIndex(index2); double distance = getEuclideanDistance(luv1, luv2); if (distance > tColor) { similarityMatrix[index1, index2] = 0; } else { similarityMatrix[index1, index2] = 1 - distance / tColor; } } } //return similarityMatrix; }
private void checkNeighbors(LUVClass[,] luvMatrix, int luvIndex, int x, int y) { Quantize q = new Quantize(); if (q.IndexOf(luvMatrix[x, y].L, luvMatrix[x, y].u, luvMatrix[x, y].v) == luvIndex) { coherenceCounter++; marked[x, y] = true; if (x + 1 < this.width - 1 && !marked[x + 1, y]) { checkNeighbors(luvMatrix, luvIndex, x + 1, y); } if (y + 1 < this.height - 1 && !marked[x, y + 1]) { checkNeighbors(luvMatrix, luvIndex, x, y + 1); } } }
public Dictionary <int, float> quantizeColors(Dictionary <LUVClass, float> histogram, int imgDimensions) { Dictionary <int, float> normalizedHist = new Dictionary <int, float>(); Quantize q = new Quantize(); foreach (LUVClass luv in histogram.Keys) { int luvIndex = q.IndexOf(luv.L, luv.u, luv.v); if (normalizedHist.ContainsKey(luvIndex)) { normalizedHist[luvIndex] = normalizedHist[luvIndex] + histogram[luv]; } else { normalizedHist.Add(luvIndex, histogram[luv]); } } return(normalizedHist); }
private void initializeMaxDistance() { int N = 159; Quantize q = new Quantize(); double max = 0; for (int index1 = 0; index1 < N; index1++) { for (int index2 = 0; index2 < N; index2++) { LUVClass luv1 = q.getLUVfromIndex(index1); LUVClass luv2 = q.getLUVfromIndex(index2); double distance = getEuclideanDistance(luv1, luv2); if (distance > max) { max = distance; } } } dMax = max; tColor = p * dMax; }
private Dictionary <int, CoherenceUnit> checkCoherence(LUVClass[,] luvMatrix, int width, int height) { //Console.WriteLine("wh: " + width + "," + height); Dictionary <int, CoherenceUnit> ccv = new Dictionary <int, CoherenceUnit>(); Quantize q = new Quantize(); int T = Convert.ToInt32(width * height * 0.01); marked = new Boolean[width, height]; for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { marked[i, j] = false; } } for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (!marked[x, y]) { coherenceCounter = 0; float a = 0; float b = 0; int luvIndex = q.IndexOf(luvMatrix[x, y].L, luvMatrix[x, y].u, luvMatrix[x, y].v); checkNeighbors(luvMatrix, luvIndex, x, y); //Console.WriteLine("coherence: " + coherenceCounter); if (coherenceCounter >= T) { a += coherenceCounter; } else { b += coherenceCounter; } if (ccv.ContainsKey(luvIndex)) { ccv[luvIndex] = new CoherenceUnit( ccv[luvIndex].aCoherentValue + a, ccv[luvIndex].bIncoherentValue + b ); } else { ccv.Add(luvIndex, new CoherenceUnit(a, b)); } } } } //normalize Dictionary <int, CoherenceUnit> ccvNorm = new Dictionary <int, CoherenceUnit>(); int dim = width * height; foreach (KeyValuePair <int, CoherenceUnit> k in ccv) { CoherenceUnit c = new CoherenceUnit(ccv[k.Key].aCoherentValue / dim, ccv[k.Key].bIncoherentValue / dim); ccvNorm[k.Key] = c; } return(ccvNorm); }