2011-10-13 44 views
0

需要一些幫助。我有一些顏色的反射值,需要將它們轉換爲L * a * b * C * h值。將彩色反射數據轉換爲L A B C和H值

我已經找到了一些聲稱做到這一點的視覺基本來源,但我沒有Visual Basic的知識將它轉換爲C sharp。

任何人都可以提供幫助嗎?

http://www.vbforums.com/showthread.php?p=821074

樣本數據 反射率值:0.35380,0.44130,0.50230,0.51650,0.52210,0.52780,0.53110,0.53350,0.53630,0.53900,0.54130,0.54330,0.54500,0.54630,0.54690,0.54680,0.54640,0.54710 ,0.54940,0.55240,0.55330,0.55250,0.55200,0.55190,0.55220,0.55310,0.55260,0.55340,0.55500,0.55540,0.55400

+0

嗨丹尼爾,可悲的沒有太多,因爲沒有太多的東西,我知道頁面上的VB代碼顯示的作品,但我有麻煩翻譯它:( – Neo

回答

1

我已經設法回答我自己的問題!

double[] d65Vals_X = new double[31] { 0.137, 0.676, 1.603, 2.451, 3.418, 3.699, 3.064, 1.933, 0.802, 0.156, 0.039, 0.347, 1.070, 2.170, 3.397, 4.732, 6.070, 7.311, 8.291, 8.634, 8.672, 7.930, 6.446, 4.669, 3.095, 1.859, 1.056, 0.570, 0.274, .0121, 0.058 }; 
     double[] d65Vals_Y = new double[31] { 0.014, 0.069, 0.168, 0.300, 0.554, 0.890, 1.290, 1.838, 2.520, 3.226, 4.320, 5.621, 6.907, 8.059, 8.668, 8.855, 8.581, 7.951, 7.106, 6.004, 5.079, 4.065, 2.999, 2.042, 1.290, 0.746, 0.417, 0.223, 0.107, 0.047, 0.023 }; 
     double[] d65Vals_Z = new double[31] { 0.612, 3.110, 7.627, 12.095, 17.537, 19.888, 17.695, 13.000, 7.699, 3.938, 2.046, 1.049, 0.544, 0.278, 0.122, 0.035, 0.001, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000, 0.000 }; 

     private double FXYZ(double[] REF, int A){ 
      double XYZref = 0; 
      double illXYZ = 0; 
      int i; 

      for (i = 0; i < 31; i++) 
      { 
       if (A == 0){ 
        XYZref = XYZref + (REF[i] * d65Vals_X[i]); 
        illXYZ = illXYZ + d65Vals_X[i]; 
       } else if (A == 1){ 
        XYZref = XYZref + (REF[i] * d65Vals_Y[i]); 
        illXYZ = illXYZ + d65Vals_Y[i]; 
       } else { 
        XYZref = XYZref + (REF[i] * d65Vals_Z[i]); 
        illXYZ = illXYZ + d65Vals_Z[i]; 
       }     
      } 
      return (XYZref/(100 * illXYZ)); 
     } 
     private void btnCalculate_Click(object sender, EventArgs e) 
     { 
      int i; 

      double L, A, B; 

      double[] reflexVals = new double[31]; 
      Console.Write("Reflex Data: "); 
      for (i = 0; i < 31; i++) 
      { 
       TextBox reflex = this.Controls["txtReflex_" + (i + 1)] as TextBox;     
       reflexVals[i] = double.Parse(reflex.Text); 
       Console.Write(reflexVals[i].ToString() + ", "); 
      } 
      Console.Write("\n"); 

      double[] FFXYZ = new double[3]; 
      double[] XYZ = new double[3]; 
      double CR = (1/3); 
      CR = 0.33333333333333333333333333333333; 
      for (i = 0; i < 3; i++) 
      { 
       XYZ[i] = FXYZ(reflexVals, i); 
       Console.WriteLine("XYZ[" + i + "] = " + XYZ[i]); 
       if (XYZ[i] > 0.008856) 
       { 

        FFXYZ[i] = Math.Pow(XYZ[i], CR); 
        Console.WriteLine("FFXYZ[" + i + "] = " + Math.Pow(XYZ[i], CR)); 
       } 
       else 
       { 
        FFXYZ[i] = (7.787 * XYZ[i]) + (16/116); 
        Console.WriteLine("FFXYZ[" + i + "] = (7.787 * " + XYZ[i] + ") + (16/116)"); 
       } 
      } 

      if (XYZ[1] > 0.00856) 
      { 
       L = (116 * FFXYZ[1]) - 16; 
       Console.WriteLine("L = (116 * " + FFXYZ[1] + ") - 16"); 
      } 
      else 
      { 
       L = 903.3 * XYZ[1]; 
       Console.WriteLine("L = 903.3 * " + XYZ[1] + ")"); 
      } 

      A = 500 * (FFXYZ[0] - FFXYZ[1]); 
      B = 200 * (FFXYZ[1] - FFXYZ[2]); 

      Console.WriteLine("A = 500 * (" + FFXYZ[0] + " - " + FFXYZ[1] + ")"); 
      Console.WriteLine("A = 200 * (" + FFXYZ[1] + " - " + FFXYZ[2] + ")"); 

      txtCalcL.Text = L.ToString(); 
      txtCalcA.Text = A.ToString(); 
      txtCalcB.Text = B.ToString(); 
     } 
相關問題