如何在以下代码中获取差异值

how to get the difference value in the following code

我有以下代码:

Double[] colorED = new Double[75];
Double[,] ColorEd = new Double[10, 10];
for (int i2 = 0; i2 < (colorfeature3.Count()) / color_no; i2++)
  {
      int cj = 0;
      for (int i3 = 0; i3 < 10; i3++)
   {
ColorEd[ci,cj]= (Math.Abs(colorfeature3[i2 * color_no + i3].GetHue()- colorarray[i3].GetHue()) + Math.Abs(colorfeature3[i2 * color_no + i3].GetSaturation() - colorarray[i3].GetSaturation()) +Math.Abs (colorfeature3[i2 * color_no + i3].GetBrightness() - colorarray[i3].GetBrightness()));
   } 
  }

我想要的是得到 colorarray 的每个元素(包含 10 个元素)和 colorfeature3 的 10 个元素(该数组包含 750 个元素,每个 10 个元素彼此分开,因为它代表一个数据集中图像的特征)并将差值保存到 10*10 数组,然后获取每一行的最小值并将其保存到列表

有人可以帮忙吗?

首先你需要定义"nearest color"是什么意思。这是一个可能有用的答案:Find nearest RGB value using color palette array in C.

public int Closeness(int c1, int c2)
{
    // Example algorithm
    int r1 = c1 / 0x010000 - c2 / 0x010000;
    int g1 = (c1 % 0x010000) / 0x00100 - (c2 % 0x010000) / 0x00100;
    int b1 = c1 % 0x000100 - c2 % 0x000100;
    return r1 * r1 + g1 * g1 + b1 * b1;
}

其次,您需要创建一个排序函数,使用此 "nearness" 算法在您的主颜色列表中找到最接近的颜色。

 public int FindClosestIndex(List<int> master, int color)
{
    var idx = -1;
    var idxCloseness = int.MaxValue;
    for (var i = 0; i < master.Count; i++)
    {
        var closeness = Closeness(master[i], color);
        if (closeness < idxCloseness)
        {
            idx = i;
            idxCloseness = closeness;
        }
    }
    return idxCloseness;
}

public int SortColorByMasterList(List<int> masterOrder, int a, int b)
{
    return FindClosestIndex(masterOrder, a).CompareTo(FindClosestIndex(masterOrder, b));
}

然后你像这样使用它:

myList.Sort((a,b) => SortColorByMasterList(masterOrder, a, b));