public double Overlap(ColorAssignment other) { double score = 0; //score the two palettes if (colors.Keys.SequenceEqual <String>(other.colors.Keys)) { foreach (String key in colors.Keys) { if (other.colors[key] == this.colors[key]) { score += 1; } } score /= colors.Keys.Count(); } else { //something is wrong Console.WriteLine("The two palettes are not compatible"); throw new ArgumentException(); } return(score); }
public Bitmap RenderAssignment(ColorAssignment assignment) { int numMembers = assignment.Keys.Count(); int colorSize = 20; int padding = 2; int textWidth = 120; int topPadding = 10; Bitmap result = new Bitmap(textWidth + colorSize + padding, numMembers * colorSize + padding + topPadding); Graphics pg = Graphics.FromImage(result); pg.FillRectangle(new SolidBrush(Color.White), 0, 0, result.Width, result.Height); Brush black = new SolidBrush(Color.Black); Font headers = new Font("Arial", 9); //write out the concept titles for (int w = 0; w < numMembers; w++) { pg.DrawString(assignment.Keys[w], headers, black, 0, w * colorSize + topPadding); } //draw the assigned colors for (int w = 0; w < assignment.Keys.Count(); w++) { int x = textWidth; int y = w * colorSize + topPadding; pg.FillRectangle(new SolidBrush(assignment.Get(assignment.Keys[w])), x, y, colorSize - padding, colorSize - padding); } return(result); }
public ColorAssignment AssignColors(Category category) { //check that number of category members is less than number of palette colors if (category.members.Count() > paletteHex.Count()) { throw new ArgumentException("Too many category members, or not enough palette colors!"); } //Get the images, if needed SearchImages(category, 3); //Compute the histograms ComputeHistograms(category); //Compute affinities and assign colors double[,] affinities = ComputeAffinities(category); //Since the Hungarian Algorithm minimizes sum of affinities, let's invert the affinities //Assume that the number of category members is less than the number of palette colors double[,] matrix = new double[paletteHex.Count(), paletteHex.Count()]; for (int c = 0; c < paletteHex.Count(); c++) { for (int w = 0; w < category.members.Count(); w++) { matrix[w, c] = 1 - affinities[c, w]; } } //create an assignment from colors to concept names List <int> assignIds = HungarianAlgorithm.Solve(matrix); ColorAssignment assignment = new ColorAssignment(category); for (int w = 0; w < category.members.Count(); w++) { assignment.Set(category.members[w], paletteRGB[assignIds[w]]); } return(assignment); }
public double Overlap(ColorAssignment other) { double score = 0; //score the two palettes if (colors.Keys.SequenceEqual<String>(other.colors.Keys)) { foreach (String key in colors.Keys) { if (other.colors[key] == this.colors[key]) score += 1; } score /= colors.Keys.Count(); } else { //something is wrong Console.WriteLine("The two palettes are not compatible"); throw new ArgumentException(); } return score; }
public Bitmap RenderAssignment(ColorAssignment assignment) { int numMembers = assignment.Keys.Count(); int colorSize = 20; int padding = 2; int textWidth = 120; int topPadding = 10; Bitmap result = new Bitmap(textWidth + colorSize+padding, numMembers * colorSize + padding+topPadding); Graphics pg = Graphics.FromImage(result); pg.FillRectangle(new SolidBrush(Color.White), 0, 0, result.Width, result.Height); Brush black = new SolidBrush(Color.Black); Font headers = new Font("Arial", 9); //write out the concept titles for (int w = 0; w < numMembers; w++) { pg.DrawString(assignment.Keys[w], headers, black, 0, w * colorSize+topPadding); } //draw the assigned colors for (int w = 0; w < assignment.Keys.Count(); w++) { int x = textWidth; int y = w * colorSize+topPadding; pg.FillRectangle(new SolidBrush(assignment.Get(assignment.Keys[w])), x, y, colorSize - padding, colorSize - padding); } return result; }
public ColorAssignment AssignColors(Category category) { //check that number of category members is less than number of palette colors if (category.members.Count() > paletteHex.Count()) throw new ArgumentException("Too many category members, or not enough palette colors!"); //Get the images, if needed SearchImages(category, 3); //Compute the histograms ComputeHistograms(category); //Compute affinities and assign colors double[,] affinities = ComputeAffinities(category); //Since the Hungarian Algorithm minimizes sum of affinities, let's invert the affinities //Assume that the number of category members is less than the number of palette colors double[,] matrix = new double[paletteHex.Count(), paletteHex.Count()]; for (int c=0; c<paletteHex.Count(); c++) for (int w=0; w<category.members.Count(); w++) matrix[w,c] = 1-affinities[c,w]; //create an assignment from colors to concept names List<int> assignIds = HungarianAlgorithm.Solve(matrix); ColorAssignment assignment = new ColorAssignment(category); for (int w = 0; w < category.members.Count(); w++) { assignment.Set(category.members[w], paletteRGB[assignIds[w]]); } return assignment; }