# 跟进：通过独特性对颜色进行“排序”

0

## 9 答案

``````XX XX XX
RR GG BB

00 00 00 = black
ff ff ff = white
ff 00 00 = red
00 ff 00 = green
00 00 ff = blue
``````

0

0

Do you mean that from a set of N colors, you need to pick M colors, where M < N, such that M is the best representation of the N colors in the M space?

0

1. Calculate the distance (ref your other post) from each color to all other colors
2. Sum the distances for each color, this gives you an indication for how far away this color is from all other colors in total
3. Order the list by distance, going down

0

``````public double colordistance(Color color0, Color color1) {
int c0 = color0.getRGB();
int c1 = color1.getRGB();
return distance(((c0>>16)&0xFF), ((c0>>8)&0xFF), (c0&0xFF), ((c1>>16)&0xFF), ((c1>>8)&0xFF), (c1&0xFF));
}

public double distance(int r1, int g1, int b1, int r2, int g2, int b2) {
int dr = (r1 - r2);
int dg = (g1 - g2);
int db = (b1 - b2);
return Math.sqrt(dr * dr + dg * dg + db * db);
}
``````

``````public void colordistancesort(Color[] candidateColors, Color[] indexColors) {
double current;

double distance[] = new double[candidateColors.length];
for (int j = 0; j < candidateColors.length; j++) {
distance[j] = -1;
for (int k = 0; k < indexColors.length; k++) {
current = colordistance(indexColors[k], candidateColors[j]);
if ((distance[j] == -1) || (current < distance[j])) {
distance[j] = current;
}
}
}

//just sorts.
for (int j = 0; j < candidateColors.length; j++) {
for (int k = j + 1; k < candidateColors.length; k++) {
if (distance[j] > distance[k]) {
double d = distance[k];
distance[k] = distance[j];
distance[j] = d;

Color m = candidateColors[k];
candidateColors[k] = candidateColors[j];
candidateColors[j] = m;
}
}
}
}
``````
0

1. Generate M random points in colour space
2. Calculate the distance between each point
3. Calculate repulsion vectors for each point that will move it away from all other points (using 1 / (distance ^ 2) as the magnitude of the vector)
4. Sum the repulsion vectors for each point
5. Update the position of each point according to the summed repulsion vectors
6. Constrain any out of bound coordinates (such as luminosity going negative or above one)
7. Repeat from step 2 until the points stabilise
8. For each point, select the nearest colour from the original set of N

0

0

N个最远距离的颜色可以被认为是三维（彩色）空间中的一组分布良好的点。如果您可以从 Halton序列生成它们，则任何前缀（前M种颜色）也会由分布良好的点组成。

0

1. 从两个列表开始。 CandidateColors，最初包含您独特的颜色和SortedColors，最初为空。
2. 选择任何颜色并将其从CandidateColors中移除并放入SortedColors中。这是第一种颜色，将是最常见的颜色，所以它是一个很好的选择颜色的应用程序。
3. CandidateColors中的每种颜色都会计算其总距离。总距离是从CandidateColor到SortedColors中每种颜色的距离的总和。
4. 从CandidateColors中移除距离最大的颜色并将其添加到SortedColors的结尾。
5. 如果CandidateColors不为空，请返回步骤3。

0