コード例 #1
0
        public static PerceptionLib.RGBValue XYZToRGB(CIEXYZ C1xyz, CIEXYZ C2xyz)
        {
            PerceptionLib.CIEXYZ C3XYZ = AddXYZ(C1xyz, C2xyz);

            PerceptionLib.RGBValue colorObject = PerceptionLib.Color.ToRBG(C3XYZ);

            return colorObject;
        }
コード例 #2
0
        public static PerceptionLib.Color XYZToLABLUV(CIEXYZ C1xyz, CIEXYZ C2xyz)
        {
            PerceptionLib.CIEXYZ C3XYZ = AddXYZ(C1xyz, C2xyz);

            PerceptionLib.Color colorObject = PerceptionLib.Color.ToLUV(C3XYZ);

            return(colorObject);
        }
コード例 #3
0
        public static PerceptionLib.RGBValue XYZToRGB(CIEXYZ C1xyz, CIEXYZ C2xyz)
        {
            PerceptionLib.CIEXYZ C3XYZ = AddXYZ(C1xyz, C2xyz);

            PerceptionLib.RGBValue colorObject = PerceptionLib.Color.ToRBG(C3XYZ);

            return(colorObject);
        }
コード例 #4
0
 public static PerceptionLib.CIEXYZ AddXYZ(CIEXYZ C1xyz, CIEXYZ C2xyz)
 {
     PerceptionLib.CIEXYZ C3XYZ = new PerceptionLib.CIEXYZ(0, 0, 0);
     C3XYZ.X = Convert.ToDouble(C1xyz.X.ToString()) + Convert.ToDouble(C2xyz.X.ToString());
     C3XYZ.Y = Convert.ToDouble(C1xyz.Y.ToString()) + Convert.ToDouble(C2xyz.Y.ToString());
     C3XYZ.Z = Convert.ToDouble(C1xyz.Z.ToString()) + Convert.ToDouble(C2xyz.Z.ToString());
     return(C3XYZ);
 }
コード例 #5
0
        public static PerceptionLib.Color XYZToLABLUV(CIEXYZ C1xyz,CIEXYZ C2xyz)
        {
            PerceptionLib.CIEXYZ C3XYZ = AddXYZ( C1xyz,  C2xyz);

            PerceptionLib.Color colorObject = PerceptionLib.Color.ToLUV(C3XYZ);

            return colorObject;
        }
コード例 #6
0
 public static PerceptionLib.CIEXYZ SubtractXYZ(CIEXYZ C1xyz, CIEXYZ C2xyz)
 {
     PerceptionLib.CIEXYZ C3XYZ = new PerceptionLib.CIEXYZ(0, 0, 0);
     C3XYZ.X = Math.Abs(Convert.ToDouble(C1xyz.X.ToString()) - Convert.ToDouble(C2xyz.X.ToString()));
     C3XYZ.Y = Math.Abs(Convert.ToDouble(C1xyz.Y.ToString()) - Convert.ToDouble(C2xyz.Y.ToString()));
     C3XYZ.Z = Math.Abs(Convert.ToDouble(C1xyz.Z.ToString()) - Convert.ToDouble(C2xyz.Z.ToString()));
     return(C3XYZ);
 }
コード例 #7
0
 public static PerceptionLib.CIEXYZ SubtractXYZ(CIEXYZ C1xyz, CIEXYZ C2xyz)
 {
     PerceptionLib.CIEXYZ C3XYZ = new PerceptionLib.CIEXYZ(0, 0, 0);
       C3XYZ.X = Math.Abs(Convert.ToDouble(C1xyz.X.ToString()) - Convert.ToDouble(C2xyz.X.ToString()));
       C3XYZ.Y = Math.Abs(Convert.ToDouble(C1xyz.Y.ToString()) - Convert.ToDouble(C2xyz.Y.ToString()));
       C3XYZ.Z = Math.Abs(Convert.ToDouble(C1xyz.Z.ToString()) - Convert.ToDouble(C2xyz.Z.ToString()));
       return C3XYZ;
 }
コード例 #8
0
 public static PerceptionLib.CIEXYZ AddXYZ(CIEXYZ C1xyz, CIEXYZ C2xyz)
 {
     PerceptionLib.CIEXYZ C3XYZ = new PerceptionLib.CIEXYZ(0, 0, 0);
     C3XYZ.X = Convert.ToDouble(C1xyz.X.ToString()) + Convert.ToDouble(C2xyz.X.ToString());
     C3XYZ.Y = Convert.ToDouble(C1xyz.Y.ToString()) + Convert.ToDouble(C2xyz.Y.ToString());
     C3XYZ.Z = Convert.ToDouble(C1xyz.Z.ToString()) + Convert.ToDouble(C2xyz.Z.ToString());
     return C3XYZ;
 }
コード例 #9
0
        public MainWindow()
        {
            InitializeComponent();
            PerceptionLib.CIEXYZ ColorToShowXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ BradXYZ = new CIEXYZ(0, 0, 0);

            ColorToShowXYZ.X = 0.003889613;
            ColorToShowXYZ.Y = 0.001555845;
            ColorToShowXYZ.Z = 0.020485292;

            ColorToShowXYZ = new PerceptionLib.CIEXYZ(0.041177778, 0.036633333, 0.020966667);
            PerceptionLib.CIEXYZ ColorToShowXYZ2 = new PerceptionLib.CIEXYZ(0.806205144, 0.775540661, 0.843191729);
            PerceptionLib.CIEXYZ ColorToShowXYZ3 = new PerceptionLib.CIEXYZ(0, 0, 0);

            ColorToShowXYZ3.X = ColorToShowXYZ.X + ColorToShowXYZ2.X;
            ColorToShowXYZ3.Y = ColorToShowXYZ.Y + ColorToShowXYZ2.Y;
            ColorToShowXYZ3.Z = ColorToShowXYZ.Z + ColorToShowXYZ2.Z;

            CIEXYZ screenBgWt = new CIEXYZ(0.724775, 0.759896, 0.727336);
            PerceptionLib.Color ColorToShow = PerceptionLib.Color.ToLAB(ColorToShowXYZ3, screenBgWt);

            BradXYZ = CATCalulation.bradford(ColorToShowXYZ);
        }
コード例 #10
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        /// <summary>
        /// Funtion to convert Lab To XYZ
        /// </summary>
        /// <param name="passedLAB"></param>
        /// <returns></returns>
        private static CIEXYZ LABToXYZ(Color passedLAB)
        {
            double X, Y, Z, xr, yr, zr, Xr, Yr, Zr, Fx, Fy, Fz;

              Fy = (double)((double)(passedLAB.LA + 16)) / 116;

              Fx = (double)((double)(passedLAB.A / 500)) + Fy;

              Fz = (double)Fy - ((double)(passedLAB.B / 200));

              xr = (Math.Pow(Fx, 3) > (0.008856)) ? Math.Pow(Fx, 3) : ((double)((double)(116 * Fx - 16) / 903.3));

              yr = (passedLAB.LA > (0.008856 * 903.3)) ? Math.Pow(Fy, 3) : ((double)(passedLAB.LA / 903.3));

              zr = (Math.Pow(Fz, 3) > (0.008856)) ? Math.Pow(Fz, 3) : ((double)((double)(116 * Fz - 16) / 903.3));

              //for D65
              Xr = 0.9504;

              Yr = 1;

              Zr = 1.0888;

              X = (double)xr * Xr;
              Y = (double)yr * Yr;
              Z = (double)zr * Zr;

              CIEXYZ xyz = new CIEXYZ(X, Y, Z);

              return xyz;
        }
コード例 #11
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        /// <summary>
        /// function to convert Yxy to XYZ
        /// </summary>
        /// <param name="passedYxy"></param>
        /// <returns></returns>
        public static CIEXYZ YxyToXYZ(Color passedYxy)
        {
            double X, Y, Z;

              if (passedYxy.Lv > 0)
              {
            X = (double)(passedYxy.x * passedYxy.Lv) / passedYxy.y;
            Y = (double)passedYxy.lv;
            Z = (double)((1 - passedYxy.x - passedYxy.y) * passedYxy.Lv) / passedYxy.y;
              }
              else
              {
            X = Y = Z = 0;
              }

              CIEXYZ xyz = new CIEXYZ(X, Y, Z);

              return xyz;
        }
コード例 #12
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        public static RGBValue ToRBG(CIEXYZ xyz)
        {
            double tempr, tempg, tempb;
              //CIEXYZ xyz = LUVToXYZ(PassedLUV);

              RGBValue rgb = new RGBValue();

              double[] Clinear = new double[3];
              double[] linear = new double[3];

              Clinear[0] = (xyz.X) * 3.2404542 - (xyz.Y) * 1.5371385 - (xyz.Z) * 0.4985314; // red
              Clinear[1] = -(xyz.X) * 0.9692660 + (xyz.Y) * 1.8760108 + (xyz.Z) * 0.0415560; // green
              Clinear[2] = (xyz.X) * 0.0556434 - (xyz.Y) * 0.2040259 + (xyz.Z) * 1.0572252; // blue

              //  if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055
              //else                     var_R = 12.92 * var_R
              //if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055
              //else                     var_G = 12.92 * var_G
              //if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055
              //else                     var_B = 12.92 * var_B

              if (Clinear[0] > 0.0031308)
              {
            Clinear[0] = 1.055 * Math.Pow(Clinear[0], (1 / (2.2))) - 0.055;
            rgb.gmt = 1;
              }
              else
              {
            Clinear[0] = 12.92 * Clinear[0];
            rgb.gmt = 0;
              }
              if (Clinear[1] > 0.0031308)
              {
            Clinear[1] = 1.055 * Math.Pow(Clinear[1], (1 / (2.2))) - 0.055;
            rgb.gmt = 1;
              }
              else
              {
            Clinear[1] = 12.92 * Clinear[1];
            rgb.gmt = 0;
              }
              if (Clinear[2] > 0.0031308)
              {
            Clinear[2] = 1.055 * Math.Pow(Clinear[2], (1 / (2.2))) - 0.055;
            rgb.gmt = 1;
              }
              else
              {
            Clinear[2] = 12.92 * Clinear[2];
            rgb.gmt = 0;
              }

              ////gamma companding
              //for (int i = 0; i < 3; i++)
              //{
              //    if (Clinear[i] <= 0.0031308)
              //    {
              //        linear[i] = Clinear[i] * 12.92;
              //    }

              //    else
              //    {
              //        linear[i] = (1.055 * Math.Pow(Clinear[i], (1.0 / 2.2))) - 0.055;
              //        //linear[i] = ( Math.Pow((Clinear[i]), (1.0 / 2.2)));

              //    }
              //}

              tempr = (Math.Round(Clinear[0] * 255));
              tempg = (Math.Round(Clinear[1] * 255));
              tempb = (Math.Round(Clinear[2] * 255));

              //if (tempr > 255 || tempg > 255 || tempb > 255)
              //  rgb.gmt = 1;
              //else
              //  rgb.gmt = 0;
              // make sure rgb is not over 255
              //if (tempr > 255)
              //{
              //    tempr = 255;
              //}
              //if (tempg > 255)
              //{
              //    tempg = 255;
              //}
              //if (tempb > 255)
              //{
              //    tempb = 255;
              //}
              //if (tempr < 0)
              //{
              //    tempr = 0;
              //}
              //if (tempg < 0)
              //{
              //    tempg = 0;
              //}
              //if (tempb < 0)
              //{
              //    tempb = 0;
              //}
              rgb.R = (byte)(tempr);
              rgb.G = (byte)(tempg);
              rgb.B = (byte)(tempb);
              return rgb;
        }
コード例 #13
0
        public static CIEXYZ StartMeasureXYZForPhone()
        {
            int time1 = 500;

            if (caputerIndex != 1)
            {
                System.Threading.Thread.Sleep(2350);
            }
            caputerIndex = 0;
            StringBuilder returnString = new StringBuilder(250);
            //measure
            string cMeasure = "MES,1\r\n";
            int    length   = cMeasure.Length;

            int r = CaptureEngine.write64_usb(0, cMeasure, 1, length);

            r = CaptureEngine.read64_usb(0, returnString, 1, 250);

            string waittime = returnString.ToString(5, 2);

            CIEXYZ xyz = new CIEXYZ(0, 0, 0);
            int    t   = Convert.ToInt32(waittime);

            t = t * 1000;
            t = t - 500;
            int temp = t;


            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //take the if out for any other than phone
            //
            if (t < 800)
            {
                System.Threading.Thread.Sleep(t);

                cMeasure = "MDR,3\r\n";
                length   = cMeasure.Length;

                r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
                r = CaptureEngine.read64_usb(0, returnString, 1, 250);

                string error = returnString.ToString(0, 4);

                while (error == "ER02")
                {
                    t = t + 300;
                    if (t < 800)
                    {
                        //System.Threading.Thread.Sleep(300);
                        cMeasure = "MDR,3\r\n";
                        length   = cMeasure.Length;

                        r     = CaptureEngine.write64_usb(0, cMeasure, 1, length);
                        r     = CaptureEngine.read64_usb(0, returnString, 1, 250);
                        error = returnString.ToString(0, 4);
                    }
                    else
                    {
                        int tMinus = Math.Abs(2750);
                        //System.Threading.Thread.Sleep(500);
                        xyz      = new CIEXYZ(0, 0, 0);
                        xyz.stdx = t;
                        xyz.stdy = 0;
                        xyz.stdz = 0;
                        break;
                    }
                }

                if (t < 800)
                {
                    string op = returnString.ToString();
                    string x  = returnString.ToString(27, 10);
                    string y  = returnString.ToString(39, 10);
                    string z  = returnString.ToString(51, 10);

                    double X = Convert.ToDouble(x) / 100;
                    double Y = Convert.ToDouble(y) / 100;
                    double Z = Convert.ToDouble(z) / 100;

                    xyz      = new CIEXYZ(X, Y, Z);
                    xyz.stdx = t;
                    xyz.stdy = 1;
                    xyz.stdz = 1;
                }
            }
            else
            {
                System.Threading.Thread.Sleep(500);

                xyz      = new CIEXYZ(-1, -1, -1);
                xyz.stdx = 0;
                xyz.stdy = 0;
                xyz.stdz = 0;
            }
            return(xyz);
        }
コード例 #14
0
        private void Btn_CSGammut_Click(object sender, RoutedEventArgs e)
        {
            ///add this sleep for phone

              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\color88ForPhone.txt");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\colorForPhone.txt");
             // PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\bin8000.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\bgcolor.csv");
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\binforL.csv");
              dtgrid_corrDisplay.IsEnabled = false;

              //Thread.Sleep(16500);
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;
              DataTable dt = new DataTable();
              DataTable new_dt = new DataTable();

              dt = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              //int connect = PerceptionLib.Cs200Connection.ConnectToCS200();
              //if not connected then connect will be 1

              BgNo = dt.Rows.Count;
              ThreadPool.QueueUserWorkItem(ignored =>
              {
            DateTime Start = DateTime.Now;

            {

              //for (int i = 1; i < dt.Rows.Count; i++)
              for (int i = 0; i < dt.Rows.Count; i++)
              {

            mainW.R = Convert.ToByte(dt.Rows[i][0].ToString());
            mainW.G = Convert.ToByte(dt.Rows[i][1].ToString());
            mainW.B = Convert.ToByte(dt.Rows[i][2].ToString());

            // converts rendered RGB to luv and displays the colour in to measure

            //NoArgDelegate fetcher = new NoArgDelegate(
            //        this.ColorCapturedUpdate);
            //Dispatcher.BeginInvoke();

            // Dispatcher.Invoke(new Action(() => ColorCapturedUpdate()));

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //take it out for any thing other than phone
            ColorCapturedUpdate();
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            colorMeasured = StartCapture1();
            //Dispatcher.Invoke(DispatcherPriority.Send, new Action(() => DisplayMeasuredValuesFromCs200()));

            //Thread.Sleep(500);
            //DisplayMeasuredValuesFromCs200();
            DifferenceCalculation();

            //bradcolor=
            // if (i > 0)

            // assignes the data to a the datatable
            dt.Rows[i][3] = colorToShow.L.ToString();
            dt.Rows[i][4] = colorToShow.U.ToString();
            dt.Rows[i][5] = colorToShow.V.ToString();
            dt.Rows[i][6] = colorToShow.UP.ToString();
            dt.Rows[i][7] = colorToShow.VP.ToString();
            dt.Rows[i][8] = ColorMeasured.L.ToString();
            dt.Rows[i][9] = ColorMeasured.U.ToString();
            dt.Rows[i][10] = ColorMeasured.V.ToString();
            dt.Rows[i][11] = ColorMeasured.UP.ToString();
            dt.Rows[i][12] = ColorMeasured.VP.ToString();
            //dt.Rows][13] = ColorDifference.L.ToString();
            //dt.Rows][14] = ColorDifference.U.ToString();
            //dt.Rows][15] = ColorDifference.V.ToString();

            ////

            dt.Rows[i][13] = colorToShow.LA.ToString();
            dt.Rows[i][14] = colorToShow.A.ToString();
            dt.Rows[i][15] = colorToShow.B.ToString();
            dt.Rows[i][16] = ColorMeasured.LA.ToString();
            dt.Rows[i][17] = ColorMeasured.A.ToString();
            dt.Rows[i][18] = ColorMeasured.B.ToString();

            //

            dt.Rows[i][19] = PerceptionLib.Color.ColorDistanceCal(colorToShow, ColorMeasured).ToString();
            dt.Rows[i][20] = PerceptionLib.Color.ColorDistanceCalAB(colorToShow, ColorMeasured).ToString();
            //
            dt.Rows[i][21] = ColorToShowXYZ.X.ToString();
            dt.Rows[i][22] = ColorToShowXYZ.Y.ToString();
            dt.Rows[i][23] = ColorToShowXYZ.Z.ToString();
            dt.Rows[i][24] = ColorMeasuredXYZ.X.ToString();
            dt.Rows[i][25] = ColorMeasuredXYZ.Y.ToString();
            dt.Rows[i][26] = ColorMeasuredXYZ.Z.ToString();

            dt.Rows[i][27] = MR.ToString();
            dt.Rows[i][28] = MG.ToString();
            dt.Rows[i][29] = MB.ToString();

            BradXYZ = Util.CATCalulation.bradford(ColorToShowXYZ);
            VonXYZ = Util.CATCalulation.VonKries(ColorToShowXYZ);
            ScalingXYZ = Util.CATCalulation.XYZScaling(ColorToShowXYZ);

            Bradcolor = PerceptionLib.Color.ToLUV(BradXYZ);
            Voncolor = PerceptionLib.Color.ToLUV(VonXYZ);
            Scalingcolor = PerceptionLib.Color.ToLUV(ScalingXYZ);

            bradRGB = PerceptionLib.Color.ToRBG(Bradcolor);
            VonRGB = PerceptionLib.Color.ToRBG(Voncolor);
            scalingRGB = PerceptionLib.Color.ToRBG(Scalingcolor);

            CalRGB = PerceptionLib.Color.ToRBG(ColorMeasuredXYZ);

            dt.Rows[i][30] = BradXYZ.X.ToString();
            dt.Rows[i][31] = BradXYZ.Y.ToString();
            dt.Rows[i][32] = BradXYZ.Z.ToString();
            dt.Rows[i][33] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Bradcolor).ToString();
            dt.Rows[i][34] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Bradcolor).ToString();

            dt.Rows[i][35] = VonXYZ.X.ToString();
            dt.Rows[i][36] = VonXYZ.Y.ToString();
            dt.Rows[i][37] = VonXYZ.Z.ToString();
            dt.Rows[i][38] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Voncolor).ToString();
            dt.Rows[i][39] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Voncolor).ToString();

            dt.Rows[i][40] = ScalingXYZ.X.ToString();
            dt.Rows[i][41] = ScalingXYZ.Y.ToString();
            dt.Rows[i][42] = ScalingXYZ.Z.ToString();
            dt.Rows[i][43] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Scalingcolor).ToString();
            dt.Rows[i][44] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Scalingcolor).ToString();

            dt.Rows[i][45] = bradRGB.R.ToString();
            dt.Rows[i][46] = bradRGB.G.ToString();
            dt.Rows[i][47] = bradRGB.B.ToString();

            dt.Rows[i][48] = VonRGB.R.ToString();
            dt.Rows[i][49] = VonRGB.G.ToString();
            dt.Rows[i][50] = VonRGB.B.ToString();

            dt.Rows[i][51] = scalingRGB.R.ToString();
            dt.Rows[i][52] = scalingRGB.G.ToString();
            dt.Rows[i][53] = scalingRGB.B.ToString();

            dt.Rows[i][54] = CalRGB.R.ToString();
            dt.Rows[i][55] = CalRGB.G.ToString();
            dt.Rows[i][56] = CalRGB.B.ToString();

            dt.Rows[i][57] = Bradcolor.UP.ToString();
            dt.Rows[i][58] = Bradcolor.VP.ToString();

            dt.Rows[i][59] = Voncolor.UP.ToString();
            dt.Rows[i][60] = Voncolor.VP.ToString();

            dt.Rows[i][61] = Scalingcolor.UP.ToString();
            dt.Rows[i][62] = Scalingcolor.VP.ToString();

            dt.Rows[i][63] = ColorMeasuredXYZ.stdx.ToString();
            dt.Rows[i][64] = ColorMeasuredXYZ.stdy.ToString();
            dt.Rows[i][65] = ColorMeasuredXYZ.stdz.ToString();

            //pairs.Clear();
            //pairs.Add(new MeasurementPair()
            //{
            //  ColorToShow = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][6].ToString()), VP = Convert.ToDouble(dt.Rows[i][7].ToString()) },
            //  ColorCaptured = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][11].ToString()), VP = Convert.ToDouble(dt.Rows[i][12].ToString()) },
            //  BradColor = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dataTable.Rows[i][57].ToString()), VP = Convert.ToDouble(dataTable.Rows[i][58].ToString()) },
            //  VonColor = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dataTable.Rows[i][59].ToString()), VP = Convert.ToDouble(dataTable.Rows[i][60].ToString()) },
            //  Scalingcolor = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dataTable.Rows[i][61].ToString()), VP = Convert.ToDouble(dataTable.Rows[i][62].ToString()) }

            //});
            //if (i == 9)
            //{
            Dispatcher.Invoke(new Action(() =>
            {
              dtgrid_corrDisplay.ItemsSource = dt.DefaultView;
              dtgrid_corrDisplay.Items.Refresh();

            }));
            //}

            //if (i == (dt.Rows.Count - 1))
            //{
            //  int disconnect = PerceptionLib.Cs200Connection.DisconnectCS200();
            //}
              }

              // System.Threading.Thread.Sleep(10000);
              // grid is populated with new datatable which has luv values
              Dispatcher.Invoke(new Action(() =>
              {
            dtgrid_corrDisplay.ItemsSource = dt.DefaultView;
            dtgrid_corrDisplay.Items.Refresh();
              }));

              //  to show all the pairs in cie graph
              pairs.Clear();

              //for (int i = 0; i < dt.Rows.Count; i++)
              //{
              //  pairs.Add(new MeasurementPair()
              //  {
              //    ColorToShow = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][6].ToString()), VP = Convert.ToDouble(dt.Rows[i][7].ToString()) },
              //    ColorCaptured = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][11].ToString()), VP = Convert.ToDouble(dt.Rows[i][12].ToString()) }
              //  });
              //}

            }
            time = DateTime.Now.Subtract(Start).ToString();
              });

              btn_ExportGrid.IsEnabled = true;

              dtgrid_corrDisplay.IsEnabled = true;
              dataTable = dt;
        }
コード例 #15
0
        private void Btn_ManualBinCalculator_Click(object sender, RoutedEventArgs e)
        {
            int connect = 0;
              ///add this sleep for phone
              int i = BinNo;
              if (i == 0)
              {
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\color88ForPhone.txt");
            //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\colorForPhone.txt");
            //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\bin8000.csv");
            dtgrid_corrDisplay.IsEnabled = false;

            //Thread.Sleep(16800);
            btn_StartMeasurment.IsEnabled = false;
            txt_R.IsEnabled = false;
            txt_G.IsEnabled = false;
            txt_B.IsEnabled = false;

            DataTable new_dt = new DataTable();

            dt = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
            connect = PerceptionLib.Cs200Connection.ConnectToCS200();
            //if not connected then connect will be 1

            BgNo = dt.Rows.Count;
              }

            DateTime Start = DateTime.Now;
            if (connect == 0)
            {

            mainW.R = Convert.ToByte(dt.Rows[i][0].ToString());
            mainW.G = Convert.ToByte(dt.Rows[i][1].ToString());
            mainW.B = Convert.ToByte(dt.Rows[i][2].ToString());

            DisplayMeasuredValuesFromCs200();

            DifferenceCalculation();

            // assignes the data to a the datatable
            dt.Rows[i][3] = colorToShow.L.ToString();
            dt.Rows[i][4] = colorToShow.U.ToString();
            dt.Rows[i][5] = colorToShow.V.ToString();
            dt.Rows[i][6] = colorToShow.UP.ToString();
            dt.Rows[i][7] = colorToShow.VP.ToString();
            dt.Rows[i][8] = ColorMeasured.L.ToString();
            dt.Rows[i][9] = ColorMeasured.U.ToString();
            dt.Rows[i][10] = ColorMeasured.V.ToString();
            dt.Rows[i][11] = ColorMeasured.UP.ToString();
            dt.Rows[i][12] = ColorMeasured.VP.ToString();
            //dt.Rows][13] = ColorDifference.L.ToString();
            //dt.Rows][14] = ColorDifference.U.ToString();
            //dt.Rows][15] = ColorDifference.V.ToString();

            ////

            dt.Rows[i][13] = colorToShow.LA.ToString();
            dt.Rows[i][14] = colorToShow.A.ToString();
            dt.Rows[i][15] = colorToShow.B.ToString();
            dt.Rows[i][16] = ColorMeasured.LA.ToString();
            dt.Rows[i][17] = ColorMeasured.A.ToString();
            dt.Rows[i][18] = ColorMeasured.B.ToString();

            //

            dt.Rows[i][19] = PerceptionLib.Color.ColorDistanceCal(colorToShow, ColorMeasured).ToString();
            dt.Rows[i][20] = PerceptionLib.Color.ColorDistanceCalAB(colorToShow, ColorMeasured).ToString();
            //
            dt.Rows[i][21] = ColorToShowXYZ.X.ToString();
            dt.Rows[i][22] = ColorToShowXYZ.Y.ToString();
            dt.Rows[i][23] = ColorToShowXYZ.Z.ToString();
            dt.Rows[i][24] = ColorMeasuredXYZ.X.ToString();
            dt.Rows[i][25] = ColorMeasuredXYZ.Y.ToString();
            dt.Rows[i][26] = ColorMeasuredXYZ.Z.ToString();

            dt.Rows[i][27] = MR.ToString();
            dt.Rows[i][28] = MG.ToString();
            dt.Rows[i][29] = MB.ToString();

            BradXYZ = Util.CATCalulation.bradford(ColorToShowXYZ);
            VonXYZ = Util.CATCalulation.VonKries(ColorToShowXYZ);
            ScalingXYZ = Util.CATCalulation.XYZScaling(ColorToShowXYZ);

            Bradcolor = PerceptionLib.Color.ToLUV(BradXYZ);
            Voncolor = PerceptionLib.Color.ToLUV(VonXYZ);
            Scalingcolor = PerceptionLib.Color.ToLUV(ScalingXYZ);

            bradRGB = PerceptionLib.Color.ToRBG(Bradcolor);
            VonRGB = PerceptionLib.Color.ToRBG(Voncolor);
            scalingRGB = PerceptionLib.Color.ToRBG(Scalingcolor);

            CalRGB = PerceptionLib.Color.ToRBG(ColorMeasuredXYZ);

            dt.Rows[i][30] = BradXYZ.X.ToString();
            dt.Rows[i][31] = BradXYZ.Y.ToString();
            dt.Rows[i][32] = BradXYZ.Z.ToString();
            dt.Rows[i][33] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Bradcolor).ToString();
            dt.Rows[i][34] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Bradcolor).ToString();

            dt.Rows[i][35] = VonXYZ.X.ToString();
            dt.Rows[i][36] = VonXYZ.Y.ToString();
            dt.Rows[i][37] = VonXYZ.Z.ToString();
            dt.Rows[i][38] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Voncolor).ToString();
            dt.Rows[i][39] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Voncolor).ToString();

            dt.Rows[i][40] = ScalingXYZ.X.ToString();
            dt.Rows[i][41] = ScalingXYZ.Y.ToString();
            dt.Rows[i][42] = ScalingXYZ.Z.ToString();
            dt.Rows[i][43] = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, Scalingcolor).ToString();
            dt.Rows[i][44] = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Scalingcolor).ToString();

            dt.Rows[i][45] = bradRGB.R.ToString();
            dt.Rows[i][46] = bradRGB.G.ToString();
            dt.Rows[i][47] = bradRGB.B.ToString();

            dt.Rows[i][48] = VonRGB.R.ToString();
            dt.Rows[i][49] = VonRGB.G.ToString();
            dt.Rows[i][50] = VonRGB.B.ToString();

            dt.Rows[i][51] = scalingRGB.R.ToString();
            dt.Rows[i][52] = scalingRGB.G.ToString();
            dt.Rows[i][53] = scalingRGB.B.ToString();

            dt.Rows[i][54] = CalRGB.R.ToString();
            dt.Rows[i][55] = CalRGB.G.ToString();
            dt.Rows[i][56] = CalRGB.B.ToString();

            dt.Rows[i][57] = Bradcolor.UP.ToString();
            dt.Rows[i][58] = Bradcolor.VP.ToString();

            dt.Rows[i][59] = Voncolor.UP.ToString();
            dt.Rows[i][60] = Voncolor.VP.ToString();

            dt.Rows[i][61] = Scalingcolor.UP.ToString();
            dt.Rows[i][62] = Scalingcolor.VP.ToString();

            dt.Rows[i][63] = ColorMeasuredXYZ.stdx.ToString();
            dt.Rows[i][64] = ColorMeasuredXYZ.stdy.ToString();
            dt.Rows[i][65] = ColorMeasuredXYZ.stdz.ToString();

            //if (i == 9)
            //{
            //  Dispatcher.Invoke(new Action(() =>
            //  {
            //    dtgrid_corrDisplay.ItemsSource = dt.DefaultView;
            //    dtgrid_corrDisplay.Items.Refresh();

            //  }));
            //}

            //if (i == (dt.Rows.Count - 1))
            //{
            //  int disconnect = PerceptionLib.Cs200Connection.DisconnectCS200();
            //}
              }

              // System.Threading.Thread.Sleep(10000);
              // grid is populated with new datatable which has luv values
             //Dispatcher.Invoke(new Action(() =>
              //{
            dtgrid_corrDisplay.ItemsSource = dt.DefaultView;
            dtgrid_corrDisplay.Items.Refresh();
              //}));

              //  to show all the pairs in cie graph
              //pairs.Clear();

              //for (int i = 0; i < dt.Rows.Count; i++)
              //{
              //  pairs.Add(new MeasurementPair()
              //  {
              //    ColorToShow = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][6].ToString()), VP = Convert.ToDouble(dt.Rows[i][7].ToString()) },
              //    ColorCaptured = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[i][11].ToString()), VP = Convert.ToDouble(dt.Rows[i][12].ToString()) }
              //  });
              //}

              BinNo++;

              btn_ExportGrid.IsEnabled = true;

              dtgrid_corrDisplay.IsEnabled = true;
              dataTable = dt;
        }
コード例 #16
0
        public static CIEXYZ StartMeasureXYZForPhone()
        {
            int time1 = 500;
              if (caputerIndex != 1)
              {
            System.Threading.Thread.Sleep(2350);
              }
              caputerIndex = 0;
              StringBuilder returnString = new StringBuilder(250);
              //measure
              string cMeasure = "MES,1\r\n";
              int length = cMeasure.Length;

              int r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
              r = CaptureEngine.read64_usb(0, returnString, 1, 250);

              string waittime = returnString.ToString(5, 2);

              CIEXYZ xyz = new CIEXYZ(0, 0, 0);
              int t = Convert.ToInt32(waittime);
              t = t * 1000;
              t = t - 500;
              int temp = t;

              ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
              //take the if out for any other than phone
              //
              if (t < 800)
              {

            System.Threading.Thread.Sleep(t);

            cMeasure = "MDR,3\r\n";
            length = cMeasure.Length;

            r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
            r = CaptureEngine.read64_usb(0, returnString, 1, 250);

            string error = returnString.ToString(0, 4);

              while (error == "ER02")
              {
            t = t + 300;
            if (t < 800)
            {
              //System.Threading.Thread.Sleep(300);
              cMeasure = "MDR,3\r\n";
              length = cMeasure.Length;

              r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
              r = CaptureEngine.read64_usb(0, returnString, 1, 250);
              error = returnString.ToString(0, 4);
            }
            else
            {
              int tMinus = Math.Abs(2750);
              //System.Threading.Thread.Sleep(500);
              xyz = new CIEXYZ(0, 0, 0);
              xyz.stdx = t;
              xyz.stdy = 0;
              xyz.stdz = 0;
              break;
            }

              }

              if (t < 800)
              {
              string op = returnString.ToString();
              string x = returnString.ToString(27, 10);
              string y = returnString.ToString(39, 10);
              string z = returnString.ToString(51, 10);

              double X = Convert.ToDouble(x) / 100;
              double Y = Convert.ToDouble(y) / 100;
              double Z = Convert.ToDouble(z) / 100;

              xyz = new CIEXYZ(X, Y, Z);
              xyz.stdx = t;
              xyz.stdy = 1;
              xyz.stdz = 1;
              }

              }
              else
              {
            System.Threading.Thread.Sleep(500);

            xyz = new CIEXYZ(-1, -1, -1);
            xyz.stdx = 0;
            xyz.stdy = 0;
            xyz.stdz = 0;

              }
               return xyz;
        }
コード例 #17
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        public static Color ToLUV(CIEXYZ xyz,CIEXYZ WtPoint)
        {
            Color rColor = new Color();
              Color rColorlab = new Color();
              //CIEXYZ xyz = RGBToXYZ(cRGB);

              rColor.UP = (4 * xyz.X) / (xyz.X + (15 * xyz.Y) + (3 * xyz.Z));
              rColor.VP = (9 * xyz.Y) / (xyz.X + (15 * xyz.Y) + (3 * xyz.Z));

              double UR = (4 * WtPoint.X) / (WtPoint.X + (15 * WtPoint.Y) + (3 * WtPoint.Z));
              double VR = (9 * WtPoint.Y) / (WtPoint.X + (15 * WtPoint.Y) + (3 * WtPoint.Z));

              double yr = xyz.Y / WtPoint.Y;
              rColor.L = Lxyz(yr);
              rColor.U = (13 * rColor.L) * (rColor.UP - UR);
              rColor.V = (13 * rColor.L) * (rColor.VP - VR);
              rColorlab = ToLAB(xyz);
              rColor.LA = rColorlab.LA;
              rColor.A = rColorlab.A;
              rColor.B = rColorlab.B;
              return rColor;
        }
コード例 #18
0
ファイル: Color.cs プロジェクト: pilot007/STColorCorrection
        public static RGBValue ToRBG(CIEXYZ xyz)
        {
            double tempr, tempg, tempb;
            //CIEXYZ xyz = LUVToXYZ(PassedLUV);


            RGBValue rgb = new RGBValue();

            double[] Clinear = new double[3];
            double[] linear  = new double[3];

            Clinear[0] = (xyz.X) * 3.2404542 - (xyz.Y) * 1.5371385 - (xyz.Z) * 0.4985314;  // red
            Clinear[1] = -(xyz.X) * 0.9692660 + (xyz.Y) * 1.8760108 + (xyz.Z) * 0.0415560; // green
            Clinear[2] = (xyz.X) * 0.0556434 - (xyz.Y) * 0.2040259 + (xyz.Z) * 1.0572252;  // blue


            //  if ( var_R > 0.0031308 ) var_R = 1.055 * ( var_R ^ ( 1 / 2.4 ) ) - 0.055
            //else                     var_R = 12.92 * var_R
            //if ( var_G > 0.0031308 ) var_G = 1.055 * ( var_G ^ ( 1 / 2.4 ) ) - 0.055
            //else                     var_G = 12.92 * var_G
            //if ( var_B > 0.0031308 ) var_B = 1.055 * ( var_B ^ ( 1 / 2.4 ) ) - 0.055
            //else                     var_B = 12.92 * var_B



            if (Clinear[0] > 0.0031308)
            {
                Clinear[0] = 1.055 * Math.Pow(Clinear[0], (1 / (2.2))) - 0.055;
                rgb.gmt    = 1;
            }
            else
            {
                Clinear[0] = 12.92 * Clinear[0];
                rgb.gmt    = 0;
            }
            if (Clinear[1] > 0.0031308)
            {
                Clinear[1] = 1.055 * Math.Pow(Clinear[1], (1 / (2.2))) - 0.055;
                rgb.gmt    = 1;
            }
            else
            {
                Clinear[1] = 12.92 * Clinear[1];
                rgb.gmt    = 0;
            }
            if (Clinear[2] > 0.0031308)
            {
                Clinear[2] = 1.055 * Math.Pow(Clinear[2], (1 / (2.2))) - 0.055;
                rgb.gmt    = 1;
            }
            else
            {
                Clinear[2] = 12.92 * Clinear[2];
                rgb.gmt    = 0;
            }

            ////gamma companding
            //for (int i = 0; i < 3; i++)
            //{
            //    if (Clinear[i] <= 0.0031308)
            //    {
            //        linear[i] = Clinear[i] * 12.92;
            //    }

            //    else
            //    {
            //        linear[i] = (1.055 * Math.Pow(Clinear[i], (1.0 / 2.2))) - 0.055;
            //        //linear[i] = ( Math.Pow((Clinear[i]), (1.0 / 2.2)));

            //    }
            //}

            tempr = (Math.Round(Clinear[0] * 255));
            tempg = (Math.Round(Clinear[1] * 255));
            tempb = (Math.Round(Clinear[2] * 255));

            //if (tempr > 255 || tempg > 255 || tempb > 255)
            //  rgb.gmt = 1;
            //else
            //  rgb.gmt = 0;
            // make sure rgb is not over 255
            //if (tempr > 255)
            //{
            //    tempr = 255;
            //}
            //if (tempg > 255)
            //{
            //    tempg = 255;
            //}
            //if (tempb > 255)
            //{
            //    tempb = 255;
            //}
            //if (tempr < 0)
            //{
            //    tempr = 0;
            //}
            //if (tempg < 0)
            //{
            //    tempg = 0;
            //}
            //if (tempb < 0)
            //{
            //    tempb = 0;
            //}
            rgb.R = (byte)(tempr);
            rgb.G = (byte)(tempg);
            rgb.B = (byte)(tempb);
            return(rgb);
        }
コード例 #19
0
        private void Btn_Recheck_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;

              double X, Y, Z;

              int binnumber = 0;
              int GammutRangeCheck1, GammutRangeCheck4;

              CIEXYZ BINcolorXYZ = new CIEXYZ(0, 0, 0);
              CIEXYZ MBINcolorXYZ = new CIEXYZ(0, 0, 0);

              CIEXYZ NoBINcolorXYZ = new CIEXYZ(0, 0, 0);
              CIEXYZ NoMBINcolorXYZ = new CIEXYZ(0, 0, 0);
              int connect = PerceptionLib.Cs200Connection.ConnectToCS200();

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\BaseBinFile.csv");
              DataTable bin = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              double minLLevel = double.MaxValue;
              double maxLLevel = double.MinValue;
              double minALevel = double.MaxValue;
              double maxALevel = double.MinValue;
              double minBLevel = double.MaxValue;
              double maxBLevel = double.MinValue;

              double minL = double.MaxValue;
              double maxL = double.MinValue;
              double minA = double.MaxValue;
              double maxA = double.MinValue;
              double minB = double.MaxValue;
              double maxB = double.MinValue;

              foreach (DataRow dr in bin.Rows)
              {
            double accountLevel = dr.Field<double>("MLA");
            minLLevel = Math.Min(minLLevel, accountLevel);
            maxLLevel = Math.Max(maxLLevel, accountLevel);

            double ALevel = dr.Field<double>("MA");
            minALevel = Math.Min(minALevel, ALevel);
            maxALevel = Math.Max(maxALevel, ALevel);

            double BLevel = dr.Field<double>("MlaB");
            minBLevel = Math.Min(minBLevel, BLevel);
            maxBLevel = Math.Max(maxBLevel, BLevel);

            double account = dr.Field<double>("LA");
            minL = Math.Min(minL, account);
            maxL = Math.Max(maxL, account);

            double ALvl = dr.Field<double>("A");
            minA = Math.Min(minA, ALvl);
            maxA = Math.Max(maxA, ALvl);

            double BLvl = dr.Field<double>("LB");
            minB = Math.Min(minBLevel, BLvl);
            maxB = Math.Max(maxBLevel, BLvl);
              }

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\big_pro_crosscheck.csv");
              DataTable dt_Bg = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_Bg = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));
              ThreadPool.QueueUserWorkItem(ignored =>
            {
              PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();
              for (int i = 0; i < dt_Bg.Rows.Count; i++)
              {
            if (stop == 1)
            {
              stop = 0;
              break;
            }

            BgR = Convert.ToByte(dt_Bg.Rows[i][12].ToString());
            BgG = Convert.ToByte(dt_Bg.Rows[i][13].ToString());
            BgB = Convert.ToByte(dt_Bg.Rows[i][14].ToString());

            X = Convert.ToDouble(dt_Bg.Rows[i][15].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][16].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][17].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            X = Convert.ToDouble(dt_Bg.Rows[i][9].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][10].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][11].ToString());
            BINcolorXYZ = new CIEXYZ(X, Y, Z);
            BINColor = PerceptionLib.Color.ToLAB(MBINcolorXYZ);

            MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BINcolorXYZ, ColorBackGroundXYZ);
            MBINColor = PerceptionLib.Color.ToLAB(MBINcolorXYZ);

            dt_Bg.Rows[i][27] = MBINColor.LA.ToString();
            dt_Bg.Rows[i][28] = MBINColor.A.ToString();
            dt_Bg.Rows[i][29] = MBINColor.B.ToString();

            ColorToShow.LA = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            ColorToShow.A = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            ColorToShow.B = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            binnumber = Util.CATCalulation.MatchWithBinned(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            GammutRangeCheck4 = 1;

            if ((MBINColor.LA >= minLLevel) & (MBINColor.LA <= maxLLevel) & (MBINColor.A >= minALevel) & (MBINColor.A <= maxALevel) & (MBINColor.B >= minBLevel) & (MBINColor.B <= maxBLevel))
            {
              for (int index = 0; index < bin.Rows.Count; index++)
              {
            double tempL, tempA, tempB;
            tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
            tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
            tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

            if ((MBINColor.LA >= tempL - 5) & (MBINColor.LA <= tempL + 5) & (MBINColor.A >= tempA - 5) & (MBINColor.A <= tempA + 5) & (MBINColor.B >= tempB - 5) & (MBINColor.B <= tempB + 5))
            {
              GammutRangeCheck4 = 0;
              break;
            }
            GammutRangeCheck4 = 1;
              }

            }
            else
              GammutRangeCheck4 = 1;
            //
            //binnumber = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            double LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            double A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            double B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            byte R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            byte G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            byte Bi = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            dt_Bg.Rows[i][45] = LA.ToString();
            dt_Bg.Rows[i][46] = A.ToString();
            dt_Bg.Rows[i][47] = B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BgR, BgG, BgB));
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(R, G, Bi));

            }));
            DisplayMeasuredValuesFromCs200();

            MBincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            dt_Bg.Rows[i][48] = ColorMeasured.LA.ToString();
            dt_Bg.Rows[i][49] = ColorMeasured.A.ToString();
            dt_Bg.Rows[i][50] = ColorMeasured.B.ToString();

            ColorToShow.L =Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            ColorToShow.L = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            ColorToShow.L = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            double DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);

            dt_Bg.Rows[i][51] = DeltaBin_Lab.ToString();
            dt_Bg.Rows[i][52] = GammutRangeCheck4.ToString();

            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //binnumber = Util.CATCalulation.MatchWithBinned(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            //GammutRangeCheck1 = 1;

            //if ((MBINColor.LA >= minLLevel) & (MBINColor.LA <= maxLLevel) & (MBINColor.A >= minALevel) & (MBINColor.A <= maxALevel) & (MBINColor.B >= minBLevel) & (MBINColor.B <= maxBLevel))
            //{
            //  for (int index = 0; index < bin.Rows.Count; index++)
            //  {
            //    double tempL, tempA, tempB;
            //    tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
            //    tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
            //    tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

            //    if ((MBINColor.LA >= tempL - 5) & (MBINColor.LA <= tempL + 5) & (MBINColor.A >= tempA - 5) & (MBINColor.A <= tempA + 5) & (MBINColor.B >= tempB - 5) & (MBINColor.B <= tempB + 5))
            //    {
            //      GammutRangeCheck1 = 0;
            //      break;
            //    }
            //    GammutRangeCheck1 = 1;
            //  }

            //}
            //else
            //  GammutRangeCheck1 = 1;
            ////

            //NoMBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            //NoMBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            //NoMBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            //double NoLA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            //double NoA = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            //double NoB = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            //byte NoR = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            //byte NoG = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            //byte NoBi = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            //dt_Bg.Rows[i][45] = LA.ToString();
            //dt_Bg.Rows[i][46] = A.ToString();
            //dt_Bg.Rows[i][47] = B.ToString();

            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BgR, BgG, BgB));
            //  rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(NoR, NOG, NoBi));

            //}));
            //DisplayMeasuredValuesFromCs200();

            //MBincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            //dt_Bg.Rows[i][48] = ColorMeasured.LA.ToString();
            //dt_Bg.Rows[i][49] = ColorMeasured.A.ToString();
            //dt_Bg.Rows[i][50] = ColorMeasured.B.ToString();

            //double NODeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);

            //dt_Bg.Rows[i][51] = DeltaBin_Lab.ToString();
            //dt_Bg.Rows[i][52] = GammutRangeCheck4.ToString();

            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_Bg.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              }
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_Bg.DefaultView));
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            });

              btn_ExportGrid.IsEnabled = true;
        }
コード例 #20
0
        private void Btn_PhoneDataCalculator_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\phone\cal\consolidated_Phone_NewBG.csv");

              DataTable MixedXYZ = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            MixedXYZ = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\phone\cal\FinalValue.csv");

              DataTable FinalValue = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            FinalValue = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              CIEXYZ BgWithScreenXYZ;
              CIEXYZ colorToShowBINXYZ;
              PerceptionLib.Color colorToShowBIN;

              Double CDiff, ADiff, AsDiff, BDiff, BsDiff;

              DataRow newRow;

              for (int i = 0; i < MixedXYZ.Rows.Count; i++)
              {
            newRow = FinalValue.NewRow();

            double xbG = Convert.ToDouble(MixedXYZ.Rows[i][1].ToString());
            double ybG = Convert.ToDouble(MixedXYZ.Rows[i][2].ToString());
            double zbG = Convert.ToDouble(MixedXYZ.Rows[i][3].ToString());
            ColorBackGroundXYZ = new CIEXYZ(xbG, ybG, zbG);

            double xbGS = Convert.ToDouble(MixedXYZ.Rows[i][4].ToString());
            double ybGS = Convert.ToDouble(MixedXYZ.Rows[i][5].ToString());
            double zbGS = Convert.ToDouble(MixedXYZ.Rows[i][6].ToString());
            BgWithScreenXYZ = new CIEXYZ(xbGS, ybGS, zbGS);

            double xfG = Convert.ToDouble(MixedXYZ.Rows[i][8].ToString());
            double yfG = Convert.ToDouble(MixedXYZ.Rows[i][9].ToString());
            double zfG = Convert.ToDouble(MixedXYZ.Rows[i][10].ToString());
            ColorToShowXYZ = new CIEXYZ(xfG, yfG, zfG);

            double xfGB = Convert.ToDouble(MixedXYZ.Rows[i][11].ToString());
            double yfGB = Convert.ToDouble(MixedXYZ.Rows[i][12].ToString());
            double zfGB = Convert.ToDouble(MixedXYZ.Rows[i][13].ToString());
            colorToShowBINXYZ = new CIEXYZ(xfGB, yfGB, zfGB);
            colorToShowBIN = PerceptionLib.Color.ToLAB(colorToShowBINXYZ);

            double xcfG = Convert.ToDouble(MixedXYZ.Rows[i][14].ToString());
            double ycfG = Convert.ToDouble(MixedXYZ.Rows[i][15].ToString());
            double zcfG = Convert.ToDouble(MixedXYZ.Rows[i][16].ToString());

            ColorMeasuredXYZ = new CIEXYZ(xcfG, ycfG, zcfG);
            ColorMeasured = PerceptionLib.Color.ToLAB(ColorMeasuredXYZ);

            AcolorXYZ = new CIEXYZ(0, 0, 0);
            AcolorXYZ.X = xbG + xfG;
            AcolorXYZ.Y = ybG + yfG;
            AcolorXYZ.Z = zbG + zfG;

            Acolor = PerceptionLib.Color.ToLAB(AcolorXYZ);
            MAcolorXYZ = new CIEXYZ(0, 0, 0);
            MAcolorXYZ.X = xbGS + xfG;
            MAcolorXYZ.Y = ybGS + yfG;
            MAcolorXYZ.Z = zbGS + zfG;

            MAcolor = PerceptionLib.Color.ToLAB(MAcolorXYZ);
            BINcolorXYZ = new CIEXYZ(0, 0, 0);
            BINcolorXYZ.X = xbG + xcfG;
            BINcolorXYZ.Y = ybG + ycfG;
            BINcolorXYZ.Z = zbG + zcfG;

            BINColor = PerceptionLib.Color.ToLAB(BINcolorXYZ);
            MBINcolorXYZ = new CIEXYZ(0, 0, 0);
            MBINcolorXYZ.X = xbGS + xcfG;
            MBINcolorXYZ.Y = ybGS + ycfG;
            MBINcolorXYZ.Z = zbGS + zcfG;

            MBINColor = PerceptionLib.Color.ToLAB(MBINcolorXYZ);

            CDiff = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, colorToShowBIN);
            ADiff = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Acolor);
            AsDiff = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MAcolor);
            BDiff = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, BINColor);
            BsDiff = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MBINColor);

            newRow[0] =MixedXYZ.Rows[i][0].ToString();
            newRow[1] =MixedXYZ.Rows[i][7].ToString();
            newRow[2] =colorToShowBIN.LA.ToString();
            newRow[3] =colorToShowBIN.A.ToString();
            newRow[4] =colorToShowBIN.B.ToString();
            newRow[5] =ColorMeasured.LA.ToString();
            newRow[6] =ColorMeasured.A.ToString();
            newRow[7] =ColorMeasured.B.ToString();
            newRow[8] =Acolor.LA.ToString();
            newRow[9] =Acolor.A.ToString();
            newRow[10]=Acolor.B.ToString();
            newRow[11] = MAcolor.LA.ToString();
            newRow[12] = MAcolor.A.ToString();
            newRow[13] = MAcolor.B.ToString();

            newRow[14] = BINColor.LA.ToString();
            newRow[15] = BINColor.A.ToString();
            newRow[16] = BINColor.B.ToString();
            newRow[17] = MBINColor.LA.ToString();
            newRow[18] = MBINColor.A.ToString();
            newRow[19] = MBINColor.B.ToString();

            newRow[20] = ADiff.ToString();
            newRow[21] = AsDiff.ToString();
            newRow[22] = BDiff.ToString();
            newRow[23] = BsDiff.ToString();
            newRow[24] = CDiff.ToString();
            FinalValue.Rows.Add(newRow);
              }

              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = FinalValue.DefaultView));
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              btn_ExportGrid.IsEnabled = true;
        }
コード例 #21
0
        public static CIEXYZ StartAVGMeasureXYZ9()
        {
            double x, y, z;

              CIEXYZ xyz1 = StartAVGMeasureXYZ3();
              CIEXYZ xyz2 = StartAVGMeasureXYZ3();
              CIEXYZ xyz3 = StartAVGMeasureXYZ3();

              x = (double)((xyz1.X) + (xyz2.X) + (xyz3.X)) / 3.0;
              y = (double)((xyz1.Y) + (xyz2.Y) + (xyz3.Y)) / 3.0;
              z = (double)((xyz1.Z) + (xyz2.Z) + (xyz3.Z)) / 3.0;

              CIEXYZ xyz = new CIEXYZ(x, y, z);
              xyz.stdx = (double)((xyz1.stdx) + (xyz2.stdx) + (xyz3.stdx)) / 3.0;
              xyz.stdy = (double)((xyz1.stdy) + (xyz2.stdy) + (xyz3.stdy)) / 3.0;
              xyz.stdz = (double)((xyz1.stdz) + (xyz2.stdz) + (xyz3.stdz)) / 3.0;

              return xyz;
        }
コード例 #22
0
 public static PerceptionLib.CIEXYZ ToGetXYZ(int r, int g, int b)
 {
     System.Drawing.Color mRGB        = ToGetRGB(r, g, b);
     PerceptionLib.CIEXYZ colorObject = PerceptionLib.Color.RGBToXYZ(mRGB);
     return(colorObject);
 }
コード例 #23
0
        /// <summary>
        /// function to get XYZ vales from CS200
        /// </summary>
        /// <returns></returns>
        public static CIEXYZ StartMeasureXYZ()
        {
            StringBuilder returnString = new StringBuilder(250);
              //measure
              string cMeasure = "MES,1\r\n";
              int length = cMeasure.Length;

              int r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
              r = CaptureEngine.read64_usb(0, returnString, 1, 250);

              string waittime = returnString.ToString(5, 2);

              int t = Convert.ToInt32(waittime);
              t = t * 1000;
              t = t - 500;

              ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
              //take the if out for any other than phone
              //

              System.Threading.Thread.Sleep(t);

              cMeasure = "MDR,3\r\n";
              length = cMeasure.Length;

              r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
              r = CaptureEngine.read64_usb(0, returnString, 1, 250);

              string error = returnString.ToString(0, 4);

              if (error == "ER21")
              {
            CIEXYZ xyz = new CIEXYZ(0, 0, 0);
            xyz.stdx = t;
            xyz.stdy = 0;
            xyz.stdz = 0;
            return xyz;
              }

              while (error == "ER02")
              {
            t = t + 300;
            System.Threading.Thread.Sleep(300);
            cMeasure = "MDR,3\r\n";
            length = cMeasure.Length;

            r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
            r = CaptureEngine.read64_usb(0, returnString, 1, 250);
            error = returnString.ToString(0, 4);
              }

              if (error == "ER21")
              {
            CIEXYZ xyz = new CIEXYZ(0, 0, 0);
            xyz.stdx = t;
            xyz.stdy = 0;
            xyz.stdz = 0;
            return xyz;
              }
              else
              {

            string op = returnString.ToString();
            string x = returnString.ToString(27, 10);
            string y = returnString.ToString(39, 10);
            string z = returnString.ToString(51, 10);

            double X = Convert.ToDouble(x) / 100;
            double Y = Convert.ToDouble(y) / 100;
            double Z = Convert.ToDouble(z) / 100;

            CIEXYZ xyz = new CIEXYZ(X, Y, Z);
            xyz.stdx = t;
            xyz.stdy = 0;
            xyz.stdz = 0;

            return xyz;
              }
        }
コード例 #24
0
        private void Btn_CSPredictor_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;

              double X, Y, Z, DeltaA_Luv, DeltaA_LAb, DeltaBin_Luv, DeltaBin_Lab, DeltaB_luv, DeltaB_Lab, DeltaS_Luv, DeltaS_Lab, DeltaV_Luv, DeltaV_Lab,DeltaC,BinDeltaC;

              DataRow newRow;

              int connect = PerceptionLib.Cs200Connection.ConnectToCS200();

              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValue.csv");
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValueWtPt.csv");
              DataTable dt_Bg = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_Bg = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\RGBgammut.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB8000.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB88.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB88.csv");
              DataTable dt_RGBGammut = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_RGBGammut = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              BgNo = dt_Bg.Rows.Count;
              FgNo = dt_RGBGammut.Rows.Count;

              //BgNo = 6;
              //FgNo = 4;
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\Cspredictor.csv");
              DataTable dt_DataCollection = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_DataCollection = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              ThreadPool.QueueUserWorkItem(ignored =>
              {
            PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();
            for (int i = 0; i < BgNo; i++)
            {

              for (int j = 0; j < FgNo; j=j+20)
              {
            BgR = Convert.ToByte(dt_Bg.Rows[i][0].ToString());
            BgG = Convert.ToByte(dt_Bg.Rows[i][1].ToString());
            BgB = Convert.ToByte(dt_Bg.Rows[i][2].ToString());

            X = Convert.ToDouble(dt_Bg.Rows[i][3].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][4].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][5].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            R = Convert.ToByte(dt_RGBGammut.Rows[j][0].ToString());
            G = Convert.ToByte(dt_RGBGammut.Rows[j][1].ToString());
            B = Convert.ToByte(dt_RGBGammut.Rows[j][2].ToString());

            //cat model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][25].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][26].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][27].ToString());
            BradXYZ = new CIEXYZ(X, Y, Z);

            X = Convert.ToDouble(dt_RGBGammut.Rows[j][28].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][29].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][30].ToString());
            VonXYZ = new CIEXYZ(X, Y, Z);

            X = Convert.ToDouble(dt_RGBGammut.Rows[j][31].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][32].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][33].ToString());
            ScalingXYZ = new CIEXYZ(X, Y, Z);

            //direct model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][11].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][12].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][13].ToString());
            AcolorXYZ = new CIEXYZ(X, Y, Z);

            Acolor = PerceptionLib.Color.ToLUV(AcolorXYZ);

            //bin model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][22].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][23].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][24].ToString());
            BINcolorXYZ = new CIEXYZ(X, Y, Z);

            BINColor = PerceptionLib.Color.ToLUV(BINcolorXYZ);

            //adding XYZ values
            MBradXYZ = Util.ColorSpaceConverter.AddXYZ(BradXYZ, ColorBackGroundXYZ);
            MScalingXYZ = Util.ColorSpaceConverter.AddXYZ(ScalingXYZ, ColorBackGroundXYZ);
            MVonXYZ = Util.ColorSpaceConverter.AddXYZ(VonXYZ, ColorBackGroundXYZ);
            MAcolorXYZ = Util.ColorSpaceConverter.AddXYZ(AcolorXYZ, ColorBackGroundXYZ);
            MBINcolorXYZ = Util.ColorSpaceConverter.AddXYZ(BINcolorXYZ, ColorBackGroundXYZ);

            //converting back to various spaces fpr color difference calculation
            MBradcolor = PerceptionLib.Color.ToLUV(MBradXYZ);
            MVoncolor = PerceptionLib.Color.ToLUV(MVonXYZ);
            MScalingcolor = PerceptionLib.Color.ToLUV(MScalingXYZ);
            MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);
            MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);

            bradRGB = PerceptionLib.Color.ToRBG(MBradXYZ);
            VonRGB = PerceptionLib.Color.ToRBG(MVonXYZ);
            scalingRGB = PerceptionLib.Color.ToRBG(MScalingXYZ);
            acolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);
            BincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            CSColorUpdateOnScreenWithBG();

            DisplayMeasuredValuesFromCs200();

            //difference calculation
            DeltaB_luv = PerceptionLib.Color.ColorDistanceCal(Mbradcolor, ColorMeasured);
            DeltaB_Lab = PerceptionLib.Color.ColorDistanceCalAB(Mbradcolor, ColorMeasured);

            DeltaV_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MVoncolor);
            DeltaV_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MVoncolor);

            DeltaS_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MScalingcolor);
            DeltaS_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MScalingcolor);

            DeltaA_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MAcolor);
            DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MAcolor);

            DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MBINColor);
            DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MBINColor);

            BinDeltaC = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, BINColor);

            DeltaC = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, Acolor);

            newRow = dt_DataCollection.NewRow();
            newRow[0] = R;
            newRow[1] = G;
            newRow[2] = B;
            newRow[3] = dt_RGBGammut.Rows[j][3].ToString();
            newRow[4] = dt_RGBGammut.Rows[j][4].ToString();
            newRow[5] = dt_RGBGammut.Rows[j][5].ToString();
            newRow[6] = dt_RGBGammut.Rows[j][6].ToString();
            newRow[7] = dt_RGBGammut.Rows[j][7].ToString();
            newRow[8] = dt_RGBGammut.Rows[j][8].ToString();
            newRow[9] = dt_RGBGammut.Rows[j][9].ToString();
            newRow[10] = dt_RGBGammut.Rows[j][10].ToString();
            newRow[11] = dt_RGBGammut.Rows[j][11].ToString();
            newRow[12] = dt_RGBGammut.Rows[j][12].ToString();
            newRow[13] = dt_RGBGammut.Rows[j][13].ToString();
            newRow[14] = dt_RGBGammut.Rows[j][14].ToString();
            newRow[15] = dt_RGBGammut.Rows[j][15].ToString();
            newRow[16] = dt_RGBGammut.Rows[j][16].ToString();
            newRow[17] = dt_RGBGammut.Rows[j][17].ToString();
            newRow[18] = dt_RGBGammut.Rows[j][18].ToString();
            newRow[19] = dt_RGBGammut.Rows[j][19].ToString();
            newRow[20] = dt_RGBGammut.Rows[j][20].ToString();
            newRow[21] = dt_RGBGammut.Rows[j][21].ToString();
            newRow[22] = dt_RGBGammut.Rows[j][22].ToString();
            newRow[23] = dt_RGBGammut.Rows[j][23].ToString();
            newRow[24] = dt_RGBGammut.Rows[j][24].ToString();
            newRow[25] = dt_RGBGammut.Rows[j][25].ToString();
            newRow[26] = dt_RGBGammut.Rows[j][26].ToString();
            newRow[27] = dt_RGBGammut.Rows[j][27].ToString();
            newRow[28] = dt_RGBGammut.Rows[j][28].ToString();
            newRow[29] = dt_RGBGammut.Rows[j][29].ToString();
            newRow[30] = dt_RGBGammut.Rows[j][30].ToString();
            newRow[31] = dt_RGBGammut.Rows[j][31].ToString();
            newRow[32] = dt_RGBGammut.Rows[j][32].ToString();
            newRow[33] = dt_RGBGammut.Rows[j][33].ToString();
            newRow[34] = BgR;
            newRow[35] = BgG;
            newRow[36] = BgB;
            newRow[37] = dt_Bg.Rows[i][3].ToString();
            newRow[38] = dt_Bg.Rows[i][4].ToString();
            newRow[39] = dt_Bg.Rows[i][5].ToString();
            newRow[40] = ColorMeasuredXYZ.X.ToString();
            newRow[41] = ColorMeasuredXYZ.Y.ToString();
            newRow[42] = ColorMeasuredXYZ.Z.ToString();
            newRow[43] = ColorMeasured.L.ToString();
            newRow[44] = ColorMeasured.U.ToString();
            newRow[45] = ColorMeasured.V.ToString();
            newRow[46] = ColorMeasured.UP.ToString();
            newRow[47] = ColorMeasured.VP.ToString();
            newRow[48] = ColorMeasured.LA.ToString();
            newRow[49] = ColorMeasured.A.ToString();
            newRow[50] = ColorMeasured.B.ToString();
            newRow[51] = MR.ToString();
            newRow[52] = MG.ToString();
            newRow[53] = MB.ToString();
            newRow[54] = MAcolorXYZ.X.ToString();
            newRow[55] = MAcolorXYZ.Y.ToString();
            newRow[56] = MAcolorXYZ.Z.ToString();
            newRow[57] = MAcolor.L.ToString();
            newRow[58] = MAcolor.U.ToString();
            newRow[59] = MAcolor.V.ToString();
            newRow[60] = MAcolor.UP.ToString();
            newRow[61] = MAcolor.VP.ToString();
            newRow[62] = MAcolor.LA.ToString();
            newRow[63] = MAcolor.A.ToString();
            newRow[64] = MAcolor.B.ToString();
            newRow[65] = acolorRGB.R.ToString();
            newRow[66] = acolorRGB.G.ToString();
            newRow[67] = acolorRGB.B.ToString();
            newRow[68] = MBradXYZ.X.ToString();
            newRow[69] = MBradXYZ.Y.ToString();
            newRow[70] = MBradXYZ.Z.ToString();
            newRow[71] = MBradcolor.L.ToString();
            newRow[72] = MBradcolor.U.ToString();
            newRow[73] = MBradcolor.V.ToString();
            newRow[74] = MBradcolor.UP.ToString();
            newRow[75] = MBradcolor.VP.ToString();
            newRow[76] = MBradcolor.LA.ToString();
            newRow[77] = MBradcolor.A.ToString();
            newRow[78] = MBradcolor.B.ToString();
            newRow[79] = MVonXYZ.X.ToString();
            newRow[80] = MVonXYZ.Y.ToString();
            newRow[81] = MVonXYZ.Z.ToString();
            newRow[82] = MVoncolor.L.ToString();
            newRow[83] = MVoncolor.U.ToString();
            newRow[84] = MVoncolor.V.ToString();
            newRow[85] = MVoncolor.UP.ToString();
            newRow[86] = MVoncolor.VP.ToString();
            newRow[87] = MVoncolor.LA.ToString();
            newRow[88] = MVoncolor.A.ToString();
            newRow[89] = MVoncolor.B.ToString();
            newRow[90] = MScalingXYZ.X.ToString();
            newRow[91] = MScalingXYZ.Y.ToString();
            newRow[92] = MScalingXYZ.Z.ToString();
            newRow[93] = MScalingcolor.L.ToString();
            newRow[94] = MScalingcolor.U.ToString();
            newRow[95] = MScalingcolor.V.ToString();
            newRow[96] = MScalingcolor.UP.ToString();
            newRow[97] = MScalingcolor.VP.ToString();
            newRow[98] = MScalingcolor.LA.ToString();
            newRow[99] = MScalingcolor.A.ToString();
            newRow[100] = MScalingcolor.B.ToString();
            newRow[101] = MBINcolorXYZ.X.ToString();
            newRow[102] = MBINcolorXYZ.Y.ToString();
            newRow[103] = MBINcolorXYZ.Z.ToString();
            newRow[104] = MBINColor.L.ToString();
            newRow[105] = MBINColor.U.ToString();
            newRow[106] = MBINColor.V.ToString();
            newRow[107] = MBINColor.UP.ToString();
            newRow[108] = MBINColor.VP.ToString();
            newRow[109] = MBINColor.LA.ToString();
            newRow[110] = MBINColor.A.ToString();
            newRow[111] = MBINColor.B.ToString();
            newRow[112] = DeltaA_Luv.ToString();
            newRow[113] = DeltaA_LAb.ToString();
            newRow[114] = DeltaBin_Luv.ToString();
            newRow[115] = DeltaBin_Lab.ToString();
            newRow[116] = DeltaB_luv.ToString();
            newRow[117] = DeltaB_Lab.ToString();
            newRow[118] = DeltaV_Luv.ToString();
            newRow[119] = DeltaV_Lab.ToString();
            newRow[120] = DeltaS_Luv.ToString();
            newRow[121] = DeltaS_Lab.ToString();
            newRow[122] = BinDeltaC.ToString();
            newRow[123] = DeltaC.ToString();

            //calculation for Bg through the screen.
            X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            MBradXYZ = Util.ColorSpaceConverter.AddXYZ(BradXYZ, ColorBackGroundXYZ);
            MScalingXYZ = Util.ColorSpaceConverter.AddXYZ(ScalingXYZ, ColorBackGroundXYZ);
            MVonXYZ = Util.ColorSpaceConverter.AddXYZ(VonXYZ, ColorBackGroundXYZ);
            MAcolorXYZ = Util.ColorSpaceConverter.AddXYZ(AcolorXYZ, ColorBackGroundXYZ);
            MBINcolorXYZ = Util.ColorSpaceConverter.AddXYZ(BINcolorXYZ, ColorBackGroundXYZ);

            //converting back to various spaces fpr color difference calculation
            MBradcolor = PerceptionLib.Color.ToLUV(MBradXYZ);
            MVoncolor = PerceptionLib.Color.ToLUV(MVonXYZ);
            MScalingcolor = PerceptionLib.Color.ToLUV(MScalingXYZ);
            MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);
            MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);

            bradRGB = PerceptionLib.Color.ToRBG(MBradXYZ);
            VonRGB = PerceptionLib.Color.ToRBG(MVonXYZ);
            scalingRGB = PerceptionLib.Color.ToRBG(MScalingXYZ);
            acolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);
            BincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            DeltaB_luv = PerceptionLib.Color.ColorDistanceCal(Mbradcolor, ColorMeasured);
            DeltaB_Lab = PerceptionLib.Color.ColorDistanceCalAB(Mbradcolor, ColorMeasured);

            DeltaV_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MVoncolor);
            DeltaV_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MVoncolor);

            DeltaS_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MScalingcolor);
            DeltaS_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MScalingcolor);

            DeltaA_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MAcolor);
            DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MAcolor);

            DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCal(ColorMeasured, MBINColor);
            DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, MBINColor);

            newRow[124] = MAcolorXYZ.X.ToString();
            newRow[125] = MAcolorXYZ.Y.ToString();
            newRow[126] = MAcolorXYZ.Z.ToString();
            newRow[127] = MAcolor.L.ToString();
            newRow[128] = MAcolor.U.ToString();
            newRow[129] = MAcolor.V.ToString();
            newRow[130] = MAcolor.UP.ToString();
            newRow[131] = MAcolor.VP.ToString();
            newRow[132] = MAcolor.LA.ToString();
            newRow[133] = MAcolor.A.ToString();
            newRow[134] = MAcolor.B.ToString();
            newRow[135] = acolorRGB.R.ToString();
            newRow[136] = acolorRGB.G.ToString();
            newRow[137] = acolorRGB.B.ToString();
            newRow[138] = MBradXYZ.X.ToString();
            newRow[139] = MBradXYZ.Y.ToString();
            newRow[140] = MBradXYZ.Z.ToString();
            newRow[141] = MBradcolor.L.ToString();
            newRow[142] = MBradcolor.U.ToString();
            newRow[143] = MBradcolor.V.ToString();
            newRow[144] = MBradcolor.UP.ToString();
            newRow[145] = MBradcolor.VP.ToString();
            newRow[146] = MBradcolor.LA.ToString();
            newRow[147] = MBradcolor.A.ToString();
            newRow[148] = MBradcolor.B.ToString();
            newRow[149] = MVonXYZ.X.ToString();
            newRow[150] = MVonXYZ.Y.ToString();
            newRow[151] = MVonXYZ.Z.ToString();
            newRow[152] = MVoncolor.L.ToString();
            newRow[153] = MVoncolor.U.ToString();
            newRow[154] = MVoncolor.V.ToString();
            newRow[155] = MVoncolor.UP.ToString();
            newRow[156] = MVoncolor.VP.ToString();
            newRow[157] = MVoncolor.LA.ToString();
            newRow[158] = MVoncolor.A.ToString();
            newRow[159] = MVoncolor.B.ToString();
            newRow[160] = MScalingXYZ.X.ToString();
            newRow[161] = MScalingXYZ.Y.ToString();
            newRow[162] = MScalingXYZ.Z.ToString();
            newRow[163] = MScalingcolor.L.ToString();
            newRow[164] = MScalingcolor.U.ToString();
            newRow[165] = MScalingcolor.V.ToString();
            newRow[166] = MScalingcolor.UP.ToString();
            newRow[167] = MScalingcolor.VP.ToString();
            newRow[168] = MScalingcolor.LA.ToString();
            newRow[169] = MScalingcolor.A.ToString();
            newRow[170] = MScalingcolor.B.ToString();
            newRow[171] = MBINcolorXYZ.X.ToString();
            newRow[172] = MBINcolorXYZ.Y.ToString();
            newRow[173] = MBINcolorXYZ.Z.ToString();
            newRow[174] = MBINColor.L.ToString();
            newRow[175] = MBINColor.U.ToString();
            newRow[176] = MBINColor.V.ToString();
            newRow[177] = MBINColor.UP.ToString();
            newRow[178] = MBINColor.VP.ToString();
            newRow[179] = MBINColor.LA.ToString();
            newRow[180] = MBINColor.A.ToString();
            newRow[181] = MBINColor.B.ToString();
            newRow[182] = DeltaA_Luv.ToString();
            newRow[183] = DeltaA_LAb.ToString();
            newRow[184] = DeltaBin_Luv.ToString();
            newRow[185] = DeltaBin_Lab.ToString();
            newRow[186] = DeltaB_luv.ToString();
            newRow[187] = DeltaB_Lab.ToString();
            newRow[188] = DeltaV_Luv.ToString();
            newRow[189] = DeltaV_Lab.ToString();
            newRow[190] = DeltaS_Luv.ToString();
            newRow[191] = DeltaS_Lab.ToString();
            newRow[192] = Util.CATCalulation.HueAngle(ColorMeasured).ToString();
            newRow[193] = Util.CATCalulation.HueAngle(Acolor).ToString();
            newRow[194] = Util.CATCalulation.HueAngle(MBINColor).ToString();

            dt_DataCollection.Rows.Add(newRow);

            R = 0; G = 0; B = 0;
            //dt.Rows.Add(newRow);

            //Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            //Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
              }

            }

            //double AvgBin,AvgA,Avgb,AvgV,Avgs,dbc,dc;
            //double sAvgBin, sAvgA, sAvgb, sAvgV, sAvgs;
            //AvgBin =0;
            //AvgA = 0;
            //Avgb = 0;
            //AvgV = 0;
            //Avgs = 0;
            //dbc = 0;
            //dc = 0;

            //sAvgBin = 0;
            //sAvgA = 0;
            //sAvgb = 0;
            //sAvgV = 0;
            //sAvgs = 0;
            //dbc = 0;
            //dc = 0;

            //for (int i = 0; i < BgNo * FgNo; i = i + FgNo)
            //{
            //  newRow = dt_DataCollection.NewRow();
            //  for (int j = i; j < i+FgNo; j++)
            //  {

            //    if (j == i)
            //    {
            //      AvgBin = Convert.ToDouble(dt_DataCollection.Rows[j][115].ToString());
            //      AvgA = Convert.ToDouble(dt_DataCollection.Rows[j][113].ToString());
            //      Avgb = Convert.ToDouble(dt_DataCollection.Rows[j][117].ToString());
            //      AvgV = Convert.ToDouble(dt_DataCollection.Rows[j][119].ToString());
            //      Avgs = Convert.ToDouble(dt_DataCollection.Rows[j][121].ToString());
            //      sAvgBin = Convert.ToDouble(dt_DataCollection.Rows[j][184].ToString());
            //      sAvgA = Convert.ToDouble(dt_DataCollection.Rows[j][182].ToString());
            //      sAvgb = Convert.ToDouble(dt_DataCollection.Rows[j][186].ToString());
            //      sAvgV = Convert.ToDouble(dt_DataCollection.Rows[j][188].ToString());
            //      sAvgs = Convert.ToDouble(dt_DataCollection.Rows[j][190].ToString());
            //      dbc = Convert.ToDouble(dt_DataCollection.Rows[j][122].ToString());
            //      dc=Convert.ToDouble(dt_DataCollection.Rows[j][123].ToString());
            //    }
            //    else
            //    {
            //      //AvgBin = AvgBin + Convert.ToDouble(dt_DataCollection.Rows[j][115].ToString());
            //      //AvgA = AvgA+ Convert.ToDouble(dt_DataCollection.Rows[j][113].ToString());
            //      //Avgb = Avgb+Convert.ToDouble(dt_DataCollection.Rows[j][117].ToString());
            //      //AvgV = AvgV+Convert.ToDouble(dt_DataCollection.Rows[j][119].ToString());
            //      //Avgs = Avgs+Convert.ToDouble(dt_DataCollection.Rows[j][121].ToString());
            //      //sAvgBin = sAvgBin + Convert.ToDouble(dt_DataCollection.Rows[j][184].ToString());
            //      //sAvgA   = sAvgA + Convert.ToDouble(dt_DataCollection.Rows[j][182].ToString());
            //      //sAvgb   = sAvgb + Convert.ToDouble(dt_DataCollection.Rows[j][186].ToString());
            //      //sAvgV   = sAvgV + Convert.ToDouble(dt_DataCollection.Rows[j][188].ToString());
            //      //sAvgs   = sAvgs + Convert.ToDouble(dt_DataCollection.Rows[j][190].ToString());
            //      //dbc = dbc+Convert.ToDouble(dt_DataCollection.Rows[j][122].ToString());
            //      //dc =dc+Convert.ToDouble(dt_DataCollection.Rows[j][123].ToString());
            //    }

            //  }

            //  newRow[1] = (AvgBin / FgNo).ToString();
            //  newRow[2] = (AvgA/ FgNo).ToString();
            //  newRow[3] = (Avgb/ FgNo).ToString();
            //  newRow[4] = (AvgV/ FgNo).ToString();
            //  newRow[5] = (Avgs/ FgNo).ToString();
            //  newRow[6] = (dbc / FgNo).ToString();
            //  newRow[7] = (dc / FgNo).ToString();
            //  newRow[8] = (sAvgBin/ FgNo).ToString();
            //  newRow[9] = (sAvgA/ FgNo).ToString();
            //  newRow[10] = (sAvgb/ FgNo).ToString();
            //  newRow[11] = (sAvgV/ FgNo).ToString();
            //  newRow[11] = (sAvgs/ FgNo).ToString();
            //  dt_DataCollection.Rows.Add(newRow);
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            //}

              });

              btn_ExportGrid.IsEnabled = true;
        }
コード例 #25
0
        public static CIEXYZ StartAVGMeasureXYZ2()
        {
            double x, x1, x2, x3, y, y1, y2, y3, z, z1, z2, z3, mux, muy, muz;

              CIEXYZ xyz1 = StartMeasureXYZ();
              CIEXYZ xyz2 = StartMeasureXYZ();
              // CIEXYZ xyz3 = StartMeasureXYZ();

              x = (double)((xyz1.X * 100) + (xyz2.X * 100)) / 2.0;
              y = (double)((xyz1.Y * 100) + (xyz2.Y * 100)) / 2.0;
              z = (double)((xyz1.Z * 100) + (xyz2.Z * 100)) / 2.0;

              x1 = Math.Pow((xyz1.X - x), 2);
              x2 = Math.Pow((xyz2.X - x), 2);
              //x3 = Math.Pow((xyz3.X - x), 2);

              y1 = Math.Pow((xyz1.Y - y), 2);
              y2 = Math.Pow((xyz2.Y - y), 2);
              //y3 = Math.Pow((xyz3.Y - y), 2);

              z1 = Math.Pow((xyz1.Z - z), 2);
              z2 = Math.Pow((xyz2.Z - z), 2);
              //z3 = Math.Pow((xyz3.Z - z), 2);

              mux = (x1 + x2) / 2;
              muy = (y1 + y2) / 2;
              muz = (z1 + z2) / 2;

              x = (double)((xyz1.X) + (xyz2.X)) / 2.0;
              y = (double)((xyz1.Y) + (xyz2.Y)) / 2.0;
              z = (double)((xyz1.Z) + (xyz2.Z)) / 2.0;

              CIEXYZ xyz = new CIEXYZ(x, y, z);
              xyz.stdx = Math.Sqrt(mux);
              xyz.stdy = Math.Sqrt(muy);
              xyz.stdz = Math.Sqrt(muz);

              return xyz;
        }
コード例 #26
0
        private void Btn_CSBasicCompensation_Encd_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;

              double X, Y, Z, DeltaA_Luv, DeltaA_LAb, DeltaBin_Luv, DeltaBin_Lab;
              double CDeltaA_Luv, CDeltaA_LAb, CDeltaBin_Luv, CDeltaBin_Lab;

              int binnumber = 0;
              int GammutRangeCheck1, GammutRangeCheck2, GammutRangeCheck3, GammutRangeCheck4;

              DataRow newRow;

              int connect = PerceptionLib.Cs200Connection.ConnectToCS200();

              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValueWtPt.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValueSet1.csv");
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValue.csv");
              DataTable dt_Bg = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_Bg = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BaseBinFile.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\BaseBinFile.csv");
              DataTable bin = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              double minLLevel = double.MaxValue;
              double maxLLevel = double.MinValue;
              double minALevel = double.MaxValue;
              double maxALevel = double.MinValue;
              double minBLevel = double.MaxValue;
              double maxBLevel = double.MinValue;

              double minL = double.MaxValue;
              double maxL = double.MinValue;
              double minA = double.MaxValue;
              double maxA = double.MinValue;
              double minB = double.MaxValue;
              double maxB = double.MinValue;

              foreach (DataRow dr in bin.Rows)
              {
            double accountLevel = dr.Field<double>("MLA");
            minLLevel = Math.Min(minLLevel, accountLevel);
            maxLLevel = Math.Max(maxLLevel, accountLevel);

            double ALevel = dr.Field<double>("MA");
            minALevel = Math.Min(minALevel, ALevel);
            maxALevel = Math.Max(maxALevel, ALevel);

            double BLevel = dr.Field<double>("MlaB");
            minBLevel = Math.Min(minBLevel, BLevel);
            maxBLevel = Math.Max(maxBLevel, BLevel);

            double account = dr.Field<double>("LA");
            minL = Math.Min(minL, account);
            maxL = Math.Max(maxL, account);

            double ALvl = dr.Field<double>("A");
            minA = Math.Min(minA, ALvl);
            maxA = Math.Max(maxA, ALvl);

            double BLvl = dr.Field<double>("LB");
            minB = Math.Min(minBLevel, BLvl);
            maxB = Math.Max(maxBLevel, BLvl);
              }

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\RGBgammut.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB88.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB8000Sorted.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\bigProjecor\RGB8000NotSorted.csv");
              DataTable dt_RGBGammut = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_RGBGammut = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              BgNo = dt_Bg.Rows.Count;
              FgNo = dt_RGBGammut.Rows.Count;

              //BgNo = 12;
             // FgNo = 100;
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\CsBasicCOMPENSATOR.csv");

              DataTable dt_DataCollection = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_DataCollection = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              ThreadPool.QueueUserWorkItem(ignored =>
              {
            PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();
            for (int i = 12; i < BgNo; i++)
            {

              for (int j = 11; j < FgNo; j = j + 20)
              {
            newRow = dt_DataCollection.NewRow();
            BgR = Convert.ToByte(dt_Bg.Rows[i][0].ToString());
            BgG = Convert.ToByte(dt_Bg.Rows[i][1].ToString());
            BgB = Convert.ToByte(dt_Bg.Rows[i][2].ToString());

            X = Convert.ToDouble(dt_Bg.Rows[i][3].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][4].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][5].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            R = Convert.ToByte(dt_RGBGammut.Rows[j][0].ToString());
            G = Convert.ToByte(dt_RGBGammut.Rows[j][1].ToString());
            B = Convert.ToByte(dt_RGBGammut.Rows[j][2].ToString());

            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(R, G, B));
            //  rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0));
            //}));

            //DisplayMeasuredValuesFromCs200();

            //ColorDifference = ColorMeasured;

            ////to measure the color mixture as well
            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  //rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(R, G, B));
            //  rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BgR, BgG, BgB));
            //}));

            //DisplayMeasuredValuesFromCs200();
            ////aclor is use tem for mixed color capture
            //acolorRGB = PerceptionLib.Color.ToRBGFromLAB(ColorMeasured);
            //newRow[132] = ColorMeasured.LA.ToString();
            //newRow[133] = ColorMeasured.A.ToString();
            //newRow[134] = ColorMeasured.B.ToString();
            //newRow[135] = acolorRGB.R.ToString();
            //newRow[136] = acolorRGB.G.ToString();
            //newRow[137] = acolorRGB.B.ToString();
            //newRow[138] = Util.CATCalulation.HueAngle(ColorMeasured).ToString();
            //newRow[139] = Util.CATCalulation.hueDifference(ColorMeasured, ColorDifference).ToString();

            //direct model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][11].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][12].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][13].ToString());
            AcolorXYZ = new CIEXYZ(X, Y, Z);

            Acolor = PerceptionLib.Color.ToLUV(AcolorXYZ);

            //adding XYZ values

            MAcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(AcolorXYZ, ColorBackGroundXYZ);

            //converting back to various spaces fpr color difference calculation

            MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);

            acolorRGB = PerceptionLib.Color.ToRBGFromLAB(MAcolor);

            newRow[0] = R;
            newRow[1] = G;
            newRow[2] = B;
            newRow[3] = dt_RGBGammut.Rows[j][3].ToString();
            newRow[4] = dt_RGBGammut.Rows[j][4].ToString();
            newRow[5] = dt_RGBGammut.Rows[j][5].ToString();
            newRow[6] = dt_RGBGammut.Rows[j][6].ToString();
            newRow[7] = dt_RGBGammut.Rows[j][7].ToString();
            newRow[8] = dt_RGBGammut.Rows[j][8].ToString();
            newRow[9] = dt_RGBGammut.Rows[j][9].ToString();
            newRow[10] = dt_RGBGammut.Rows[j][10].ToString();
            newRow[11] = dt_RGBGammut.Rows[j][11].ToString();
            newRow[12] = dt_RGBGammut.Rows[j][12].ToString();
            newRow[13] = dt_RGBGammut.Rows[j][13].ToString();
            newRow[14] = dt_RGBGammut.Rows[j][14].ToString();
            newRow[15] = dt_RGBGammut.Rows[j][15].ToString();
            newRow[16] = dt_RGBGammut.Rows[j][16].ToString();
            newRow[17] = dt_RGBGammut.Rows[j][17].ToString();
            newRow[18] = dt_RGBGammut.Rows[j][18].ToString();
            newRow[19] = dt_RGBGammut.Rows[j][19].ToString();
            newRow[20] = dt_RGBGammut.Rows[j][20].ToString();
            newRow[21] = dt_RGBGammut.Rows[j][21].ToString();
            newRow[22] = dt_RGBGammut.Rows[j][22].ToString();
            newRow[23] = dt_RGBGammut.Rows[j][23].ToString();
            newRow[24] = dt_RGBGammut.Rows[j][24].ToString();
            newRow[25] = BgR;
            newRow[26] = BgG;
            newRow[27] = BgB;
            newRow[28] = dt_Bg.Rows[i][3].ToString();
            newRow[29] = dt_Bg.Rows[i][4].ToString();
            newRow[30] = dt_Bg.Rows[i][5].ToString();
            newRow[31] = dt_Bg.Rows[i][6].ToString();
            newRow[32] = dt_Bg.Rows[i][7].ToString();
            newRow[33] = dt_Bg.Rows[i][8].ToString();
            newRow[34] = MAcolorXYZ.X.ToString();
            newRow[35] = MAcolorXYZ.Y.ToString();
            newRow[36] = MAcolorXYZ.Z.ToString();
            newRow[37] = MAcolor.LA.ToString();
            newRow[38] = MAcolor.A.ToString();
            newRow[39] = MAcolor.B.ToString();
            GammutRangeCheck1 = 1;

            if ((MAcolor.LA >= minL) & (MAcolor.LA <= maxL) & (MAcolor.A >= minA) & (MAcolor.A <= maxA) & (MAcolor.B >= minB) & (MAcolor.B <= maxB))
            {
              for (int index = 0; index < bin.Rows.Count; index++)
              {
                double tempL, tempA, tempB;
                tempL = Convert.ToDouble(bin.Rows[index][3].ToString());
                tempA = Convert.ToDouble(bin.Rows[index][4].ToString());
                tempB = Convert.ToDouble(bin.Rows[index][5].ToString());

                if ((MAcolor.LA >= tempL - 5) & (MAcolor.LA <= tempL + 5) & (MAcolor.A >= tempA - 5) & (MAcolor.A <= tempA + 5) & (MAcolor.B >= tempB - 5) & (MAcolor.B <= tempB + 5))
                {
                  GammutRangeCheck1 = 0;
                  break;
                }
                GammutRangeCheck1 = 1;
              }
            }
            else
              GammutRangeCheck1 = 1;

            newRow[40] = acolorRGB.R.ToString();
            newRow[41] = acolorRGB.G.ToString();
            newRow[42] = acolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BgR, BgG, BgB));
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(acolorRGB.R, acolorRGB.G, acolorRGB.B));
            }));

            DisplayMeasuredValuesFromCs200();

            acolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);

            newRow[43] = ColorMeasuredXYZ.X.ToString();
            newRow[44] = ColorMeasuredXYZ.Y.ToString();
            newRow[45] = ColorMeasuredXYZ.Z.ToString();
            newRow[46] = ColorMeasured.LA.ToString();
            newRow[47] = ColorMeasured.A.ToString();
            newRow[48] = ColorMeasured.B.ToString();
            newRow[49] = MR.ToString();
            newRow[50] = MG.ToString();
            newRow[51] = MB.ToString();

            ColorToShow.LA = Convert.ToDouble(dt_RGBGammut.Rows[j][19].ToString());
            ColorToShow.A = Convert.ToDouble(dt_RGBGammut.Rows[j][20].ToString());
            ColorToShow.B = Convert.ToDouble(dt_RGBGammut.Rows[j][21].ToString());

            // DeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(MAcolor, ColorMeasured);
            DeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            //CDeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            //X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            //Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            //Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            //ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            //MAcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(AcolorXYZ, ColorBackGroundXYZ);
            //MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);
            //acolorRGB = PerceptionLib.Color.ToRBGFromLAB(MAcolor);

            //newRow[52] = MAcolorXYZ.X.ToString();
            //newRow[53] = MAcolorXYZ.Y.ToString();
            //newRow[54] = MAcolorXYZ.Z.ToString();
            //newRow[55] = MAcolor.LA.ToString();
            //newRow[56] = MAcolor.A.ToString();
            //newRow[57] = MAcolor.B.ToString();
            //newRow[58] = acolorRGB.R.ToString();
            //newRow[59] = acolorRGB.G.ToString();
            //newRow[60] = acolorRGB.B.ToString();
            //GammutRangeCheck2 = 1;
            //if ((MAcolor.LA >= minL) & (MAcolor.LA <= maxL) & (MAcolor.A >= minA) & (MAcolor.A <= maxA) & (MAcolor.B >= minB) & (MAcolor.B <= maxB))
            //{
            //  for (int index = 0; index < bin.Rows.Count; index++)
            //  {
            //    double tempL, tempA, tempB;
            //    tempL = Convert.ToDouble(bin.Rows[index][3].ToString());
            //    tempA = Convert.ToDouble(bin.Rows[index][4].ToString());
            //    tempB = Convert.ToDouble(bin.Rows[index][5].ToString());

            //    if ((MAcolor.LA >= tempL - 5) & (MAcolor.LA <= tempL + 5) & (MAcolor.A >= tempA - 5) & (MAcolor.A <= tempA + 5) & (MAcolor.B >= tempB - 5) & (MAcolor.B <= tempB + 5))
            //    {
            //      GammutRangeCheck2 = 0;
            //      break;
            //    }
            //    GammutRangeCheck2 = 1;
            //  }
            //}
            //else
            //  GammutRangeCheck2 = 1;

            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(acolorRGB.R, acolorRGB.G, acolorRGB.B));
            //}));

            //DisplayMeasuredValuesFromCs200();

            //MacolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);

            //newRow[61] = ColorMeasuredXYZ.X.ToString();
            //newRow[62] = ColorMeasuredXYZ.Y.ToString();
            //newRow[63] = ColorMeasuredXYZ.Z.ToString();
            //newRow[64] = ColorMeasured.LA.ToString();
            //newRow[65] = ColorMeasured.A.ToString();
            //newRow[66] = ColorMeasured.B.ToString();
            //newRow[67] = MR.ToString();
            //newRow[68] = MG.ToString();
            //newRow[69] = MB.ToString();

            //newRow[131] = Util.CATCalulation.HueAngle(MAcolor);
            //// DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(MAcolor, ColorMeasured);
            //DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            //CDeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //bin model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][22].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][23].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][24].ToString());
            BINcolorXYZ = new CIEXYZ(X, Y, Z);
            BincolorRGB = new RGBValue();
            BINColor = PerceptionLib.Color.ToLUV(BINcolorXYZ);

            //MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BINcolorXYZ, ColorBackGroundXYZ);

            //MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);
            //GammutRangeCheck3 = 1;
            //if ((MBINColor.LA >= minLLevel) & (MBINColor.LA <= maxLLevel) & (MBINColor.A >= minALevel) & (MBINColor.A <= maxALevel) & (MBINColor.B >= minBLevel) & (MBINColor.B <= maxBLevel))
            //{
            //  for (int index = 0; index < bin.Rows.Count; index++)
            //  {
            //    double tempL, tempA, tempB;
            //    tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
            //    tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
            //    tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

            //    if ((MBINColor.LA >= tempL - 5) & (MBINColor.LA <= tempL + 5) & (MBINColor.A >= tempA - 5) & (MBINColor.A <= tempA + 5) & (MBINColor.B >= tempB - 5) & (MBINColor.B <= tempB + 5))
            //    {
            //      GammutRangeCheck3 = 0;
            //      break;
            //    }
            //    GammutRangeCheck3 = 1;
            //  }
            //}
            //else
            //  GammutRangeCheck3 = 1;

            //binnumber = Util.CATCalulation.MatchWithBinnedColors(MBINColor, bin, ColorBackGroundXYZ, BINColor);
            //newRow[124] = Util.CATCalulation.closestColorInsideTheBin.ToString();
            //newRow[125] = Util.CATCalulation.closestColorOnAddition.ToString();
            ////int binnum = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin);

            ////binnumber = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            //MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            //MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            //MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            //MBINColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            //MBINColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            //MBINColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            //BincolorRGB.R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            //BincolorRGB.G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            //BincolorRGB.B = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            //newRow[70] = MBINcolorXYZ.X.ToString();
            //newRow[71] = MBINcolorXYZ.Y.ToString();
            //newRow[72] = MBINcolorXYZ.Z.ToString();
            //newRow[73] = MBINColor.LA.ToString();
            //newRow[74] = MBINColor.A.ToString();
            //newRow[75] = MBINColor.B.ToString();
            //newRow[76] = BincolorRGB.R.ToString();
            //newRow[77] = BincolorRGB.G.ToString();
            //newRow[78] = BincolorRGB.B.ToString();

            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B));
            //}));

            //DisplayMeasuredValuesFromCs200();
            //BincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            //newRow[79] = ColorMeasuredXYZ.X.ToString();
            //newRow[80] = ColorMeasuredXYZ.Y.ToString();
            //newRow[81] = ColorMeasuredXYZ.Z.ToString();
            //newRow[82] = ColorMeasured.LA.ToString();
            //newRow[83] = ColorMeasured.A.ToString();
            //newRow[84] = ColorMeasured.B.ToString();
            //newRow[85] = MR.ToString();
            //newRow[86] = MG.ToString();
            //newRow[87] = MB.ToString();

            ////DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(MBINColor, ColorMeasured);
            //DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            //CDeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BINcolorXYZ, ColorBackGroundXYZ);
            MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);
            BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(MBINColor);

            newRow[140] = MBINColor.LA.ToString();
            newRow[141] = MBINColor.A.ToString();
            newRow[142] = MBINColor.B.ToString();

            binnumber = Util.CATCalulation.MatchWithBinnedColors(MBINColor, bin, ColorBackGroundXYZ, BINColor);
            newRow[126] = Util.CATCalulation.closestColorInsideTheBin.ToString();
            newRow[127] = Util.CATCalulation.closestColorOnAddition.ToString();
            GammutRangeCheck4 = 1;

            newRow[143] = Util.CATCalulation.ClosestL.ToString();
            newRow[144] = Util.CATCalulation.ClosestA.ToString();
            newRow[145] = Util.CATCalulation.ClosestB.ToString();

            if ((MBINColor.LA >= minLLevel) & (MBINColor.LA <= maxLLevel) & (MBINColor.A >= minALevel) & (MBINColor.A <= maxALevel) & (MBINColor.B >= minBLevel) & (MBINColor.B <= maxBLevel))
            {
              for (int index = 0; index < bin.Rows.Count; index++)
              {
                double tempL, tempA, tempB;
                tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
                tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
                tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

                if ((MBINColor.LA >= tempL - 5) & (MBINColor.LA <= tempL + 5) & (MBINColor.A >= tempA - 5) & (MBINColor.A <= tempA + 5) & (MBINColor.B >= tempB - 5) & (MBINColor.B <= tempB + 5))
                {
                  GammutRangeCheck4 = 0;
                  break;
                }
                GammutRangeCheck4 = 1;
              }

            }
            else
              GammutRangeCheck4 = 1;
            //
            //binnumber = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            MBINColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            MBINColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            MBINColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            BincolorRGB.R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            BincolorRGB.G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            BincolorRGB.B = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            newRow[88] = MBINcolorXYZ.X.ToString();
            newRow[89] = MBINcolorXYZ.Y.ToString();
            newRow[90] = MBINcolorXYZ.Z.ToString();
            newRow[91] = MBINColor.LA.ToString();
            newRow[92] = MBINColor.A.ToString();
            newRow[93] = MBINColor.B.ToString();
            newRow[94] = BincolorRGB.R.ToString();
            newRow[95] = BincolorRGB.G.ToString();
            newRow[96] = BincolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B));
            }));

            DisplayMeasuredValuesFromCs200();

            MBincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            newRow[97] = ColorMeasuredXYZ.X.ToString();
            newRow[98] = ColorMeasuredXYZ.Y.ToString();
            newRow[99] = ColorMeasuredXYZ.Z.ToString();
            newRow[100] = ColorMeasured.LA.ToString();
            newRow[101] = ColorMeasured.A.ToString();
            newRow[102] = ColorMeasured.B.ToString();
            newRow[103] = MR.ToString();
            newRow[104] = MG.ToString();
            newRow[105] = MB.ToString();
            newRow[160] = Util.CATCalulation.HueAngle(ColorMeasured);

            newRow[122] = binnumber.ToString();

            //DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(MBINColor, ColorMeasured);
            DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            //CDeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////color with closest hue

            //MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BinXYZ, ColorBackGroundXYZ);
            //MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);
            //BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(MBINColor);

            //binnumber = Util.CATCalulation.MatchWithBinnedColorsWithHue(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            //if ((MBINColor.LA >= minLLevel) & (MBINColor.LA <= maxLLevel) & (MBINColor.A >= minALevel) & (MBINColor.A <= maxALevel) & (MBINColor.B >= minBLevel) & (MBINColor.B <= maxBLevel))
            //{
            //  for (int index = 0; index < bin.Rows.Count; index++)
            //  {
            //    double tempL, tempA, tempB;
            //    tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
            //    tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
            //    tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

            //    if ((MBINColor.LA >= tempL - 5) & (MBINColor.LA <= tempL + 5) & (MBINColor.A >= tempA - 5) & (MBINColor.A <= tempA + 5) & (MBINColor.B >= tempB - 5) & (MBINColor.B <= tempB + 5))
            //    {
            //      GammutRangeCheck4 = 0;
            //      break;
            //    }
            //    GammutRangeCheck4 = 1;
            //  }

            //}
            //else
            //  GammutRangeCheck4 = 1;
            ////
            ////binnumber = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            //MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            //MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            //MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            //MBINColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            //MBINColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            //MBINColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            //BincolorRGB.R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            //BincolorRGB.G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            //BincolorRGB.B = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            //newRow[146] = MBINColor.LA.ToString();
            //newRow[147] = MBINColor.A.ToString();
            //newRow[148] = MBINColor.B.ToString();
            //newRow[149] = BincolorRGB.R.ToString();
            //newRow[150] = BincolorRGB.G.ToString();
            //newRow[151] = BincolorRGB.B.ToString();

            //Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            //{
            //  rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B));
            //}));

            //DisplayMeasuredValuesFromCs200();

            //MBincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            //newRow[123] = binnumber.ToString();

            //newRow[152] = ColorMeasured.LA.ToString();
            //newRow[153] = ColorMeasured.A.ToString();
            //newRow[154] = ColorMeasured.B.ToString();
            //newRow[155] = MR.ToString();
            //newRow[156] = MG.ToString();
            //newRow[157] = MB.ToString();
            //newRow[158] = Util.CATCalulation.HueAngle(ColorMeasured).ToString();

            ////DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(MBINColor, ColorMeasured);

            //newRow[159] = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured).ToString();
            ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            newRow[106] = DeltaA_Luv.ToString();
            //newRow[107] = DeltaA_LAb.ToString();
            //newRow[108] = DeltaBin_Luv.ToString();
            newRow[109] = DeltaBin_Lab.ToString();
            newRow[110] = GammutRangeCheck1.ToString();
            //newRow[111] = GammutRangeCheck2.ToString();
            //newRow[112] = GammutRangeCheck3.ToString();
            newRow[113] = GammutRangeCheck4.ToString();
            //newRow[114] = CDeltaA_Luv.ToString();
            //newRow[115] = CDeltaA_LAb.ToString();
            //newRow[116] = CDeltaBin_Luv.ToString();
            //newRow[117] = CDeltaBin_Lab.ToString();
            //newRow[118] = ColorDifference.LA.ToString();
            //newRow[119] = ColorDifference.A.ToString();
            //newRow[120] = ColorDifference.B.ToString();
            ////newRow[122] = binnumber.ToString();
            ////newRow[123] = binnum.ToString();
            //newRow[121] = (PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorToShow)).ToString();
            newRow[128] = Util.CATCalulation.HueAngeDifference.ToString();
            newRow[129] = Util.CATCalulation.HueAngle(ColorToShow).ToString();
            newRow[130] = Util.CATCalulation.HueAngle(ColorMeasured).ToString();
            dt_DataCollection.Rows.Add(newRow);

            R = 0; G = 0; B = 0;

            //Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            //Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
              }

            }
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              });

              btn_ExportGrid.IsEnabled = true;
        }
コード例 #27
0
        private void PhoneCompensation_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;

            double X, Y, Z;

            int binnumber = 0;
            int GammutRangeCheck3, GammutRangeCheck4;

            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\phone\BaseBinFile.csv");
            DataTable bin = new DataTable();
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                dtgrid_corrDisplay.Items.Refresh();
                bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

            }));

            double minLLevel = double.MaxValue;
            double maxLLevel = double.MinValue;
            double minALevel = double.MaxValue;
            double maxALevel = double.MinValue;
            double minBLevel = double.MaxValue;
            double maxBLevel = double.MinValue;

            double minL = double.MaxValue;
            double maxL = double.MinValue;
            double minA = double.MaxValue;
            double maxA = double.MinValue;
            double minB = double.MaxValue;
            double maxB = double.MinValue;

            foreach (DataRow dr in bin.Rows)
            {
                double accountLevel = dr.Field<double>("MLA");
                minLLevel = Math.Min(minLLevel, accountLevel);
                maxLLevel = Math.Max(maxLLevel, accountLevel);

                double ALevel = dr.Field<double>("MA");
                minALevel = Math.Min(minALevel, ALevel);
                maxALevel = Math.Max(maxALevel, ALevel);

                double BLevel = dr.Field<double>("MlaB");
                minBLevel = Math.Min(minBLevel, BLevel);
                maxBLevel = Math.Max(maxBLevel, BLevel);

                double account = dr.Field<double>("LA");
                minL = Math.Min(minL, account);
                maxL = Math.Max(maxL, account);

                double ALvl = dr.Field<double>("A");
                minA = Math.Min(minA, ALvl);
                maxA = Math.Max(maxA, ALvl);

                double BLvl = dr.Field<double>("LB");
                minB = Math.Min(minBLevel, BLvl);
                maxB = Math.Max(maxBLevel, BLvl);
            }

            RGBValue BincolorRGB = new RGBValue();

            CIEXYZ BINCOLOR = new CIEXYZ(0, 0, 0);
            CIEXYZ BgND = new CIEXYZ(0, 0, 0);
            CIEXYZ BgTD = new CIEXYZ(0, 0, 0);
            CIEXYZ BP_TD = new CIEXYZ(0, 0, 0);
            CIEXYZ BP_ND = new CIEXYZ(0, 0, 0);

            CIEXYZ MBgND = new CIEXYZ(0, 0, 0);
            CIEXYZ MBgTD = new CIEXYZ(0, 0, 0);
            CIEXYZ MBP_TD = new CIEXYZ(0, 0, 0);
            CIEXYZ MBP_ND = new CIEXYZ(0, 0, 0);

            PerceptionLib.Color BINColor;
            PerceptionLib.Color BINTDColor;
            PerceptionLib.Color BINNDColor;

            PerceptionLib.Color MBINColor;
            PerceptionLib.Color MBINTDColor;
            PerceptionLib.Color MBINNDColor;

            //FgNo = 400;
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\PerceptionLib\bin\previous data\cs-200 data\color compensation\phone input\17bg_ip.csv");

            DataTable dt_DataCollection = new DataTable();
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                dtgrid_corrDisplay.Items.Refresh();
                dt_DataCollection = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
            }));

            {
                PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();

                foreach (DataRow dr in dt_DataCollection.Rows)
                {

                    X = Convert.ToDouble(dr["BGX"].ToString());
                    Y = Convert.ToDouble(dr["BGY"].ToString());
                    Z = Convert.ToDouble(dr["BGZ"].ToString());

                    BgND = new CIEXYZ(X, Y, Z);

                    X = Convert.ToDouble(dr["BGsX"].ToString());
                    Y = Convert.ToDouble(dr["BGsY"].ToString());
                    Z = Convert.ToDouble(dr["BGsZ"].ToString());

                    BgTD = new CIEXYZ(X, Y, Z);

                    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                    //bin model
                    X = Convert.ToDouble(dr["Mx"].ToString());
                    Y = Convert.ToDouble(dr["My"].ToString());
                    Z = Convert.ToDouble(dr["Mz"].ToString());
                    BINCOLOR = new CIEXYZ(X, Y, Z);
                    BincolorRGB = new RGBValue();
                    BINColor = new PerceptionLib.Color();

                    BINColor.LA = Convert.ToDouble(dr["Ml"].ToString());
                    BINColor.A = Convert.ToDouble(dr["Ma"].ToString());
                    BINColor.B = Convert.ToDouble(dr["Mlb"].ToString());

                    MBP_ND = ColorSpaceConverter.SubtractXYZ(BINCOLOR, BgND);

                    MBINNDColor = PerceptionLib.Color.ToLUV(MBP_ND);

                    dr["ComS_Fg_L"] = MBINNDColor.LA.ToString();
                    dr["ComS_Fg_a"] = MBINNDColor.A.ToString();
                    dr["ComS_Fg_b"] = MBINNDColor.B.ToString();
                    GammutRangeCheck3 = 1;
                    if ((MBINNDColor.LA >= minLLevel) & (MBINNDColor.LA <= maxLLevel) & (MBINNDColor.A >= minALevel) & (MBINNDColor.A <= maxALevel) & (MBINNDColor.B >= minBLevel) & (MBINNDColor.B <= maxBLevel))
                    {
                        for (int index = 0; index < bin.Rows.Count; index++)
                        {
                            double tempL, tempA, tempB;
                            tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
                            tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
                            tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

                            if ((MBINNDColor.LA >= tempL - 5) & (MBINNDColor.LA <= tempL + 5) & (MBINNDColor.A >= tempA - 5) & (MBINNDColor.A <= tempA + 5) & (MBINNDColor.B >= tempB - 5) & (MBINNDColor.B <= tempB + 5))
                            {
                                GammutRangeCheck3 = 0;
                                break;
                            }
                            GammutRangeCheck3 = 1;
                        }
                    }
                    else
                        GammutRangeCheck3 = 1;

                    binnumber = CATCalulation.MatchWithBinnedColors(MBINNDColor, bin, BgND, BINColor);

                    BINNDColor = new PerceptionLib.Color();
                    BINNDColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
                    BINNDColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
                    BINNDColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());

                    dr["Com_Fg_L"] = BINNDColor.LA.ToString();
                    dr["Com_Fg_a"] = BINNDColor.A.ToString();
                    dr["Com_Fg_b"] = BINNDColor.B.ToString();

                    BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(BINNDColor);
                    string Hex = PerceptionLib.Color.RGBtoHEX(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B);
                    dr["Com_HEX"] = "0x" + Hex;

                    dr["GammutFlag"] = GammutRangeCheck3.ToString();

                    MBP_TD = ColorSpaceConverter.SubtractXYZ(BINCOLOR, BgTD);

                    MBINTDColor = PerceptionLib.Color.ToLUV(MBP_TD);
                    dr["TDComS_Fg_L"] = MBINNDColor.LA.ToString();
                    dr["TDComS_Fg_a"] = MBINNDColor.A.ToString();
                    dr["TDComS_Fg_b"] = MBINNDColor.B.ToString();
                    GammutRangeCheck4 = 1;
                    if ((MBINTDColor.LA >= minLLevel) & (MBINTDColor.LA <= maxLLevel) & (MBINTDColor.A >= minALevel) & (MBINTDColor.A <= maxALevel) & (MBINTDColor.B >= minBLevel) & (MBINTDColor.B <= maxBLevel))
                    {
                        for (int index = 0; index < bin.Rows.Count; index++)
                        {
                            double tempL, tempA, tempB;
                            tempL = Convert.ToDouble(bin.Rows[index][9].ToString());
                            tempA = Convert.ToDouble(bin.Rows[index][10].ToString());
                            tempB = Convert.ToDouble(bin.Rows[index][11].ToString());

                            if ((MBINTDColor.LA >= tempL - 5) & (MBINTDColor.LA <= tempL + 5) & (MBINTDColor.A >= tempA - 5) & (MBINTDColor.A <= tempA + 5) & (MBINTDColor.B >= tempB - 5) & (MBINTDColor.B <= tempB + 5))
                            {
                                GammutRangeCheck4 = 0;
                                break;
                            }
                            GammutRangeCheck4 = 1;
                        }
                    }
                    else
                        GammutRangeCheck4 = 1;

                    binnumber = CATCalulation.MatchWithBinnedColors(MBINTDColor, bin, BgND, BINColor);
                    BINTDColor = new PerceptionLib.Color();

                    BINTDColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
                    BINTDColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
                    BINTDColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());

                    dr["TDCom_Fg_L"] = BINTDColor.LA.ToString();
                    dr["TDCom_Fg_a"] = BINTDColor.A.ToString();
                    dr["TDCom_Fg_b"] = BINTDColor.B.ToString();

                    BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(BINTDColor);
                    Hex = PerceptionLib.Color.RGBtoHEX(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B);
                    dr["TDCom_HEX"] = "0x" + Hex;

                    dr["TDGammutFlag"] = GammutRangeCheck4.ToString();
                }

            }
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

            btn_ExportGrid.IsEnabled = true;
        }
コード例 #28
0
        private void Btn_CSCompensation_Click(object sender, RoutedEventArgs e)
        {
            dtgrid_corrDisplay.IsEnabled = true;
              btn_StartMeasurment.IsEnabled = false;
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;

              double X, Y, Z, DeltaA_Luv, DeltaA_LAb, DeltaBin_Luv, DeltaBin_Lab, DeltaB_luv, DeltaB_Lab, DeltaS_Luv, DeltaS_Lab, DeltaV_Luv, DeltaV_Lab, DeltaC, BinDeltaC;
              double CDeltaA_Luv, CDeltaA_LAb, CDeltaBin_Luv, CDeltaBin_Lab, CDeltaB_luv, CDeltaB_Lab, CDeltaS_Luv, CDeltaS_Lab, CDeltaV_Luv, CDeltaV_Lab;

              int binnumber = 0;
              DataRow newRow;

              int connect = PerceptionLib.Cs200Connection.ConnectToCS200();

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValue.csv");
              //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BgValueSet1.csv");
              DataTable dt_Bg = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_Bg = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\BaseBinFile.csv");
              DataTable bin = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              }));

              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\RGBgammut.csv");
              DataTable dt_RGBGammut = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_RGBGammut = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              BgNo = dt_Bg.Rows.Count;
              FgNo = dt_RGBGammut.Rows.Count;

              BgNo = 4;
              //FgNo = 2;
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\CscOMPENSATOR.csv");
              DataTable dt_DataCollection = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            dt_DataCollection = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              ThreadPool.QueueUserWorkItem(ignored =>
              {
            PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();
            for (int i = 0; i < BgNo; i++)
            {

              for (int j = 1; j < FgNo; j=j+20)
              {
            BgR = Convert.ToByte(dt_Bg.Rows[i][0].ToString());
            BgG = Convert.ToByte(dt_Bg.Rows[i][1].ToString());
            BgB = Convert.ToByte(dt_Bg.Rows[i][2].ToString());

            X = Convert.ToDouble(dt_Bg.Rows[i][3].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][4].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][5].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            R = Convert.ToByte(dt_RGBGammut.Rows[j][0].ToString());
            G = Convert.ToByte(dt_RGBGammut.Rows[j][1].ToString());
            B = Convert.ToByte(dt_RGBGammut.Rows[j][2].ToString());

            //cat model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][25].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][26].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][27].ToString());
            BradXYZ = new CIEXYZ(X, Y, Z);

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(R, G, B));
              rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0, 0, 0));
            }));

            DisplayMeasuredValuesFromCs200();

            ColorDifference = ColorMeasured;

            X = Convert.ToDouble(dt_RGBGammut.Rows[j][28].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][29].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][30].ToString());
            VonXYZ = new CIEXYZ(X, Y, Z);

            X = Convert.ToDouble(dt_RGBGammut.Rows[j][31].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][32].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][33].ToString());
            ScalingXYZ = new CIEXYZ(X, Y, Z);

            //direct model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][11].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][12].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][13].ToString());
            AcolorXYZ = new CIEXYZ(X, Y, Z);

            Acolor = PerceptionLib.Color.ToLUV(AcolorXYZ);

            //bin model
            X = Convert.ToDouble(dt_RGBGammut.Rows[j][22].ToString());
            Y = Convert.ToDouble(dt_RGBGammut.Rows[j][23].ToString());
            Z = Convert.ToDouble(dt_RGBGammut.Rows[j][24].ToString());
            BINcolorXYZ = new CIEXYZ(X, Y, Z);

            BINColor = PerceptionLib.Color.ToLUV(BINcolorXYZ);

            //adding XYZ values
            MBradXYZ = Util.ColorSpaceConverter.SubtractXYZ(BradXYZ, ColorBackGroundXYZ);
            MScalingXYZ = Util.ColorSpaceConverter.SubtractXYZ(ScalingXYZ, ColorBackGroundXYZ);
            MVonXYZ = Util.ColorSpaceConverter.SubtractXYZ(VonXYZ, ColorBackGroundXYZ);
            MAcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(AcolorXYZ, ColorBackGroundXYZ);
            MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BINcolorXYZ, ColorBackGroundXYZ);

            //converting back to various spaces fpr color difference calculation
            MBradcolor = PerceptionLib.Color.ToLUV(MBradXYZ);
            MVoncolor = PerceptionLib.Color.ToLUV(MVonXYZ);
            MScalingcolor = PerceptionLib.Color.ToLUV(MScalingXYZ);
            MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);
            MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);

            bradRGB = PerceptionLib.Color.ToRBGFromLAB(MBradcolor);
            VonRGB = PerceptionLib.Color.ToRBGFromLAB(MVoncolor);
            scalingRGB = PerceptionLib.Color.ToRBGFromLAB(MScalingcolor);
            acolorRGB = PerceptionLib.Color.ToRBGFromLAB(MAcolor);
            BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(MBINColor);

            newRow = dt_DataCollection.NewRow();
            newRow[0] = R;
            newRow[1] = G;
            newRow[2] = B;
            newRow[3] = dt_RGBGammut.Rows[j][3].ToString();
            newRow[4] = dt_RGBGammut.Rows[j][4].ToString();
            newRow[5] = dt_RGBGammut.Rows[j][5].ToString();
            newRow[6] = dt_RGBGammut.Rows[j][6].ToString();
            newRow[7] = dt_RGBGammut.Rows[j][7].ToString();
            newRow[8] = dt_RGBGammut.Rows[j][8].ToString();
            newRow[9] = dt_RGBGammut.Rows[j][9].ToString();
            newRow[10] = dt_RGBGammut.Rows[j][10].ToString();
            newRow[11] = dt_RGBGammut.Rows[j][11].ToString();
            newRow[12] = dt_RGBGammut.Rows[j][12].ToString();
            newRow[13] = dt_RGBGammut.Rows[j][13].ToString();
            newRow[14] = dt_RGBGammut.Rows[j][14].ToString();
            newRow[15] = dt_RGBGammut.Rows[j][15].ToString();
            newRow[16] = dt_RGBGammut.Rows[j][16].ToString();
            newRow[17] = dt_RGBGammut.Rows[j][17].ToString();
            newRow[18] = dt_RGBGammut.Rows[j][18].ToString();
            newRow[19] = dt_RGBGammut.Rows[j][19].ToString();
            newRow[20] = dt_RGBGammut.Rows[j][20].ToString();
            newRow[21] = dt_RGBGammut.Rows[j][21].ToString();
            newRow[22] = dt_RGBGammut.Rows[j][22].ToString();
            newRow[23] = dt_RGBGammut.Rows[j][23].ToString();
            newRow[24] = dt_RGBGammut.Rows[j][24].ToString();
            newRow[25] = dt_RGBGammut.Rows[j][25].ToString();
            newRow[26] = dt_RGBGammut.Rows[j][26].ToString();
            newRow[27] = dt_RGBGammut.Rows[j][27].ToString();
            newRow[28] = dt_RGBGammut.Rows[j][28].ToString();
            newRow[29] = dt_RGBGammut.Rows[j][29].ToString();
            newRow[30] = dt_RGBGammut.Rows[j][30].ToString();
            newRow[31] = dt_RGBGammut.Rows[j][31].ToString();
            newRow[32] = dt_RGBGammut.Rows[j][32].ToString();
            newRow[33] = dt_RGBGammut.Rows[j][33].ToString();
            newRow[34] = BgR;
            newRow[35] = BgG;
            newRow[36] = BgB;
            newRow[37] = dt_Bg.Rows[i][3].ToString();
            newRow[38] = dt_Bg.Rows[i][4].ToString();
            newRow[39] = dt_Bg.Rows[i][5].ToString();
            newRow[40] = dt_Bg.Rows[i][6].ToString();
            newRow[41] = dt_Bg.Rows[i][7].ToString();
            newRow[42] = dt_Bg.Rows[i][8].ToString();

            newRow[43] = MAcolorXYZ.X.ToString();
            newRow[44] = MAcolorXYZ.Y.ToString();
            newRow[45] = MAcolorXYZ.Z.ToString();
            newRow[46] = MAcolor.LA.ToString();
            newRow[47] = MAcolor.A.ToString();
            newRow[48] = MAcolor.B.ToString();
            newRow[49] = acolorRGB.R.ToString();
            newRow[50] = acolorRGB.G.ToString();
            newRow[51] = acolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_BgColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BgR, BgG, BgB));
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(acolorRGB.R, acolorRGB.G, acolorRGB.B));
            }));

            DisplayMeasuredValuesFromCs200();

            acolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);

            newRow[52] = ColorMeasuredXYZ.X.ToString();
            newRow[53] = ColorMeasuredXYZ.Y.ToString();
            newRow[54] = ColorMeasuredXYZ.Z.ToString();
            newRow[55] = ColorMeasured.LA.ToString();
            newRow[56] = ColorMeasured.A.ToString();
            newRow[57] = ColorMeasured.B.ToString();
            newRow[58] = MR.ToString();
            newRow[59] = MG.ToString();
            newRow[60] = MB.ToString();

            ColorToShow.LA =Convert.ToDouble( dt_RGBGammut.Rows[j][19].ToString());
            ColorToShow.A = Convert.ToDouble( dt_RGBGammut.Rows[j][20].ToString());
            ColorToShow.B = Convert.ToDouble( dt_RGBGammut.Rows[j][21].ToString());

               // DeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(MAcolor, ColorMeasured);
            DeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            CDeltaA_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            MAcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(AcolorXYZ, ColorBackGroundXYZ);
            MAcolor = PerceptionLib.Color.ToLUV(MAcolorXYZ);
            acolorRGB = PerceptionLib.Color.ToRBGFromLAB(MAcolor);

            newRow[61] = MAcolorXYZ.X.ToString();
            newRow[62] = MAcolorXYZ.Y.ToString();
            newRow[63] = MAcolorXYZ.Z.ToString();
            newRow[64] = MAcolor.LA.ToString();
            newRow[65] = MAcolor.A.ToString();
            newRow[66] = MAcolor.B.ToString();
            newRow[67] = acolorRGB.R.ToString();
            newRow[68] = acolorRGB.G.ToString();
            newRow[69] = acolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(acolorRGB.R, acolorRGB.G, acolorRGB.B));
             }));

            DisplayMeasuredValuesFromCs200();

            MacolorRGB = PerceptionLib.Color.ToRBG(MAcolorXYZ);

            newRow[70] = ColorMeasuredXYZ.X.ToString();
            newRow[71] = ColorMeasuredXYZ.Y.ToString();
            newRow[72] = ColorMeasuredXYZ.Z.ToString();
            newRow[73] = ColorMeasured.LA.ToString();
            newRow[74] = ColorMeasured.A.ToString();
            newRow[75] = ColorMeasured.B.ToString();
            newRow[76] = MR.ToString();
            newRow[77] = MG.ToString();
            newRow[78] = MB.ToString();

               // DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(MAcolor, ColorMeasured);
            DeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            CDeltaA_LAb = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////brad color
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

               // newRow[79] = MBradXYZ.X.ToString();
               // newRow[80] = MBradXYZ.Y.ToString();
               // newRow[81] = MBradXYZ.Z.ToString();
               // newRow[82] = MBradcolor.LA.ToString();
               // newRow[83] = MBradcolor.A.ToString();
               // newRow[84] = MBradcolor.B.ToString();
               // newRow[85] = bradRGB.R.ToString();
               // newRow[86] = bradRGB.G.ToString();
               // newRow[87] = bradRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {

               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(bradRGB.R, bradRGB.G, bradRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();
               // bradRGB = PerceptionLib.Color.ToRBG(MBradXYZ);

               // newRow[88] = ColorMeasuredXYZ.X.ToString();
               // newRow[89] = ColorMeasuredXYZ.Y.ToString();
               // newRow[90] = ColorMeasuredXYZ.Z.ToString();
               // newRow[91] = ColorMeasured.LA.ToString();
               // newRow[92] = ColorMeasured.A.ToString();
               // newRow[93] = ColorMeasured.B.ToString();
               // newRow[94] = MR.ToString();
               // newRow[95] = MG.ToString();
               // newRow[96] = MB.ToString();

               // //DeltaB_luv = PerceptionLib.Color.ColorDistanceCalAB(MBradcolor, ColorMeasured);
               // DeltaB_luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaB_luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

               // X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
               // Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
               // Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

               // ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

               // MBradXYZ = Util.ColorSpaceConverter.SubtractXYZ(BradXYZ, ColorBackGroundXYZ);
               // MBradcolor = PerceptionLib.Color.ToLUV(MBradXYZ);
               // bradRGB = PerceptionLib.Color.ToRBGFromLAB(MBradcolor);

               // newRow[97] = MBradXYZ.X.ToString();
               // newRow[98] = MBradXYZ.Y.ToString();
               // newRow[99] = MBradXYZ.Z.ToString();
               // newRow[100] = MBradcolor.LA.ToString();
               // newRow[101] = MBradcolor.A.ToString();
               // newRow[102] = MBradcolor.B.ToString();
               // newRow[103] = bradRGB.R.ToString();
               // newRow[104] = bradRGB.G.ToString();
               // newRow[105] = bradRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {
               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(bradRGB.R, bradRGB.G, bradRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();

               // MbradRGB = PerceptionLib.Color.ToRBG(MBradXYZ);

               // newRow[106] = ColorMeasuredXYZ.X.ToString();
               // newRow[107] = ColorMeasuredXYZ.Y.ToString();
               // newRow[108] = ColorMeasuredXYZ.Z.ToString();
               // newRow[109] = ColorMeasured.LA.ToString();
               // newRow[110] = ColorMeasured.A.ToString();
               // newRow[111] = ColorMeasured.B.ToString();
               // newRow[112] = MR.ToString();
               // newRow[113] = MG.ToString();
               // newRow[114] = MB.ToString();

               // //DeltaB_Lab = PerceptionLib.Color.ColorDistanceCalAB(MBradcolor, ColorMeasured);
               // DeltaB_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaB_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

               // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
               // ////Von color
               // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

               // newRow[115] = MVonXYZ.X.ToString();
               // newRow[116] = MVonXYZ.Y.ToString();
               // newRow[117] = MVonXYZ.Z.ToString();
               // newRow[118] = MVoncolor.LA.ToString();
               // newRow[119] = MVoncolor.A.ToString();
               // newRow[120] = MVoncolor.B.ToString();
               // newRow[121] = VonRGB.R.ToString();
               // newRow[122] = VonRGB.G.ToString();
               // newRow[123] = VonRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {
               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(VonRGB.R, VonRGB.G, VonRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();

               // VonRGB = PerceptionLib.Color.ToRBG(MVonXYZ);

               // newRow[124] = ColorMeasuredXYZ.X.ToString();
               // newRow[125] = ColorMeasuredXYZ.Y.ToString();
               // newRow[126] = ColorMeasuredXYZ.Z.ToString();
               // newRow[127] = ColorMeasured.LA.ToString();
               // newRow[128] = ColorMeasured.A.ToString();
               // newRow[129] = ColorMeasured.B.ToString();
               // newRow[130] = MR.ToString();
               // newRow[131] = MG.ToString();
               // newRow[132] = MB.ToString();

               //// DeltaV_Luv = PerceptionLib.Color.ColorDistanceCalAB(MVoncolor, ColorMeasured);
               // DeltaV_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaV_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

               // X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
               // Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
               // Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

               // ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

               // MVonXYZ = Util.ColorSpaceConverter.SubtractXYZ(VonXYZ, ColorBackGroundXYZ);
               // MVoncolor = PerceptionLib.Color.ToLUV(MVonXYZ);
               // VonRGB = PerceptionLib.Color.ToRBGFromLAB(MVoncolor);

               // newRow[133] = MVonXYZ.X.ToString();
               // newRow[134] = MVonXYZ.Y.ToString();
               // newRow[135] = MVonXYZ.Z.ToString();
               // newRow[136] = MVoncolor.LA.ToString();
               // newRow[137] = MVoncolor.A.ToString();
               // newRow[138] = MVoncolor.B.ToString();
               // newRow[139] = VonRGB.R.ToString();
               // newRow[140] = VonRGB.G.ToString();
               // newRow[141] = VonRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {
               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(VonRGB.R, VonRGB.G, VonRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();

               // MVonRGB = PerceptionLib.Color.ToRBG(MVonXYZ);

               // newRow[142] = ColorMeasuredXYZ.X.ToString();
               // newRow[143] = ColorMeasuredXYZ.Y.ToString();
               // newRow[144] = ColorMeasuredXYZ.Z.ToString();
               // newRow[145] = ColorMeasured.LA.ToString();
               // newRow[146] = ColorMeasured.A.ToString();
               // newRow[147] = ColorMeasured.B.ToString();
               // newRow[148] = MR.ToString();
               // newRow[149] = MG.ToString();
               // newRow[150] = MB.ToString();

               // //DeltaV_Lab = PerceptionLib.Color.ColorDistanceCalAB(MVoncolor, ColorMeasured);
               // DeltaV_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaV_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

               // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
               // ////S color
               // ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

               // newRow[151] = MScalingXYZ.X.ToString();
               // newRow[152] = MScalingXYZ.Y.ToString();
               // newRow[153] = MScalingXYZ.Z.ToString();
               // newRow[154] = MScalingcolor.LA.ToString();
               // newRow[155] = MScalingcolor.A.ToString();
               // newRow[156] = MScalingcolor.B.ToString();
               // newRow[157] = scalingRGB.R.ToString();
               // newRow[158] = scalingRGB.G.ToString();
               // newRow[159] = scalingRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {
               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(scalingRGB.R, scalingRGB.G, scalingRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();

               // scalingRGB = PerceptionLib.Color.ToRBG(MScalingXYZ);

               // newRow[160] = ColorMeasuredXYZ.X.ToString();
               // newRow[161] = ColorMeasuredXYZ.Y.ToString();
               // newRow[162] = ColorMeasuredXYZ.Z.ToString();
               // newRow[163] = ColorMeasured.LA.ToString();
               // newRow[164] = ColorMeasured.A.ToString();
               // newRow[165] = ColorMeasured.B.ToString();
               // newRow[166] = MR.ToString();
               // newRow[167] = MG.ToString();
               // newRow[168] = MB.ToString();

               // //DeltaS_Luv = PerceptionLib.Color.ColorDistanceCalAB(MScalingcolor, ColorMeasured);
               // DeltaS_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaS_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

               // X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
               // Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
               // Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

               // ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

               // MScalingXYZ = Util.ColorSpaceConverter.SubtractXYZ(ScalingXYZ, ColorBackGroundXYZ);
               // MScalingcolor = PerceptionLib.Color.ToLUV(MVonXYZ);
               // scalingRGB = PerceptionLib.Color.ToRBGFromLAB(MScalingcolor);

               // newRow[169] = MScalingXYZ.X.ToString();
               // newRow[170] = MScalingXYZ.Y.ToString();
               // newRow[171] = MScalingXYZ.Z.ToString();
               // newRow[172] = MScalingcolor.LA.ToString();
               // newRow[173] = MScalingcolor.A.ToString();
               // newRow[174] = MScalingcolor.B.ToString();
               // newRow[175] = scalingRGB.R.ToString();
               // newRow[176] = scalingRGB.G.ToString();
               // newRow[177] = scalingRGB.B.ToString();

               // Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
               // {
               //   rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(scalingRGB.R, scalingRGB.G, scalingRGB.B));
               // }));

               // DisplayMeasuredValuesFromCs200();

               // MscalingRGB = PerceptionLib.Color.ToRBG(MScalingXYZ);

               // newRow[178] = ColorMeasuredXYZ.X.ToString();
               // newRow[179] = ColorMeasuredXYZ.Y.ToString();
               // newRow[180] = ColorMeasuredXYZ.Z.ToString();
               // newRow[181] = ColorMeasured.LA.ToString();
               // newRow[182] = ColorMeasured.A.ToString();
               // newRow[183] = ColorMeasured.B.ToString();
               // newRow[184] = MR.ToString();
               // newRow[185] = MG.ToString();
               // newRow[186] = MB.ToString();

               // //DeltaS_Lab = PerceptionLib.Color.ColorDistanceCalAB(MScalingcolor, ColorMeasured);
               // DeltaS_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
               // CDeltaS_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            ////bin color
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

            binnumber = Util.CATCalulation.MatchWithBinnedColors(MBINColor, bin,ColorBackGroundXYZ,BINColor);
            int binnum = Util.CATCalulation.MatchWithBinnedColorsBasedOn3D(MBINColor, bin, ColorBackGroundXYZ, BINColor);

            MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            MBINColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            MBINColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            MBINColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            BincolorRGB.R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            BincolorRGB.G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            BincolorRGB.B = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            newRow[187] = MBINcolorXYZ.X.ToString();
            newRow[188] = MBINcolorXYZ.Y.ToString();
            newRow[189] = MBINcolorXYZ.Z.ToString();
            newRow[190] = MBINColor.LA.ToString();
            newRow[191] = MBINColor.A.ToString();
            newRow[192] = MBINColor.B.ToString();
            newRow[193] = BincolorRGB.R.ToString();
            newRow[194] = BincolorRGB.G.ToString();
            newRow[195] = BincolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B));
            }));

            DisplayMeasuredValuesFromCs200();
            BincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            newRow[196] = ColorMeasuredXYZ.X.ToString();
            newRow[197] = ColorMeasuredXYZ.Y.ToString();
            newRow[198] = ColorMeasuredXYZ.Z.ToString();
            newRow[199] = ColorMeasured.LA.ToString();
            newRow[200] = ColorMeasured.A.ToString();
            newRow[201] = ColorMeasured.B.ToString();
            newRow[202] = MR.ToString();
            newRow[203] = MG.ToString();
            newRow[204] = MB.ToString();

            //DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(MBINColor, ColorMeasured);
            DeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            CDeltaBin_Luv = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            X = Convert.ToDouble(dt_Bg.Rows[i][6].ToString());
            Y = Convert.ToDouble(dt_Bg.Rows[i][7].ToString());
            Z = Convert.ToDouble(dt_Bg.Rows[i][8].ToString());

            ColorBackGroundXYZ = new CIEXYZ(X, Y, Z);

            MBINcolorXYZ = Util.ColorSpaceConverter.SubtractXYZ(BinXYZ, ColorBackGroundXYZ);
            MBINColor = PerceptionLib.Color.ToLUV(MBINcolorXYZ);
            //BincolorRGB = PerceptionLib.Color.ToRBGFromLAB(MBINColor);

            binnumber = Util.CATCalulation.MatchWithBinnedColors(MBINColor, bin, ColorBackGroundXYZ,BINColor);

            MBINcolorXYZ.X = Convert.ToDouble(bin.Rows[binnumber][6].ToString());
            MBINcolorXYZ.Y = Convert.ToDouble(bin.Rows[binnumber][7].ToString());
            MBINcolorXYZ.Z = Convert.ToDouble(bin.Rows[binnumber][8].ToString());
            MBINColor.LA = Convert.ToDouble(bin.Rows[binnumber][3].ToString());
            MBINColor.A = Convert.ToDouble(bin.Rows[binnumber][4].ToString());
            MBINColor.B = Convert.ToDouble(bin.Rows[binnumber][5].ToString());
            BincolorRGB.R = Convert.ToByte(bin.Rows[binnumber][0].ToString());
            BincolorRGB.G = Convert.ToByte(bin.Rows[binnumber][1].ToString());
            BincolorRGB.B = Convert.ToByte(bin.Rows[binnumber][2].ToString());

            newRow[205] = MBINcolorXYZ.X.ToString();
            newRow[206] = MBINcolorXYZ.Y.ToString();
            newRow[207] = MBINcolorXYZ.Z.ToString();
            newRow[208] = MBINColor.LA.ToString();
            newRow[209] = MBINColor.A.ToString();
            newRow[210] = MBINColor.B.ToString();
            newRow[211] = BincolorRGB.R.ToString();
            newRow[212] = BincolorRGB.G.ToString();
            newRow[213] = BincolorRGB.B.ToString();

            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
              rec_displayColor.Fill = new SolidColorBrush(System.Windows.Media.Color.FromRgb(BincolorRGB.R, BincolorRGB.G, BincolorRGB.B));
            }));

            DisplayMeasuredValuesFromCs200();

            MBincolorRGB = PerceptionLib.Color.ToRBG(MBINcolorXYZ);

            newRow[214] = ColorMeasuredXYZ.X.ToString();
            newRow[215] = ColorMeasuredXYZ.Y.ToString();
            newRow[216] = ColorMeasuredXYZ.Z.ToString();
            newRow[217] = ColorMeasured.LA.ToString();
            newRow[218] = ColorMeasured.A.ToString();
            newRow[219] = ColorMeasured.B.ToString();
            newRow[220] = MR.ToString();
            newRow[221] = MG.ToString();
            newRow[222] = MB.ToString();

            //DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(MBINColor, ColorMeasured);
            DeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured);
            CDeltaBin_Lab = PerceptionLib.Color.ColorDistanceCalAB(ColorDifference, ColorMeasured);

            newRow[223] = DeltaA_Luv.ToString();
            newRow[224] = DeltaA_LAb.ToString();
            //newRow[225] = DeltaB_luv.ToString();
            //newRow[226] = DeltaB_Lab.ToString();
            //newRow[227] = DeltaV_Luv.ToString();
            //newRow[228] = DeltaV_Lab.ToString();
            //newRow[229] = DeltaS_Luv.ToString();
            //newRow[230] = DeltaS_Lab.ToString();
            newRow[231] = DeltaBin_Luv.ToString();
            newRow[232] = DeltaBin_Lab.ToString();

            newRow[233] = acolorRGB.gmt.ToString();
            //newRow[234] = bradRGB.gmt.ToString();
            //newRow[235] = VonRGB.gmt.ToString();
            //newRow[236] = scalingRGB.gmt.ToString();
            newRow[237] = BincolorRGB.gmt.ToString();
            newRow[238] = MacolorRGB.gmt.ToString();
            //newRow[239] = MbradRGB.gmt.ToString();
            //newRow[240] = MVonRGB.gmt.ToString();
            //newRow[241] = MscalingRGB.gmt.ToString();
            newRow[242] = MBincolorRGB.gmt.ToString();

            newRow[243] = CDeltaA_Luv.ToString();
            newRow[244] = CDeltaA_LAb.ToString();
            //newRow[245] = CDeltaB_luv.ToString();
            //newRow[246] = CDeltaB_Lab.ToString();
            //newRow[247] = CDeltaV_Luv.ToString();
            //newRow[248] = CDeltaV_Lab.ToString();
            //newRow[249] = CDeltaS_Luv.ToString();
            //newRow[250] = CDeltaS_Lab.ToString();
            newRow[251] = CDeltaBin_Luv.ToString();
            newRow[252] = CDeltaBin_Lab.ToString();
            newRow[253] = ColorDifference.LA.ToString();
            newRow[254] = ColorDifference.A.ToString() + "," + scalingRGB.gmt.ToString() ;
               // newRow[255] = scalingRGB.gmt.ToString();;

            newRow[249] = binnumber.ToString();
            newRow[250] = binnum.ToString();

            dt_DataCollection.Rows.Add(newRow);

            R = 0; G = 0; B = 0;

            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
              }

            }
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              //  double AvgBin, AvgA, Avgb, AvgV, Avgs, dbc, dc;
              //  double sAvgBin, sAvgA, sAvgb, sAvgV, sAvgs;
              //  AvgBin = 0;
              //  AvgA = 0;
              //  Avgb = 0;
              //  AvgV = 0;
              //  Avgs = 0;
              //  dbc = 0;
              //  dc = 0;

              //  sAvgBin = 0;
              //  sAvgA = 0;
              //  sAvgb = 0;
              //  sAvgV = 0;
              //  sAvgs = 0;
              //  dbc = 0;
              //  dc = 0;

              //  for (int i = 0; i < BgNo * FgNo; i = i + FgNo)
              //  {
              //    newRow = dt_DataCollection.NewRow();
              //    for (int j = i; j < i + FgNo; j++)
              //    {

              //      if (j == i)
              //      {
              //        AvgBin = Convert.ToDouble(dt_DataCollection.Rows[j][115].ToString());
              //        AvgA = Convert.ToDouble(dt_DataCollection.Rows[j][113].ToString());
              //        Avgb = Convert.ToDouble(dt_DataCollection.Rows[j][117].ToString());
              //        AvgV = Convert.ToDouble(dt_DataCollection.Rows[j][119].ToString());
              //        Avgs = Convert.ToDouble(dt_DataCollection.Rows[j][121].ToString());
              //        sAvgBin = Convert.ToDouble(dt_DataCollection.Rows[j][184].ToString());
              //        sAvgA = Convert.ToDouble(dt_DataCollection.Rows[j][182].ToString());
              //        sAvgb = Convert.ToDouble(dt_DataCollection.Rows[j][186].ToString());
              //        sAvgV = Convert.ToDouble(dt_DataCollection.Rows[j][188].ToString());
              //        sAvgs = Convert.ToDouble(dt_DataCollection.Rows[j][190].ToString());
              //        dbc = Convert.ToDouble(dt_DataCollection.Rows[j][122].ToString());
              //        dc = Convert.ToDouble(dt_DataCollection.Rows[j][123].ToString());
              //      }
              //      else
              //      {
              //        AvgBin = AvgBin + Convert.ToDouble(dt_DataCollection.Rows[j][115].ToString());
              //        AvgA = AvgA + Convert.ToDouble(dt_DataCollection.Rows[j][113].ToString());
              //        Avgb = Avgb + Convert.ToDouble(dt_DataCollection.Rows[j][117].ToString());
              //        AvgV = AvgV + Convert.ToDouble(dt_DataCollection.Rows[j][119].ToString());
              //        Avgs = Avgs + Convert.ToDouble(dt_DataCollection.Rows[j][121].ToString());
              //        sAvgBin = sAvgBin + Convert.ToDouble(dt_DataCollection.Rows[j][184].ToString());
              //        sAvgA = sAvgA + Convert.ToDouble(dt_DataCollection.Rows[j][182].ToString());
              //        sAvgb = sAvgb + Convert.ToDouble(dt_DataCollection.Rows[j][186].ToString());
              //        sAvgV = sAvgV + Convert.ToDouble(dt_DataCollection.Rows[j][188].ToString());
              //        sAvgs = sAvgs + Convert.ToDouble(dt_DataCollection.Rows[j][190].ToString());
              //        dbc = dbc + Convert.ToDouble(dt_DataCollection.Rows[j][122].ToString());
              //        dc = dc + Convert.ToDouble(dt_DataCollection.Rows[j][123].ToString());
              //      }

              //    }

              //    newRow[1] = (AvgBin / FgNo).ToString();
              //    newRow[2] = (AvgA / FgNo).ToString();
              //    newRow[3] = (Avgb / FgNo).ToString();
              //    newRow[4] = (AvgV / FgNo).ToString();
              //    newRow[5] = (Avgs / FgNo).ToString();
              //    newRow[6] = (dbc / FgNo).ToString();
              //    newRow[7] = (dc / FgNo).ToString();
              //    newRow[8] = (sAvgBin / FgNo).ToString();
              //    newRow[9] = (sAvgA / FgNo).ToString();
              //    newRow[10] = (sAvgb / FgNo).ToString();
              //    newRow[11] = (sAvgV / FgNo).ToString();
              //    newRow[11] = (sAvgs / FgNo).ToString();
              //    dt_DataCollection.Rows.Add(newRow);
              //    Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt_DataCollection.DefaultView));
              //    Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
              //  }

              });

              btn_ExportGrid.IsEnabled = true;
        }
コード例 #29
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        /// <summary>
        /// Function to Convert LUV to XyZ
        /// </summary>
        /// <param name="PassedLUV"></param>
        /// <returns></returns>
        private static CIEXYZ LUVToXYZ(Color PassedLUV)
        {
            // by the formula given the the web page http://www.brucelindbloom.com/index.html
              double x, y, z, a, b, c, d;

              y = GetY(PassedLUV.L);

              a = (double)(1.0 / 3.0) * ((52.0 * PassedLUV.L) / (PassedLUV.U + (13.0 * PassedLUV.L * PassedLUV.UR)) - 1.0);
              b = (double)-5.0 * y;
              c = (double)-1.0 / 3.0;
              d = (double)y * (((39.0 * PassedLUV.L) / (PassedLUV.V + (13.0 * PassedLUV.L * PassedLUV.VR))) - 5.0);

              x = (double)(d - b) / (double)(a - c);
              if (Double.IsNaN(x)) { x = 0.0; }

              z = (double)(x * a) + (double)b;
              if (Double.IsNaN(z)) { z = 0.0; }

              CIEXYZ xyz = new CIEXYZ(x, y, z);

              return xyz;
        }
コード例 #30
0
        private void Btn_ColorPredictor_Click(object sender, RoutedEventArgs e)
        {
            //  PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\StdColor.txt");
              PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\predictor.csv");
              txt_R.IsEnabled = false;
              txt_G.IsEnabled = false;
              txt_B.IsEnabled = false;
              txt_BgNo.IsEnabled = false;
              txt_FgNo.IsEnabled = false;
              btn_MixedColour.IsEnabled = false;
              DataTable dt = new DataTable();
              // DataTable new_dt = new DataTable();
              DataRow newRow;
              dt = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

              // to create a random number
              //BgNo = 5;
              BgNo = 24;
              //FgNo = 27;
              FgNo = dt.Rows.Count;

              // this loop is too changfe the bg color
              //  for (int i = 0; i < 5; i++)
              ThreadPool.QueueUserWorkItem(ignored =>
              {
            PerceptionLib.RGBValue rgb = new PerceptionLib.RGBValue();
            for (int i = 0; i < BgNo; i++)
            {

              // for the first set of vaule it tahes balck as the bg colour
              switch (i)
              {
            // black bg
            case 0:
              BgR = 0;
              BgG = 0;
              BgB = 0;
              break;
            //Brick

            case 1:

              BgR = 115;
              BgG = 80;
              BgB = 64;
              break;

            case 2:
              BgR = 195;
              BgG = 151;
              BgB = 130;
              break;

            //Pavement
            case 3:
              BgR = 94;
              BgG = 123;
              BgB = 156;
              break;

            //vaiants of blue
            case 4:
              BgR = 88;
              BgG = 108;
              BgB = 65;
              break;

            case 5:
              BgR = 100;
              BgG = 190;
              BgB = 171;
              break;

            case 6:
              BgR = 217;
              BgG = 122;
              BgB = 37;
              break;

            case 7:
              BgR = 72;
              BgG = 91;
              BgB = 165;
              break;

            //variants of green

            case 8:
              BgR = 194;
              BgG = 84;
              BgB = 98;
              break;

            case 9:
              BgR = 91;
              BgG = 59;
              BgB = 107;
              break;

            case 10:
              BgR = 115;
              BgG = 80;
              BgB = 64;
              break;

            case 11:
              BgR = 160;
              BgG = 188;
              BgB = 60;
              break;

            //yellow

            case 12:
              BgR = 230;
              BgG = 163;
              BgB = 42;
              break;

            case 13:
              BgR = 46;
              BgG = 60;
              BgB = 153;
              break;

            case 14:
              BgR = 71;
              BgG = 150;
              BgB = 69;
              break;

            //red
            case 15:
              BgR = 177;
              BgG = 44;
              BgB = 56;
              break;

            case 16:
              BgR = 238;
              BgG = 200;
              BgB = 27;
              break;

            case 17:
              BgR = 187;
              BgG = 82;
              BgB = 148;
              break;

            case 18:
              BgR = 243;
              BgG = 242;
              BgB = 237;
              break;

            case 19:
              BgR = 201;
              BgG = 201;
              BgB = 201;
              break;

            case 20:
              BgR = 161;
              BgG = 161;
              BgB = 161;
              break;

            case 21:
              BgR = 122;
              BgG = 122;
              BgB = 121;
              break;

            case 22:
              BgR = 83;
              BgG = 83;
              BgB = 83;
              break;

            case 23:
              BgR = 50;
              BgG = 49;
              BgB = 50;
              break;

              }

              for (int j = 0; j < FgNo; j++)
              {
            //if (i == 0)
            //{
            //    mainW.R = Convert.ToByte(dt.Rows[j][0].ToString());
            //    mainW.G = Convert.ToByte(dt.Rows[j][1].ToString());
            //    mainW.B = Convert.ToByte(dt.Rows[j][2].ToString());
            //}
            //else
            //{
            mainW.R = Convert.ToByte(dt.Rows[j][0].ToString());
            mainW.G = Convert.ToByte(dt.Rows[j][1].ToString());
            mainW.B = Convert.ToByte(dt.Rows[j][2].ToString());
            //}

            //if (i != 0)
            //               System.Threading.Thread.Sleep(500);
            Dispatcher.Invoke(new Action(() => ColorUpdateOnScreenWithBG()));
            //           System.Windows.Forms.Application.DoEvents();

            colorMeasured = StartCapture1();

            Dispatcher.Invoke(new Action(() => DisplayMeasuredValues()));
            Dispatcher.Invoke(new Action(() => progress(i)));

            DifferenceCalculation();

            BradXYZ = Util.CATCalulation.bradford(ColorToShowXYZ);
            VonXYZ = Util.CATCalulation.VonKries(ColorToShowXYZ);
            ScalingXYZ = Util.CATCalulation.XYZScaling(ColorToShowXYZ);

            Bradcolor = PerceptionLib.Color.ToLUV(BradXYZ);
            Voncolor = PerceptionLib.Color.ToLUV(VonXYZ);
            Scalingcolor = PerceptionLib.Color.ToLUV(ScalingXYZ);

            bradRGB = PerceptionLib.Color.ToRBG(BradXYZ);
            VonRGB = PerceptionLib.Color.ToRBG(VonXYZ);
            scalingRGB = PerceptionLib.Color.ToRBG(ScalingXYZ);

            CalRGB = PerceptionLib.Color.ToRBG(ColorMeasuredXYZ);

            if (i == 0)
            {
              //dt.Rows[j][0] = R.ToString();
              //dt.Rows[j][1] = G.ToString();
              //dt.Rows[j][2] = B.ToString();
              //dt.Rows[j][3] = colorToShow.L.ToString();
              //dt.Rows[j][4] = colorToShow.U.ToString();
              //dt.Rows[j][5] = colorToShow.V.ToString();
              //dt.Rows[j][6] = colorToShow.UP.ToString();
              //dt.Rows[j][7] = colorToShow.VP.ToString();
              //dt.Rows[j][8] = ColorMeasured.L.ToString();
              //dt.Rows[j][9] = ColorMeasured.U.ToString();
              //dt.Rows[j][10] = ColorMeasured.V.ToString();
              //dt.Rows[j][11] = ColorMeasured.UP.ToString();
              //dt.Rows[j][12] = ColorMeasured.VP.ToString();
              //dt.Rows[j][13] = MR.ToString();
              //dt.Rows[j][14] = MG.ToString();
              //dt.Rows[j][15] = MB.ToString();
              //dt.Rows[j][16] = colorDifference.L.ToString();
              //dt.Rows[j][17] = colorDifference.U.ToString();
              //dt.Rows[j][18] = colorDifference.V.ToString();
              //dt.Rows[j][19] = BgR.ToString();
              //dt.Rows[j][20] = BgG.ToString();
              //dt.Rows[j][21] = BgB.ToString();
              //dt.Rows[j][22] = 0;
              //dt.Rows[j][23] = 0;
              //dt.Rows[j][24] = 0;
              //dt.Rows[j][25] = 0;
              //dt.Rows[j][26] = 0;
              //dt.Rows[j][27] = 0;
              //dt.Rows[j][28] = 0;
              //dt.Rows[j][29] = 0;
              //dt.Rows[j][30] = 0;
              //dt.Rows[j][31] = 0;
              //dt.Rows[j][32] = 0;
              //dt.Rows[j][33] = 0;
              //dt.Rows[j][34] = 0;
              //dt.Rows[j][35] = 0;
              //dt.Rows[j][36] = 0;
              //dt.Rows[j][37] = 0;
              dt.Rows[j][0] = R.ToString();
              dt.Rows[j][1] = G.ToString();
              dt.Rows[j][2] = B.ToString();
              dt.Rows[j][3] = colorToShow.L.ToString();
              dt.Rows[j][4] = colorToShow.U.ToString();
              dt.Rows[j][5] = colorToShow.V.ToString();
              dt.Rows[j][6] = colorToShow.UP.ToString();
              dt.Rows[j][7] = colorToShow.VP.ToString();
              dt.Rows[j][8] = colorToShow.LA.ToString();
              dt.Rows[j][9] = colorToShow.A.ToString();
              dt.Rows[j][10] = colorToShow.B.ToString();
              dt.Rows[j][11] = ColorToShowXYZ.X.ToString();
              dt.Rows[j][12] = ColorToShowXYZ.Y.ToString();
              dt.Rows[j][13] = ColorToShowXYZ.Z.ToString();
              dt.Rows[j][14] = MR.ToString();
              dt.Rows[j][15] = MG.ToString();
              dt.Rows[j][16] = MB.ToString();
              dt.Rows[j][17] = ColorMeasured.L.ToString();
              dt.Rows[j][18] = ColorMeasured.U.ToString();
              dt.Rows[j][19] = ColorMeasured.V.ToString();
              dt.Rows[j][20] = ColorMeasured.UP.ToString();
              dt.Rows[j][21] = ColorMeasured.VP.ToString();
              dt.Rows[j][22] = ColorMeasured.LA.ToString();
              dt.Rows[j][23] = ColorMeasured.A.ToString();
              dt.Rows[j][24] = ColorMeasured.B.ToString();
              dt.Rows[j][25] = ColorMeasuredXYZ.X.ToString();
              dt.Rows[j][26] = ColorMeasuredXYZ.Y.ToString();
              dt.Rows[j][27] = ColorMeasuredXYZ.Z.ToString();

              BradXYZ = Util.CATCalulation.bradford(ColorToShowXYZ);
              VonXYZ = Util.CATCalulation.VonKries(ColorToShowXYZ);
              ScalingXYZ = Util.CATCalulation.XYZScaling(ColorToShowXYZ);

              Bradcolor = PerceptionLib.Color.ToLUV(BradXYZ);
              Voncolor = PerceptionLib.Color.ToLUV(VonXYZ);
              Scalingcolor = PerceptionLib.Color.ToLUV(ScalingXYZ);

              bradRGB = PerceptionLib.Color.ToRBG(BradXYZ);
              VonRGB = PerceptionLib.Color.ToRBG(VonXYZ);
              scalingRGB = PerceptionLib.Color.ToRBG(ScalingXYZ);

              dt.Rows[j][28] = Bradcolor.L.ToString();
              dt.Rows[j][29] = Bradcolor.U.ToString();
              dt.Rows[j][30] = Bradcolor.V.ToString();
              dt.Rows[j][31] = Bradcolor.UP.ToString();
              dt.Rows[j][32] = Bradcolor.VP.ToString();
              dt.Rows[j][33] = Bradcolor.LA.ToString();
              dt.Rows[j][34] = Bradcolor.A.ToString();
              dt.Rows[j][35] = Bradcolor.B.ToString();
              dt.Rows[j][36] = BradXYZ.X.ToString();
              dt.Rows[j][37] = BradXYZ.Y.ToString();
              dt.Rows[j][38] = BradXYZ.Z.ToString();
              dt.Rows[j][39] = bradRGB.R.ToString();
              dt.Rows[j][40] = bradRGB.G.ToString();
              dt.Rows[j][41] = bradRGB.B.ToString();

              dt.Rows[j][42] = Voncolor.L.ToString();
              dt.Rows[j][43] = Voncolor.U.ToString();
              dt.Rows[j][44] = Voncolor.V.ToString();
              dt.Rows[j][45] = Voncolor.UP.ToString();
              dt.Rows[j][46] = Voncolor.VP.ToString();
              dt.Rows[j][47] = Voncolor.LA.ToString();
              dt.Rows[j][48] = Voncolor.A.ToString();
              dt.Rows[j][49] = Voncolor.B.ToString();
              dt.Rows[j][50] = VonXYZ.X.ToString();
              dt.Rows[j][51] = VonXYZ.Y.ToString();
              dt.Rows[j][52] = VonXYZ.Z.ToString();
              dt.Rows[j][53] = VonRGB.R.ToString();
              dt.Rows[j][54] = VonRGB.G.ToString();
              dt.Rows[j][55] = VonRGB.B.ToString();

              dt.Rows[j][57] = Scalingcolor.L.ToString();
              dt.Rows[j][57] = Scalingcolor.U.ToString();
              dt.Rows[j][58] = Scalingcolor.V.ToString();
              dt.Rows[j][59] = Scalingcolor.UP.ToString();
              dt.Rows[j][60] = Scalingcolor.VP.ToString();
              dt.Rows[j][61] = Scalingcolor.LA.ToString();
              dt.Rows[j][62] = Scalingcolor.A.ToString();
              dt.Rows[j][63] = Scalingcolor.B.ToString();
              dt.Rows[j][64] = ScalingXYZ.X.ToString();
              dt.Rows[j][65] = ScalingXYZ.Y.ToString();
              dt.Rows[j][66] = ScalingXYZ.Z.ToString();
              dt.Rows[j][67] = scalingRGB.R.ToString();
              dt.Rows[j][68] = scalingRGB.G.ToString();
              dt.Rows[j][69] = scalingRGB.B.ToString();

              dt.Rows[j][71] = BgR.ToString();
              dt.Rows[j][71] = BgG.ToString();
              dt.Rows[j][72] = BgB.ToString();
              dt.Rows[j][73] = ColorBackGround.L.ToString();
              dt.Rows[j][74] = ColorBackGround.U.ToString();
              dt.Rows[j][75] = ColorBackGround.V.ToString();
              dt.Rows[j][76] = ColorBackGround.UP.ToString();
              dt.Rows[j][77] = ColorBackGround.VP.ToString();
              dt.Rows[j][78] = ColorBackGround.LA.ToString();
              dt.Rows[j][79] = ColorBackGround.A.ToString();
              dt.Rows[j][80] = ColorBackGround.B.ToString();
              dt.Rows[j][81] = ColorBackGroundXYZ.X.ToString();
              dt.Rows[j][82] = ColorBackGroundXYZ.Y.ToString();
              dt.Rows[j][83] = ColorBackGroundXYZ.Z.ToString();
              dt.Rows[j][84] = 0;
              dt.Rows[j][85] = 0;
              dt.Rows[j][86] = 0;
              dt.Rows[j][87] = 0;
              dt.Rows[j][88] = 0;
              dt.Rows[j][89] = 0;
              dt.Rows[j][90] = 0;
              dt.Rows[j][91] = 0;
              dt.Rows[j][92] = 0;
              dt.Rows[j][93] = 0;
              dt.Rows[j][94] = 0;
              dt.Rows[j][95] = 0;
              dt.Rows[j][96] = 0;
              dt.Rows[j][97] = 0;
              dt.Rows[j][98] = 0;
              dt.Rows[j][99] = 0;
              dt.Rows[j][100] = 0;
              dt.Rows[j][101] = 0;
              dt.Rows[j][102] = 0;
              dt.Rows[j][103] = 0;
              dt.Rows[j][104] = 0;
              dt.Rows[j][105] = 0;
              dt.Rows[j][106] = 0;
              dt.Rows[j][107] = 0;
              dt.Rows[j][108] = 0;
              dt.Rows[j][109] = 0;
              dt.Rows[j][110] = 0;
              dt.Rows[j][111] = 0;
              dt.Rows[j][112] = 0;
              dt.Rows[j][113] = 0;
              dt.Rows[j][114] = 0;
              dt.Rows[j][115] = 0;
              dt.Rows[j][116] = 0;
              dt.Rows[j][117] = 0;
              dt.Rows[j][118] = 0;
              dt.Rows[j][119] = 0;
              dt.Rows[j][120] = 0;
              dt.Rows[j][121] = 0;
              dt.Rows[j][122] = 0;
              dt.Rows[j][123] = 0;
              dt.Rows[j][124] = 0;
              dt.Rows[j][125] = 0;
              dt.Rows[j][126] = 0;
              dt.Rows[j][127] = 0;
              dt.Rows[j][128] = 0;
              dt.Rows[j][129] = 0;
              dt.Rows[j][130] = 0;
              dt.Rows[j][131] = 0;
              dt.Rows[j][132] = 0;
              dt.Rows[j][133] = 0;
              dt.Rows[j][134] = 0;
              dt.Rows[j][135] = 0;
              dt.Rows[j][136] = 0;
              dt.Rows[j][137] = 0;
              dt.Rows[j][138] = 0;
              dt.Rows[j][139] = 0;
              dt.Rows[j][140] = 0;
              dt.Rows[j][141] = 0;
              dt.Rows[j][142] = 0;
              dt.Rows[j][143] = 0;
              dt.Rows[j][144] = 0;
              dt.Rows[j][145] = 0;
              dt.Rows[j][146] = 0;
              dt.Rows[j][147] = 0;
              dt.Rows[j][148] = 0;
              dt.Rows[j][149] = 0;
              dt.Rows[j][150] = 0;
              dt.Rows[j][151] = 0;
              dt.Rows[j][152] = 0;
              dt.Rows[j][153] = 0;
              dt.Rows[j][154] = 0;
              dt.Rows[j][155] = 0;
              dt.Rows[j][156] = 0;
              dt.Rows[j][157] = 0;
              dt.Rows[j][158] = 0;
              dt.Rows[j][159] = 0;
              dt.Rows[j][160] = 0;
              dt.Rows[j][161] = 0;
              dt.Rows[j][162] = 0;
              dt.Rows[j][163] = 0;
              dt.Rows[j][164] = 0;
              dt.Rows[j][165] = 0;
              dt.Rows[j][166] = 0;
              dt.Rows[j][167] = 0;
              dt.Rows[j][168] = 0;
              dt.Rows[j][169] = 0;
              dt.Rows[j][170] = 0;
              dt.Rows[j][171] = 0;
              dt.Rows[j][172] = 0;
              dt.Rows[j][173] = 0;
              dt.Rows[j][174] = 0;
              dt.Rows[j][175] = 0;
              dt.Rows[j][176] = 0;
              dt.Rows[j][177] = 0;
              dt.Rows[j][178] = 0;
              dt.Rows[j][179] = 0;
              dt.Rows[j][180] = 0;

              /////////////////

              pairs.Clear();
              pairs.Add(new MeasurementPair()
              {
                ColorToShow = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(colorToShow.UP.ToString()), VP = Convert.ToDouble(colorToShow.VP.ToString()) },
                ColorCaptured = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(ColorMeasured.UP.ToString()), VP = Convert.ToDouble(ColorMeasured.VP.ToString()) }
              });

            }
            else
            {

              newRow = dt.NewRow();
              //newRow[0] = R.ToString();
              //newRow[1] = G.ToString();
              //newRow[2] = B.ToString();
              //newRow[3] = colorToShow.L.ToString();
              //newRow[4] = colorToShow.U.ToString();
              //newRow[5] = colorToShow.V.ToString();
              //newRow[6] = colorToShow.UP.ToString();
              //newRow[7] = colorToShow.VP.ToString();

              //newRow[8]  = dt.Rows[j][8].ToString();
              //newRow[9]  = dt.Rows[j][9].ToString();
              //newRow[10] = dt.Rows[j][10].ToString();
              //newRow[11] = dt.Rows[j][11].ToString();
              //newRow[12] = dt.Rows[j][12].ToString();
              //newRow[13] = dt.Rows[j][13].ToString();
              //newRow[14] = dt.Rows[j][14].ToString();
              //newRow[15] = dt.Rows[j][15].ToString();

              //newRow[16] = colorDifference.L.ToString();
              //newRow[17] = colorDifference.U.ToString();
              //newRow[18] = colorDifference.V.ToString();
              //newRow[19] = BgR.ToString();
              //newRow[20] = BgG.ToString();
              //newRow[21] = BgB.ToString();
              //newRow[22] = 0;
              //newRow[23] = 0;
              //newRow[24] = 0;
              //newRow[25] = 0;
              //newRow[26] = 0;
              //newRow[27] = 0;
              //newRow[28] = 0;
              //newRow[29] = 0;
              //newRow[30] = ColorMeasured.L.ToString();
              //newRow[31] = ColorMeasured.U.ToString();
              //newRow[32] = ColorMeasured.V.ToString();
              //newRow[33] = ColorMeasured.UP.ToString();
              //newRow[34] = ColorMeasured.VP.ToString();
              //newRow[35] = MR.ToString();
              //newRow[36] = MG.ToString();
              //newRow[37] = MB.ToString();

              newRow[0] = R.ToString();
              newRow[1] = G.ToString();
              newRow[2] = B.ToString();
              newRow[3] = colorToShow.L.ToString();
              newRow[4] = colorToShow.U.ToString();
              newRow[5] = colorToShow.V.ToString();
              newRow[6] = colorToShow.UP.ToString();
              newRow[7] = colorToShow.VP.ToString();
              newRow[8] = colorToShow.LA.ToString();
              newRow[9] = colorToShow.A.ToString();
              newRow[10] = colorToShow.B.ToString();
              newRow[11] = ColorToShowXYZ.X.ToString();
              newRow[12] = ColorToShowXYZ.Y.ToString();
              newRow[13] = ColorToShowXYZ.Z.ToString();

              newRow[14] = dt.Rows[j][14].ToString();
              newRow[15] = dt.Rows[j][15].ToString();
              newRow[16] = dt.Rows[j][16].ToString();
              newRow[17] = dt.Rows[j][17].ToString();
              newRow[18] = dt.Rows[j][18].ToString();
              newRow[19] = dt.Rows[j][19].ToString();
              newRow[20] = dt.Rows[j][20].ToString();
              newRow[21] = dt.Rows[j][21].ToString();
              newRow[22] = dt.Rows[j][22].ToString();
              newRow[23] = dt.Rows[j][23].ToString();
              newRow[24] = dt.Rows[j][24].ToString();
              newRow[25] = dt.Rows[j][25].ToString();
              newRow[26] = dt.Rows[j][26].ToString();
              newRow[27] = dt.Rows[j][27].ToString();

              newRow[28] = dt.Rows[j][28].ToString();
              newRow[29] = dt.Rows[j][29].ToString();
              newRow[30] = dt.Rows[j][30].ToString();
              newRow[31] = dt.Rows[j][31].ToString();
              newRow[32] = dt.Rows[j][32].ToString();
              newRow[33] = dt.Rows[j][33].ToString();
              newRow[34] = dt.Rows[j][34].ToString();
              newRow[35] = dt.Rows[j][35].ToString();
              newRow[36] = dt.Rows[j][36].ToString();
              newRow[37] = dt.Rows[j][37].ToString();
              newRow[38] = dt.Rows[j][38].ToString();
              newRow[39] = dt.Rows[j][39].ToString();
              newRow[40] = dt.Rows[j][40].ToString();
              newRow[41] = dt.Rows[j][41].ToString();

              newRow[42] = dt.Rows[j][42].ToString();
              newRow[43] = dt.Rows[j][43].ToString();
              newRow[44] = dt.Rows[j][44].ToString();
              newRow[45] = dt.Rows[j][45].ToString();
              newRow[46] = dt.Rows[j][46].ToString();
              newRow[47] = dt.Rows[j][47].ToString();
              newRow[48] = dt.Rows[j][48].ToString();
              newRow[49] = dt.Rows[j][49].ToString();
              newRow[50] = dt.Rows[j][50].ToString();
              newRow[51] = dt.Rows[j][51].ToString();
              newRow[52] = dt.Rows[j][52].ToString();
              newRow[53] = dt.Rows[j][53].ToString();
              newRow[54] = dt.Rows[j][54].ToString();
              newRow[55] = dt.Rows[j][55].ToString();

              newRow[56] = dt.Rows[j][56].ToString();
              newRow[57] = dt.Rows[j][57].ToString();
              newRow[58] = dt.Rows[j][58].ToString();
              newRow[59] = dt.Rows[j][59].ToString();
              newRow[60] = dt.Rows[j][60].ToString();
              newRow[61] = dt.Rows[j][61].ToString();
              newRow[62] = dt.Rows[j][62].ToString();
              newRow[63] = dt.Rows[j][63].ToString();
              newRow[64] = dt.Rows[j][64].ToString();
              newRow[65] = dt.Rows[j][65].ToString();
              newRow[66] = dt.Rows[j][66].ToString();
              newRow[67] = dt.Rows[j][67].ToString();
              newRow[68] = dt.Rows[j][68].ToString();
              newRow[69] = dt.Rows[j][69].ToString();

              newRow[70] = BgR.ToString();
              newRow[71] = BgG.ToString();
              newRow[72] = BgB.ToString();
              newRow[73] = ColorBackGround.L.ToString();
              newRow[74] = ColorBackGround.U.ToString();
              newRow[75] = ColorBackGround.V.ToString();
              newRow[76] = ColorBackGround.UP.ToString();
              newRow[77] = ColorBackGround.VP.ToString();
              newRow[78] = ColorBackGround.LA.ToString();
              newRow[79] = ColorBackGround.A.ToString();
              newRow[80] = ColorBackGround.B.ToString();
              newRow[81] = ColorBackGroundXYZ.X.ToString();
              newRow[82] = ColorBackGroundXYZ.Y.ToString();
              newRow[83] = ColorBackGroundXYZ.Z.ToString();
              newRow[84] = 0;
              newRow[85] = 0;
              newRow[86] = 0;
              newRow[87] = 0;
              newRow[88] = 0;
              newRow[89] = 0;
              newRow[90] = 0;
              newRow[91] = 0;
              newRow[92] = 0;
              newRow[93] = 0;
              newRow[94] = 0;
              newRow[95] = 0;
              newRow[96] = 0;
              newRow[97] = 0;
              newRow[98] = ColorMeasured.L.ToString();
              newRow[99] = ColorMeasured.U.ToString();
              newRow[100] = ColorMeasured.V.ToString();
              newRow[101] = ColorMeasured.UP.ToString();
              newRow[102] = ColorMeasured.VP.ToString();
              newRow[103] = ColorMeasured.LA.ToString();
              newRow[104] = ColorMeasured.A.ToString();
              newRow[105] = ColorMeasured.B.ToString();
              newRow[106] = ColorMeasuredXYZ.X.ToString();
              newRow[107] = ColorMeasuredXYZ.Y.ToString();
              newRow[108] = ColorMeasuredXYZ.Z.ToString();
              newRow[109] = MR.ToString();
              newRow[110] = MG.ToString();
              newRow[111] = MB.ToString();
              newRow[112] = 0;
              newRow[113] = 0;
              newRow[114] = 0;
              newRow[115] = 0;
              newRow[116] = 0;
              newRow[117] = 0;
              newRow[118] = 0;
              newRow[119] = 0;
              newRow[120] = 0;
              newRow[121] = 0;
              newRow[122] = 0;
              newRow[123] = 0;
              newRow[124] = 0;
              newRow[125] = 0;
              newRow[126] = 0;
              newRow[127] = 0;
              newRow[128] = 0;
              newRow[129] = 0;
              newRow[130] = 0;
              newRow[131] = 0;
              newRow[132] = 0;
              newRow[133] = 0;
              newRow[134] = 0;
              newRow[135] = 0;
              newRow[136] = 0;
              newRow[137] = 0;
              newRow[138] = 0;
              newRow[139] = 0;
              newRow[140] = 0;
              newRow[141] = 0;
              newRow[142] = 0;
              newRow[143] = 0;
              newRow[144] = 0;
              newRow[145] = 0;
              newRow[146] = 0;
              newRow[147] = 0;
              newRow[148] = 0;
              newRow[149] = 0;
              newRow[150] = 0;
              newRow[151] = 0;
              newRow[152] = 0;
              newRow[153] = 0;
              newRow[154] = 0;
              newRow[155] = 0;
              newRow[156] = 0;
              newRow[157] = 0;
              newRow[158] = 0;
              newRow[159] = 0;
              newRow[160] = 0;
              newRow[161] = 0;
              newRow[162] = 0;
              newRow[163] = 0;
              newRow[164] = 0;
              newRow[165] = 0;
              newRow[166] = 0;
              newRow[167] = 0;
              newRow[168] = 0;
              newRow[169] = 0;
              newRow[170] = 0;
              newRow[171] = 0;
              newRow[172] = 0;
              newRow[173] = 0;
              newRow[174] = 0;
              newRow[175] = 0;
              newRow[176] = 0;
              newRow[177] = 0;
              newRow[178] = 0;
              newRow[179] = 0;
              newRow[180] = 0;

              MixedColor = ColorMeasured;
              pairs.Clear();
              pairs.Add(new MeasurementPair()
              {
                // HERE 11 AND 12 ARE THE COLOUR CATPTURED BY THE CAMERA FOR DISPLAY 33 AND 34 ARE MIXED COLOURS
                ColorToShow = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(dt.Rows[j][20].ToString()), VP = Convert.ToDouble(dt.Rows[j][21].ToString()) },
                ColorCaptured = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(ColorMeasured.UP.ToString()), VP = Convert.ToDouble(ColorMeasured.VP.ToString()) }
              });
              dt.Rows.Add(newRow);

            }

            R = 0; G = 0; B = 0;
            //dt.Rows.Add(newRow);

            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              }
            }

            //   dtgrid_corrDisplay.ItemsSource = dt.DefaultView;
            //dtgrid_corrDisplay.Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt.DefaultView));
            // for caluclating just bg colour,.. with  fg & bg white conditions so this for loop should be 3 more than loop for bg color change
            for (int i = 1; i < BgNo + 3; i++)
            {
              if (i < BgNo)
              {
            R = 0;
            G = 0;
            B = 0;

            BgR = Convert.ToByte(dt.Rows[i * FgNo][70].ToString());
            BgG = Convert.ToByte(dt.Rows[i * FgNo][71].ToString());
            BgB = Convert.ToByte(dt.Rows[i * FgNo][72].ToString());

              }
              // both white
              else if (i == BgNo)
              {
            R = 255;
            G = 255;
            B = 255;

            BgR = 255;
            BgG = 255;
            BgB = 255;
              }
              // fg white
              else if (i == BgNo + 1)
              {
            R = 255;
            G = 255;
            B = 255;

            BgR = 0;
            BgG = 0;
            BgB = 0;
              }
              // bg white
              else
              {
            R = 0;
            G = 0;
            B = 0;

            BgR = 255;
            BgG = 255;
            BgB = 255;

              }

              ////if (i != 0)
              //System.Threading.Thread.Sleep(500);
              //ColorCaptureJustBG();
              //System.Windows.Forms.Application.DoEvents();

              ////does all the caputure and difference calculations
              //System.Threading.Thread.Sleep(500);
              //// StartCapture();

              Dispatcher.Invoke(new Action(() => ColorCaptureJustBG()));
              //           System.Windows.Forms.Application.DoEvents();

              colorMeasured = StartCapture1();

              Dispatcher.Invoke(new Action(() => DisplayMeasuredValues()));

              DifferenceCalculation();

              //just bg capture
              newRow = dt.NewRow();
              if (i < BgNo)
              {

            //newRow[0] = R.ToString();
            //newRow[1] = G.ToString();
            //newRow[2] = B.ToString();
            //newRow[3] = 0;
            //newRow[4] = 0;
            //newRow[5] = 0;
            //newRow[6] = 0;
            //newRow[7] = 0;
            //newRow[8] = 0;
            //newRow[9] = 0;
            //newRow[10] = 0;
            //newRow[11] = 0;
            //newRow[12] = 0;
            //newRow[13] = 0;
            //newRow[14] = 0;
            //newRow[15] = 0;
            //newRow[16] = 0;
            //newRow[17] = 0;
            //newRow[18] = 0;
            //newRow[19] = BgR.ToString();
            //newRow[20] = BgG.ToString();
            //newRow[21] = BgB.ToString();
            //newRow[22] = MR.ToString();
            //newRow[23] = MG.ToString();
            //newRow[24] = MB.ToString();
            //newRow[25] = ColorMeasured.L.ToString();
            //newRow[26] = ColorMeasured.U.ToString();
            //newRow[27] = ColorMeasured.V.ToString();
            //newRow[28] = ColorMeasured.UP.ToString();
            //newRow[29] = ColorMeasured.VP.ToString();
            //newRow[30] = 0;
            //newRow[31] = 0;
            //newRow[32] = 0;
            //newRow[33] = 0;
            //newRow[34] = 0;
            //newRow[35] = 0;
            //newRow[36] = 0;
            //newRow[37] = 0;

            newRow[0] = R.ToString();
            newRow[1] = G.ToString();
            newRow[2] = B.ToString();
            newRow[3] = 0;
            newRow[4] = 0;
            newRow[5] = 0;
            newRow[6] = 0;
            newRow[7] = 0;
            newRow[8] = 0;
            newRow[9] = 0;
            newRow[10] = 0;
            newRow[11] = 0;
            newRow[12] = 0;
            newRow[13] = 0;
            newRow[14] = 0;
            newRow[15] = 0;
            newRow[16] = 0;
            newRow[17] = 0;
            newRow[18] = 0;
            newRow[19] = 0;
            newRow[20] = 0;
            newRow[21] = 0;
            newRow[22] = 0;
            newRow[23] = 0;
            newRow[24] = 0;
            newRow[25] = 0;
            newRow[26] = 0;
            newRow[27] = 0;
            newRow[28] = 0;
            newRow[29] = 0;
            newRow[30] = 0;
            newRow[31] = 0;
            newRow[32] = 0;
            newRow[33] = 0;
            newRow[34] = 0;
            newRow[35] = 0;
            newRow[36] = 0;
            newRow[37] = 0;
            newRow[38] = 0;
            newRow[39] = 0;
            newRow[40] = 0;
            newRow[41] = 0;
            newRow[42] = 0;
            newRow[43] = 0;
            newRow[44] = 0;
            newRow[45] = 0;
            newRow[46] = 0;
            newRow[47] = 0;
            newRow[48] = 0;
            newRow[49] = 0;
            newRow[50] = 0;
            newRow[51] = 0;
            newRow[52] = 0;
            newRow[53] = 0;
            newRow[54] = 0;
            newRow[55] = 0;
            newRow[56] = 0;
            newRow[57] = 0;
            newRow[58] = 0;
            newRow[59] = 0;
            newRow[60] = 0;
            newRow[61] = 0;
            newRow[62] = 0;
            newRow[63] = 0;
            newRow[64] = 0;
            newRow[65] = 0;
            newRow[66] = 0;
            newRow[67] = 0;
            newRow[68] = 0;
            newRow[69] = 0;
            newRow[70] = BgR.ToString();
            newRow[71] = BgG.ToString();
            newRow[72] = BgB.ToString();
            newRow[73] = ColorBackGround.L.ToString();
            newRow[74] = ColorBackGround.U.ToString();
            newRow[75] = ColorBackGround.V.ToString();
            newRow[76] = ColorBackGround.UP.ToString();
            newRow[77] = ColorBackGround.VP.ToString();
            newRow[78] = ColorBackGround.LA.ToString();
            newRow[79] = ColorBackGround.A.ToString();
            newRow[80] = ColorBackGround.B.ToString();
            newRow[81] = ColorBackGroundXYZ.X.ToString();
            newRow[82] = ColorBackGroundXYZ.Y.ToString();
            newRow[83] = ColorBackGroundXYZ.Z.ToString();
            newRow[84] = MR.ToString();
            newRow[85] = MG.ToString();
            newRow[86] = MB.ToString();
            newRow[87] = ColorMeasured.L.ToString();
            newRow[88] = ColorMeasured.U.ToString();
            newRow[89] = ColorMeasured.V.ToString();
            newRow[90] = ColorMeasured.UP.ToString();
            newRow[91] = ColorMeasured.VP.ToString();
            newRow[92] = ColorMeasured.LA.ToString();
            newRow[93] = ColorMeasured.A.ToString();
            newRow[94] = ColorMeasured.B.ToString();
            newRow[95] = ColorMeasuredXYZ.X.ToString();
            newRow[96] = ColorMeasuredXYZ.Y.ToString();
            newRow[97] = ColorMeasuredXYZ.Z.ToString();
            newRow[98] = 0;
            newRow[99] = 0;
            newRow[100] = 0;
            newRow[101] = 0;
            newRow[102] = 0;
            newRow[103] = 0;
            newRow[104] = 0;
            newRow[105] = 0;
            newRow[106] = 0;
            newRow[107] = 0;
            newRow[108] = 0;
            newRow[109] = 0;
            newRow[110] = 0;
            newRow[111] = 0;
            newRow[112] = 0;
            newRow[113] = 0;
            newRow[114] = 0;
            newRow[115] = 0;
            newRow[116] = 0;
            newRow[117] = 0;
            newRow[118] = 0;
            newRow[119] = 0;
            newRow[120] = 0;
            newRow[121] = 0;
            newRow[122] = 0;
            newRow[123] = 0;
            newRow[124] = 0;
            newRow[125] = 0;
            newRow[126] = 0;
            newRow[127] = 0;
            newRow[128] = 0;
            newRow[129] = 0;
            newRow[130] = 0;
            newRow[131] = 0;
            newRow[132] = 0;
            newRow[133] = 0;
            newRow[134] = 0;
            newRow[135] = 0;
            newRow[136] = 0;
            newRow[137] = 0;
            newRow[138] = 0;
            newRow[139] = 0;
            newRow[140] = 0;
            newRow[141] = 0;
            newRow[142] = 0;
            newRow[143] = 0;
            newRow[144] = 0;
            newRow[145] = 0;
            newRow[146] = 0;
            newRow[147] = 0;
            newRow[148] = 0;
            newRow[149] = 0;
            newRow[150] = 0;
            newRow[151] = 0;
            newRow[152] = 0;
            newRow[153] = 0;
            newRow[154] = 0;
            newRow[155] = 0;
            newRow[156] = 0;
            newRow[157] = 0;
            newRow[158] = 0;
            newRow[159] = 0;
            newRow[160] = 0;
            newRow[161] = 0;
            newRow[162] = 0;
            newRow[163] = 0;
            newRow[164] = 0;
            newRow[165] = 0;
            newRow[166] = 0;
            newRow[167] = 0;
            newRow[168] = 0;
            newRow[169] = 0;
            newRow[170] = 0;
            newRow[171] = 0;
            newRow[172] = 0;
            newRow[173] = 0;
            newRow[174] = 0;
            newRow[175] = 0;
            newRow[176] = 0;
            newRow[177] = 0;
            newRow[178] = 0;
            newRow[179] = 0;
            newRow[180] = 0;

            pairs.Clear();

            BgColor = ColorMeasured;
            pairs.Add(new MeasurementPair()
            {//THE COLOUR DISPLAYED HERE ARE THE BG COLOUR CAPTURED
              BgColor = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(ColorMeasured.UP.ToString()), VP = Convert.ToDouble(ColorMeasured.VP.ToString()) }
            });
              }
              //white point capture
              else
              {
            //newRow[0] = R.ToString();
            //newRow[1] = G.ToString();
            //newRow[2] = B.ToString();
            //newRow[3] = 0;
            //newRow[4] = 0;
            //newRow[5] = 0;
            //newRow[6] = 0;
            //newRow[7] = 0;
            //newRow[8] = 0;
            //newRow[9] = 0;
            //newRow[10] = 0;
            //newRow[11] = 0;
            //newRow[12] = 0;
            //newRow[13] = 0;
            //newRow[14] = 0;
            //newRow[15] = 0;
            //newRow[16] = 0;
            //newRow[17] = 0;
            //newRow[18] = 0;
            //newRow[19] = BgR.ToString();
            //newRow[20] = BgG.ToString();
            //newRow[21] = BgB.ToString();
            //newRow[22] = 0;
            //newRow[23] = 0;
            //newRow[24] = 0;
            //newRow[25] = 0;
            //newRow[26] = 0;
            //newRow[27] = 0;
            //newRow[28] = 0;
            //newRow[29] = 0;
            //newRow[30] = ColorMeasured.L.ToString();
            //newRow[31] = ColorMeasured.U.ToString();
            //newRow[32] = ColorMeasured.V.ToString();
            //newRow[33] = ColorMeasured.UP.ToString();
            //newRow[34] = ColorMeasured.VP.ToString();
            //newRow[35] = MR.ToString();
            //newRow[36] = MG.ToString();
            //newRow[37] = MB.ToString();

            newRow[0] = R.ToString();
            newRow[1] = G.ToString();
            newRow[2] = B.ToString();
            newRow[3] = 0;
            newRow[4] = 0;
            newRow[5] = 0;
            newRow[6] = 0;
            newRow[7] = 0;
            newRow[8] = 0;
            newRow[9] = 0;
            newRow[10] = 0;
            newRow[11] = 0;
            newRow[12] = 0;
            newRow[13] = 0;
            newRow[14] = 0;
            newRow[15] = 0;
            newRow[16] = 0;
            newRow[17] = 0;
            newRow[18] = 0;
            newRow[19] = 0;
            newRow[20] = 0;
            newRow[21] = 0;
            newRow[22] = 0;
            newRow[23] = 0;
            newRow[24] = 0;
            newRow[25] = 0;
            newRow[26] = 0;
            newRow[27] = 0;
            newRow[28] = 0;
            newRow[29] = 0;
            newRow[30] = 0;
            newRow[31] = 0;
            newRow[32] = 0;
            newRow[33] = 0;
            newRow[34] = 0;
            newRow[35] = 0;
            newRow[36] = 0;
            newRow[37] = 0;
            newRow[38] = 0;
            newRow[39] = 0;
            newRow[40] = 0;
            newRow[41] = 0;
            newRow[42] = 0;
            newRow[43] = 0;
            newRow[44] = 0;
            newRow[45] = 0;
            newRow[46] = 0;
            newRow[47] = 0;
            newRow[48] = 0;
            newRow[49] = 0;
            newRow[50] = 0;
            newRow[51] = 0;
            newRow[52] = 0;
            newRow[53] = 0;
            newRow[54] = 0;
            newRow[55] = 0;
            newRow[56] = 0;
            newRow[57] = 0;
            newRow[58] = 0;
            newRow[59] = 0;
            newRow[60] = 0;
            newRow[61] = 0;
            newRow[62] = 0;
            newRow[63] = 0;
            newRow[64] = 0;
            newRow[65] = 0;
            newRow[66] = 0;
            newRow[67] = 0;
            newRow[68] = 0;
            newRow[69] = 0;
            newRow[70] = BgR.ToString();
            newRow[71] = BgG.ToString();
            newRow[72] = BgB.ToString();
            newRow[73] = 0;
            newRow[74] = 0;
            newRow[75] = 0;
            newRow[76] = 0;
            newRow[77] = 0;
            newRow[78] = 0;
            newRow[79] = 0;
            newRow[80] = 0;
            newRow[81] = 0;
            newRow[82] = 0;
            newRow[83] = 0;
            newRow[84] = 0;
            newRow[85] = 0;
            newRow[86] = 0;
            newRow[87] = 0;
            newRow[88] = 0;
            newRow[89] = 0;
            newRow[90] = 0;
            newRow[91] = 0;
            newRow[92] = 0;
            newRow[93] = 0;
            newRow[94] = 0;
            newRow[95] = 0;
            newRow[96] = 0;
            newRow[97] = 0;
            newRow[98] = ColorMeasured.L.ToString();
            newRow[99] = ColorMeasured.U.ToString();
            newRow[100] = ColorMeasured.V.ToString();
            newRow[101] = ColorMeasured.UP.ToString();
            newRow[102] = ColorMeasured.VP.ToString();
            newRow[103] = ColorMeasured.LA.ToString();
            newRow[104] = ColorMeasured.A.ToString();
            newRow[105] = ColorMeasured.B.ToString();
            newRow[106] = ColorMeasuredXYZ.X.ToString();
            newRow[107] = ColorMeasuredXYZ.Y.ToString();
            newRow[108] = ColorMeasuredXYZ.Z.ToString();
            newRow[109] = MR.ToString();
            newRow[110] = MG.ToString();
            newRow[111] = MB.ToString();
            newRow[112] = 0;
            newRow[113] = 0;
            newRow[114] = 0;
            newRow[115] = 0;
            newRow[116] = 0;
            newRow[117] = 0;
            newRow[118] = 0;
            newRow[119] = 0;
            newRow[120] = 0;
            newRow[121] = 0;
            newRow[122] = 0;
            newRow[123] = 0;
            newRow[124] = 0;
            newRow[125] = 0;
            newRow[126] = 0;
            newRow[127] = 0;
            newRow[128] = 0;
            newRow[129] = 0;
            newRow[130] = 0;
            newRow[131] = 0;
            newRow[132] = 0;
            newRow[133] = 0;
            newRow[134] = 0;
            newRow[135] = 0;
            newRow[136] = 0;
            newRow[137] = 0;
            newRow[138] = 0;
            newRow[139] = 0;
            newRow[140] = 0;
            newRow[141] = 0;
            newRow[142] = 0;
            newRow[143] = 0;
            newRow[144] = 0;
            newRow[145] = 0;
            newRow[146] = 0;
            newRow[147] = 0;
            newRow[148] = 0;
            newRow[149] = 0;
            newRow[150] = 0;
            newRow[151] = 0;
            newRow[152] = 0;
            newRow[153] = 0;
            newRow[154] = 0;
            newRow[155] = 0;
            newRow[156] = 0;
            newRow[157] = 0;
            newRow[158] = 0;
            newRow[159] = 0;
            newRow[160] = 0;
            newRow[161] = 0;
            newRow[162] = 0;
            newRow[163] = 0;
            newRow[164] = 0;
            newRow[165] = 0;
            newRow[166] = 0;
            newRow[167] = 0;
            newRow[168] = 0;
            newRow[169] = 0;
            newRow[170] = 0;
            newRow[171] = 0;
            newRow[172] = 0;
            newRow[173] = 0;
            newRow[174] = 0;
            newRow[175] = 0;
            newRow[176] = 0;
            newRow[177] = 0;
            newRow[178] = 0;
            newRow[179] = 0;
            newRow[180] = 0;

            pairs.Add(new MeasurementPair()
            {
              // HERE 11 AND 12 ARE THE COLOUR CATPTURED BY THE CAMERA FOR DISPLAY 33 AND 34 ARE MIXED COLOURS
              BgColor = new PerceptionLib.Color() { L = 0, UP = Convert.ToDouble(ColorMeasured.UP.ToString()), VP = Convert.ToDouble(ColorMeasured.VP.ToString()) }
            });

              }

              R = 10;
              dt.Rows.Add(newRow);

              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt.DefaultView));
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            }

            //taking back the measured value of bg to all the data set
            // adding mixed valued for cat and absolute back to all
            int totalRow = BgNo * FgNo;
            for (int i = 1; i < BgNo; i++)
            {

              for (int j = 0; j < fgNo; j++)
              {
            int rowNo = (i * FgNo) + j;
            // i am doing -1 cos the data set starts from 0 ,.. so in the first one it will still b e bg*fg but i value will be 0
            dt.Rows[rowNo][84] = dt.Rows[(totalRow) + i - 1][84].ToString();
            dt.Rows[rowNo][85] = dt.Rows[(totalRow) + i - 1][85].ToString();
            dt.Rows[rowNo][86] = dt.Rows[(totalRow) + i - 1][86].ToString();

            dt.Rows[rowNo][87] = dt.Rows[(totalRow) + i - 1][87].ToString();
            dt.Rows[rowNo][88] = dt.Rows[(totalRow) + i - 1][88].ToString();
            dt.Rows[rowNo][89] = dt.Rows[(totalRow) + i - 1][89].ToString();
            dt.Rows[rowNo][90] = dt.Rows[(totalRow) + i - 1][90].ToString();
            dt.Rows[rowNo][91] = dt.Rows[(totalRow) + i - 1][91].ToString();
            dt.Rows[rowNo][92] = dt.Rows[(totalRow) + i - 1][92].ToString();
            dt.Rows[rowNo][93] = dt.Rows[(totalRow) + i - 1][93].ToString();
            dt.Rows[rowNo][94] = dt.Rows[(totalRow) + i - 1][94].ToString();
            dt.Rows[rowNo][95] = dt.Rows[(totalRow) + i - 1][95].ToString();
            dt.Rows[rowNo][96] = dt.Rows[(totalRow) + i - 1][96].ToString();
            dt.Rows[rowNo][97] = dt.Rows[(totalRow) + i - 1][97].ToString();

            ColorToShowXYZ.X = Convert.ToDouble(dt.Rows[rowNo][11].ToString());
            ColorToShowXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][12].ToString());
            ColorToShowXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][13].ToString());

            ColorMeasuredXYZ.X = Convert.ToDouble(dt.Rows[rowNo][25].ToString());
            ColorMeasuredXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][26].ToString());
            ColorMeasuredXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][27].ToString());

            ColorBackGroundXYZ.X = Convert.ToDouble(dt.Rows[rowNo][81].ToString());
            ColorBackGroundXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][82].ToString());
            ColorBackGroundXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][83].ToString());

            //
            //McolorBackGroundXYZ.X = Convert.ToDouble(dt.Rows[rowNo][95].ToString());
            //McolorBackGroundXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][96].ToString());
            //McolorBackGroundXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][97].ToString());

            ColorToShow.L = Convert.ToDouble(dt.Rows[rowNo][3].ToString());
            ColorToShow.U = Convert.ToDouble(dt.Rows[rowNo][4].ToString());
            ColorToShow.V = Convert.ToDouble(dt.Rows[rowNo][5].ToString());
            ColorToShow.LA = Convert.ToDouble(dt.Rows[rowNo][8].ToString());
            ColorToShow.A = Convert.ToDouble(dt.Rows[rowNo][9].ToString());
            ColorToShow.B = Convert.ToDouble(dt.Rows[rowNo][10].ToString());

            ColorMeasured.L = Convert.ToDouble(dt.Rows[rowNo][17].ToString());
            ColorMeasured.U = Convert.ToDouble(dt.Rows[rowNo][18].ToString());
            ColorMeasured.V = Convert.ToDouble(dt.Rows[rowNo][19].ToString());
            ColorMeasured.LA = Convert.ToDouble(dt.Rows[rowNo][22].ToString());
            ColorMeasured.A = Convert.ToDouble(dt.Rows[rowNo][23].ToString());
            ColorMeasured.B = Convert.ToDouble(dt.Rows[rowNo][24].ToString());

            //  HERE I CHOSE TO USE  BG COLOR IN PLACES OF MEASURE COLOR !!
            BgColor.L = Convert.ToDouble(dt.Rows[rowNo][98].ToString());
            BgColor.U = Convert.ToDouble(dt.Rows[rowNo][99].ToString());
            BgColor.V = Convert.ToDouble(dt.Rows[rowNo][100].ToString());
            BgColor.LA = Convert.ToDouble(dt.Rows[rowNo][103].ToString());
            BgColor.A = Convert.ToDouble(dt.Rows[rowNo][104].ToString());
            BgColor.B = Convert.ToDouble(dt.Rows[rowNo][105].ToString());

            BradXYZ.X = Convert.ToDouble(dt.Rows[rowNo][36].ToString());
            BradXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][37].ToString());
            BradXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][38].ToString());

            VonXYZ.X = Convert.ToDouble(dt.Rows[rowNo][50].ToString());
            VonXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][51].ToString());
            VonXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][52].ToString());

            ScalingXYZ.X = Convert.ToDouble(dt.Rows[rowNo][64].ToString());
            ScalingXYZ.Y = Convert.ToDouble(dt.Rows[rowNo][65].ToString());
            ScalingXYZ.Z = Convert.ToDouble(dt.Rows[rowNo][66].ToString());

            AcolorXYZ = Util.ColorSpaceConverter.AddXYZ(ColorToShowXYZ, ColorBackGroundXYZ);
            Acolor = Util.ColorSpaceConverter.XYZToLABLUV(ColorToShowXYZ, ColorBackGroundXYZ);
            acolorRGB = Util.ColorSpaceConverter.XYZToRGB(ColorToShowXYZ, ColorBackGroundXYZ);

            // i use original bg color not captured bg color

            MBradXYZ = Util.ColorSpaceConverter.AddXYZ(BradXYZ, ColorBackGroundXYZ);
            MBradcolor = Util.ColorSpaceConverter.XYZToLABLUV(BradXYZ, ColorBackGroundXYZ);
            MbradRGB = Util.ColorSpaceConverter.XYZToRGB(BradXYZ, ColorBackGroundXYZ);

            MVonXYZ = Util.ColorSpaceConverter.AddXYZ(VonXYZ, ColorBackGroundXYZ);
            MVoncolor = Util.ColorSpaceConverter.XYZToLABLUV(VonXYZ, ColorBackGroundXYZ);
            MVonRGB = Util.ColorSpaceConverter.XYZToRGB(VonXYZ, ColorBackGroundXYZ);

            MScalingXYZ = Util.ColorSpaceConverter.AddXYZ(ScalingXYZ, ColorBackGroundXYZ);
            MScalingcolor = Util.ColorSpaceConverter.XYZToLABLUV(ScalingXYZ, ColorBackGroundXYZ);
            MscalingRGB = Util.ColorSpaceConverter.XYZToRGB(ScalingXYZ, ColorBackGroundXYZ);

            dt.Rows[rowNo][112] = Acolor.L.ToString();
            dt.Rows[rowNo][113] = Acolor.U.ToString();
            dt.Rows[rowNo][114] = Acolor.V.ToString();
            dt.Rows[rowNo][115] = Acolor.UP.ToString();
            dt.Rows[rowNo][116] = Acolor.VP.ToString();
            dt.Rows[rowNo][117] = Acolor.LA.ToString();
            dt.Rows[rowNo][118] = Acolor.A.ToString();
            dt.Rows[rowNo][119] = Acolor.B.ToString();
            dt.Rows[rowNo][120] = AcolorXYZ.X.ToString();
            dt.Rows[rowNo][121] = AcolorXYZ.Y.ToString();
            dt.Rows[rowNo][122] = AcolorXYZ.Z.ToString();
            dt.Rows[rowNo][123] = acolorRGB.R.ToString();
            dt.Rows[rowNo][124] = acolorRGB.G.ToString();
            dt.Rows[rowNo][125] = acolorRGB.B.ToString();

            dt.Rows[rowNo][126] = MBradcolor.L.ToString();
            dt.Rows[rowNo][127] = MBradcolor.U.ToString();
            dt.Rows[rowNo][128] = MBradcolor.V.ToString();
            dt.Rows[rowNo][129] = MBradcolor.UP.ToString();
            dt.Rows[rowNo][130] = MBradcolor.VP.ToString();
            dt.Rows[rowNo][131] = MBradcolor.LA.ToString();
            dt.Rows[rowNo][132] = MBradcolor.A.ToString();
            dt.Rows[rowNo][133] = MBradcolor.B.ToString();
            dt.Rows[rowNo][134] = MBradXYZ.X.ToString();
            dt.Rows[rowNo][135] = MBradXYZ.Y.ToString();
            dt.Rows[rowNo][136] = MBradXYZ.Z.ToString();
            dt.Rows[rowNo][137] = MbradRGB.R.ToString();
            dt.Rows[rowNo][138] = MbradRGB.G.ToString();
            dt.Rows[rowNo][139] = MbradRGB.B.ToString();

            dt.Rows[rowNo][140] = MVoncolor.L.ToString();
            dt.Rows[rowNo][141] = MVoncolor.U.ToString();
            dt.Rows[rowNo][142] = MVoncolor.V.ToString();
            dt.Rows[rowNo][143] = MVoncolor.UP.ToString();
            dt.Rows[rowNo][144] = MVoncolor.VP.ToString();
            dt.Rows[rowNo][145] = MVoncolor.LA.ToString();
            dt.Rows[rowNo][146] = MVoncolor.A.ToString();
            dt.Rows[rowNo][147] = MVoncolor.B.ToString();
            dt.Rows[rowNo][148] = MVonXYZ.X.ToString();
            dt.Rows[rowNo][149] = MVonXYZ.Y.ToString();
            dt.Rows[rowNo][150] = MVonXYZ.Z.ToString();
            dt.Rows[rowNo][151] = MVonRGB.R.ToString();
            dt.Rows[rowNo][152] = MVonRGB.G.ToString();
            dt.Rows[rowNo][153] = MVonRGB.B.ToString();

            dt.Rows[rowNo][154] = MScalingcolor.L.ToString();
            dt.Rows[rowNo][155] = MScalingcolor.U.ToString();
            dt.Rows[rowNo][156] = MScalingcolor.V.ToString();
            dt.Rows[rowNo][157] = MScalingcolor.UP.ToString();
            dt.Rows[rowNo][158] = MScalingcolor.VP.ToString();
            dt.Rows[rowNo][159] = MScalingcolor.LA.ToString();
            dt.Rows[rowNo][160] = MScalingcolor.A.ToString();
            dt.Rows[rowNo][161] = MScalingcolor.B.ToString();
            dt.Rows[rowNo][162] = MScalingXYZ.X.ToString();
            dt.Rows[rowNo][163] = MScalingXYZ.Y.ToString();
            dt.Rows[rowNo][164] = MScalingXYZ.Z.ToString();
            dt.Rows[rowNo][165] = MscalingRGB.R.ToString();
            dt.Rows[rowNo][166] = MscalingRGB.G.ToString();
            dt.Rows[rowNo][167] = MscalingRGB.B.ToString();
            dt.Rows[rowNo][168] = 0;
            dt.Rows[rowNo][169] = acolorRGB.gmt;
            dt.Rows[rowNo][170] = MbradRGB.gmt;
            dt.Rows[rowNo][171] = MVonRGB.gmt;
            dt.Rows[rowNo][172] = MscalingRGB.gmt;
            dt.Rows[rowNo][173] = PerceptionLib.Color.ColorDistanceCal(BgColor, Acolor).ToString();
            dt.Rows[rowNo][174] = PerceptionLib.Color.ColorDistanceCalAB(BgColor, Acolor).ToString();
            dt.Rows[rowNo][175] = PerceptionLib.Color.ColorDistanceCal(BgColor, Bradcolor).ToString();
            dt.Rows[rowNo][176] = PerceptionLib.Color.ColorDistanceCalAB(BgColor, Bradcolor).ToString();
            dt.Rows[rowNo][177] = PerceptionLib.Color.ColorDistanceCal(BgColor, Voncolor).ToString();
            dt.Rows[rowNo][178] = PerceptionLib.Color.ColorDistanceCalAB(BgColor, Voncolor).ToString();
            dt.Rows[rowNo][179] = PerceptionLib.Color.ColorDistanceCal(BgColor, Scalingcolor).ToString();
            dt.Rows[rowNo][180] = PerceptionLib.Color.ColorDistanceCalAB(BgColor, Scalingcolor).ToString();
            dt.Rows[rowNo][181] = PerceptionLib.Color.ColorDistanceCalAB(ColorToShow, ColorMeasured).ToString();
            dt.Rows[rowNo][182] = PerceptionLib.Color.ColorDistanceCalAB(BgColor, ColorMeasured).ToString();

              }
            }

            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            dataTable = dt;
              });
              cmb_graph.IsEnabled = true;
              btn_ExportGrid.IsEnabled = true;
              // captureDevice.Dispose();
        }
コード例 #31
0
        private void MathCal_Click(object sender, RoutedEventArgs e)
        {
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\Reduscer_for_phoneCAT.csv");
            DataTable bin = new DataTable();
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                dtgrid_corrDisplay.Items.Refresh();
                bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

            }));
            PerceptionLib.CIEXYZ ColorToShowXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ BradXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ VonXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ ScalingXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.Color ColorToShow = new PerceptionLib.Color();

            foreach (DataRow dr in bin.Rows)
            {
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //CAT LAB caluclation

                //brad
                //ColorToShowXYZ.X = Convert.ToDouble(dr["bradX"].ToString());
                //ColorToShowXYZ.Y = Convert.ToDouble(dr["bradY"].ToString());
                //ColorToShowXYZ.Z = Convert.ToDouble(dr["bradZ"].ToString());

                //ColorToShow = PerceptionLib.Color.ToLAB(ColorToShowXYZ);

                //dr["bradL"] = ColorToShow.LA.ToString();
                //dr["bradA"] = ColorToShow.A.ToString();
                //dr["bradB"] = ColorToShow.B.ToString();

                ////Von
                //ColorToShowXYZ.X = Convert.ToDouble(dr["VonX"].ToString());
                //ColorToShowXYZ.Y = Convert.ToDouble(dr["VonY"].ToString());
                //ColorToShowXYZ.Z = Convert.ToDouble(dr["VonZ"].ToString());

                //ColorToShow = PerceptionLib.Color.ToLAB(ColorToShowXYZ);

                ////scaling
                //dr["vonL"] = ColorToShow.LA.ToString();
                //dr["vonA"] = ColorToShow.A.ToString();
                //dr["vonB"] = ColorToShow.B.ToString();

                //ColorToShowXYZ.X = Convert.ToDouble(dr["SX"].ToString());
                //ColorToShowXYZ.Y = Convert.ToDouble(dr["SY"].ToString());
                //ColorToShowXYZ.Z = Convert.ToDouble(dr["SZ"].ToString());

                //ColorToShow = PerceptionLib.Color.ToLAB(ColorToShowXYZ);

                //dr["sL"] = ColorToShow.LA.ToString();
                //dr["sA"] = ColorToShow.A.ToString();
                //dr["sB"] = ColorToShow.B.ToString();

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //xyz caluclation

                ColorToShowXYZ.X = Convert.ToDouble(dr["X"].ToString());
                ColorToShowXYZ.Y = Convert.ToDouble(dr["Y"].ToString());
                ColorToShowXYZ.Z = Convert.ToDouble(dr["Z"].ToString());

                BradXYZ = CATCalulation.bradford(ColorToShowXYZ);
                VonXYZ = CATCalulation.VonKries(ColorToShowXYZ);
                ScalingXYZ = CATCalulation.XYZScaling(ColorToShowXYZ);

                dr["bradX"] = BradXYZ.X.ToString();
                dr["bradY"] = BradXYZ.Y.ToString();
                dr["bradZ"] = BradXYZ.Z.ToString();

                dr["VonX"] = VonXYZ.X.ToString();
                dr["VonY"] = VonXYZ.Y.ToString();
                dr["VonZ"] = VonXYZ.Z.ToString();

                dr["ScalX"] = ScalingXYZ.X.ToString();
                dr["ScalY"] = ScalingXYZ.Y.ToString();
                dr["ScalZ"] = ScalingXYZ.Z.ToString();

                ////////////////////////////////////////////////////////////////////////////////////////////////////////////
                //ColorToShow.LA = Convert.ToDouble(dr["L"].ToString());
                //ColorToShow.A = Convert.ToDouble(dr["A"].ToString());
                //ColorToShow.B = Convert.ToDouble(dr["B"].ToString());
                //PerceptionLib.RGBValue ab = PerceptionLib.Color.ToRBGFromLAB(ColorToShow);

                ////Hex color
                //String Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                //dr["HEX"] = "0x" + Hex;
                ////////////////////////////////////////////////////////////////////////////////////////////////////////////

                //ColorToShowXYZ = new CIEXYZ(0, 0, 0);
                //ColorToShowXYZ.X = Convert.ToDouble(dr["X"].ToString());
                //ColorToShowXYZ.Y = Convert.ToDouble(dr["Y"].ToString());
                //ColorToShowXYZ.Z = Convert.ToDouble(dr["Z"].ToString());

                //ColorToShow = PerceptionLib.Color.ToLUV(ColorToShowXYZ);
                //PerceptionLib.RGBValue ab = PerceptionLib.Color.ToRBGFromLAB(ColorToShow);

                //dr["L"] = ColorToShow.LA.ToString();
                //dr["A"] = ColorToShow.A.ToString();
                //dr["LB"] = ColorToShow.B.ToString();
                //dr["R"] = ab.R.ToString();
                //dr["G"] = ab.G.ToString();
                //dr["B"] = ab.B.ToString();

                //String Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                //dr["HEX"] = "0x" + Hex;

                //////////////////////////////////////////////////////////////////////////////////////////////////////////
                // hue calculation
                //ColorToShow.LA = Convert.ToDouble(dr["L"].ToString());
                //ColorToShow.A = Convert.ToDouble(dr["A"].ToString());
                //ColorToShow.B = Convert.ToDouble(dr["B"].ToString());
                //double hue= CATCalulation.HueAngle(ColorToShow);
                //dr["Hue"] = hue.ToString();

                Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = bin.DefaultView));
                Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

            }
            btn_ExportGrid.IsEnabled = true;
        }
コード例 #32
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        public static Color ToLAB(CIEXYZ xyz)
        {
            double Fx, Fy, Fz;
              Color rColor = new Color();
              //CIEXYZ xyz = RGBToXYZ(cRGB);

              double yr = xyz.Y / CIEXYZ.D65.Y;
              double xr = xyz.X / CIEXYZ.D65.X;
              double zr = xyz.Z / CIEXYZ.D65.Z;

              Fx = FX(xr);
              Fy = FX(yr);
              Fz = FX(zr);

              rColor.LA = Lxyz(yr);
              rColor.A = 500 * (Fx - Fy);
              rColor.B = 200 * (Fy - Fz);

              return rColor;
        }
コード例 #33
0
        //cat
        private void CatCal_Click(object sender, RoutedEventArgs e)
        {
            // PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\small pro cat mixture\SmallPro800.csv");
            // PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\phone\PhonePredcition800_diff200.csv");
            //PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\value\Reduscer_HEX.csv");
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\PerceptionLib\bin\previous data\cs-200 data\color mixing\phone data pewdiction data 800\Bg4.csv");
            DataTable bin = new DataTable();
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                dtgrid_corrDisplay.Items.Refresh();
                bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

            }));
            PerceptionLib.CIEXYZ ColorToShowXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ ColorMeasuredXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.Color ColorMeasured_fordiff = new PerceptionLib.Color();

            PerceptionLib.CIEXYZ DBg = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ TDBg = new CIEXYZ(0, 0, 0);

            PerceptionLib.CIEXYZ AXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ DAXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ TDAXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.CIEXYZ BinXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ TDBinXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ DBinXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.CIEXYZ BradXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ VonXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ ScalXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.CIEXYZ TDBradXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ TDVonXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ TDScalXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.CIEXYZ DBradXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ DVonXYZ = new CIEXYZ(0, 0, 0);
            PerceptionLib.CIEXYZ DScalXYZ = new CIEXYZ(0, 0, 0);

            PerceptionLib.Color Acolor = new PerceptionLib.Color();
            PerceptionLib.Color TDAcolor = new PerceptionLib.Color();
            PerceptionLib.Color DAcolor = new PerceptionLib.Color();

            PerceptionLib.Color Bin = new PerceptionLib.Color();
            PerceptionLib.Color TDBin = new PerceptionLib.Color();
            PerceptionLib.Color DBin = new PerceptionLib.Color();

            PerceptionLib.Color Brad = new PerceptionLib.Color();
            PerceptionLib.Color Von = new PerceptionLib.Color();
            PerceptionLib.Color Scal = new PerceptionLib.Color();
            PerceptionLib.Color TDBrad = new PerceptionLib.Color();
            PerceptionLib.Color TDVon = new PerceptionLib.Color();
            PerceptionLib.Color TDScal = new PerceptionLib.Color();
            PerceptionLib.Color DBrad = new PerceptionLib.Color();
            PerceptionLib.Color DVon = new PerceptionLib.Color();
            PerceptionLib.Color DScal = new PerceptionLib.Color();
            PerceptionLib.RGBValue ab;

            /// small pro
            //CIEXYZ screenWt = new CIEXYZ(0.265572, 0.282182, 0.481033);

            //CIEXYZ screenBgWt = new CIEXYZ(0.9504, 0.990041, 1.0888);

            //phone
            CIEXYZ screenWt = new CIEXYZ(0.383264, 0.395001, 0.369982);

            CIEXYZ screenBgWt = new CIEXYZ(0.724775, 0.759896, 0.727336);

            //     ;
            //string Von      ;
            //string Scaling  ;
            //string TDBrad   ;
            //string TDVon    ;
            //string TDScaling;
            //string DBrad    ;
            //string DVon     ;
            //string DScaling ;

            PerceptionLib.Color ColorToShow = new PerceptionLib.Color();
            PerceptionLib.Color ColorMeasured = new PerceptionLib.Color();
            int i = 0;
            foreach (DataRow dr in bin.Rows)
            {
                //i++;

                DBg.X = Convert.ToDouble(dr["BX"].ToString());
                DBg.Y = Convert.ToDouble(dr["BY"].ToString());
                DBg.Z = Convert.ToDouble(dr["BZ"].ToString());

                TDBg.X = Convert.ToDouble(dr["BMX"].ToString());
                TDBg.Y = Convert.ToDouble(dr["BMY"].ToString());
                TDBg.Z = Convert.ToDouble(dr["BMZ"].ToString());

                //bin fg
                BinXYZ.X = Convert.ToDouble(dr["BinX"].ToString());
                BinXYZ.Y = Convert.ToDouble(dr["BinY"].ToString());
                BinXYZ.Z = Convert.ToDouble(dr["BinZ"].ToString());

                Bin = PerceptionLib.Color.ToLAB(BinXYZ, screenWt);
                dr["BP_Fg_L"] = Bin.LA.ToString();
                dr["BP_Fg_a"] = Bin.A.ToString();
                dr["BP_Fg_b"] = Bin.B.ToString();

                ab = PerceptionLib.Color.ToRBGFromLAB(Bin);
                String Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["BP_Fg_RRGGBB"] = "0x" + Hex;

                //pure

                AXYZ.X = Convert.ToDouble(dr["X"].ToString());
                AXYZ.Y = Convert.ToDouble(dr["Y"].ToString());
                AXYZ.Z = Convert.ToDouble(dr["Z"].ToString());

                Acolor.LA = Convert.ToDouble(dr["Fg_L"].ToString());
                Acolor.A = Convert.ToDouble(dr["Fg_A"].ToString());
                Acolor.B = Convert.ToDouble(dr["Fg_B"].ToString());

                ab = PerceptionLib.Color.ToRBGFromLAB(Acolor);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["Fg_RRGGBB"] = "0x" + Hex;

                BradXYZ.X = Convert.ToDouble(dr["BradX"].ToString());
                BradXYZ.Y = Convert.ToDouble(dr["BradY"].ToString());
                BradXYZ.Z = Convert.ToDouble(dr["BradZ"].ToString());

                Brad = PerceptionLib.Color.ToLAB(BradXYZ, screenWt);
                dr["CAT1_Fg_L"] = Brad.LA.ToString();
                dr["CAT1_Fg_a"] = Brad.A.ToString();
                dr["CAT1_Fg_b"] = Brad.B.ToString();

                ab = PerceptionLib.Color.ToRBGFromLAB(Brad);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT1_Fg_RRGGBB"] = "0x" + Hex;

                VonXYZ.X = Convert.ToDouble(dr["VonX"].ToString());
                VonXYZ.Y = Convert.ToDouble(dr["VonY"].ToString());
                VonXYZ.Z = Convert.ToDouble(dr["VonZ"].ToString());

                Von = PerceptionLib.Color.ToLAB(VonXYZ, screenWt);
                dr["CAT2_Fg_L"] = Von.LA.ToString();
                dr["CAT2_Fg_a"] = Von.A.ToString();
                dr["CAT2_Fg_b"] = Von.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(Von);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT2_Fg_RRGGBB"] = "0x" + Hex;

                ScalXYZ.X = Convert.ToDouble(dr["ScalX"].ToString());
                ScalXYZ.Y = Convert.ToDouble(dr["ScalY"].ToString());
                ScalXYZ.Z = Convert.ToDouble(dr["ScalZ"].ToString());

                Scal = PerceptionLib.Color.ToLAB(ScalXYZ, screenWt);
                dr["CAT3_Fg_L"] = Scal.LA.ToString();
                dr["CAT3_Fg_a"] = Scal.A.ToString();
                dr["CAT3_Fg_b"] = Scal.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(Scal);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT3_Fg_RRGGBB"] = "0x" + Hex;

                // color measured
                ColorMeasuredXYZ.X = Convert.ToDouble(dr["MX"].ToString());
                ColorMeasuredXYZ.Y = Convert.ToDouble(dr["MY"].ToString());
                ColorMeasuredXYZ.Z = Convert.ToDouble(dr["MZ"].ToString());
                ColorMeasured = PerceptionLib.Color.ToLAB(ColorMeasuredXYZ, screenBgWt);
                ColorMeasured_fordiff = PerceptionLib.Color.ToLAB(ColorMeasuredXYZ, screenWt);

                dr["Bc_L"] = ColorMeasured.LA.ToString();
                dr["Bc_a"] = ColorMeasured.A.ToString();
                dr["Bc_b"] = ColorMeasured.B.ToString();

                ab = PerceptionLib.Color.ToRBGFromLAB(ColorMeasured);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["Bc_RRGGBB"] = "0x" + Hex;

                //aCOLOR

                TDAXYZ.X = AXYZ.X + TDBg.X;
                TDAXYZ.Y = AXYZ.Y + TDBg.Y;
                TDAXYZ.Z = AXYZ.Z + TDBg.Z;

                TDAcolor = PerceptionLib.Color.ToLAB(TDAXYZ, screenBgWt);
                dr["P_Bc_TD_L"] = TDAcolor.LA.ToString();
                dr["P_Bc_TD_a"] = TDAcolor.A.ToString();
                dr["P_Bc_TD_b"] = TDAcolor.B.ToString();

                ab = PerceptionLib.Color.ToRBGFromLAB(TDAcolor);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["P_Bc_TD_RRGGBB"] = "0x" + Hex;

                DAXYZ.X = AXYZ.X + DBg.X;
                DAXYZ.Y = AXYZ.Y + DBg.Y;
                DAXYZ.Z = AXYZ.Z + DBg.Z;

                DAcolor = PerceptionLib.Color.ToLAB(DAXYZ, screenBgWt);
                dr["P_Bc_ND_L"] = DAcolor.LA.ToString();
                dr["P_Bc_ND_a"] = DAcolor.A.ToString();
                dr["P_Bc_ND_b"] = DAcolor.B.ToString();

                ab = PerceptionLib.Color.ToRBGFromLAB(DAcolor);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["P_Bc_ND_RRGGBB"] = "0x" + Hex;

                //brad

                TDBradXYZ.X = BradXYZ.X + TDBg.X;
                TDBradXYZ.Y = BradXYZ.Y + TDBg.Y;
                TDBradXYZ.Z = BradXYZ.Z + TDBg.Z;

                TDBrad = PerceptionLib.Color.ToLAB(TDBradXYZ, screenBgWt);
                dr["CAT1_P_Bc_TD_L"] = TDBrad.LA.ToString();
                dr["CAT1_P_Bc_TD_a"] = TDBrad.A.ToString();
                dr["CAT1_P_Bc_TD_b"] = TDBrad.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(TDBrad);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT1_P_Bc_TD_RRGGBB"] = "0x" + Hex;

                DBradXYZ.X = BradXYZ.X + DBg.X;
                DBradXYZ.Y = BradXYZ.Y + DBg.Y;
                DBradXYZ.Z = BradXYZ.Z + DBg.Z;

                DBrad = PerceptionLib.Color.ToLAB(DBradXYZ, screenBgWt);
                dr["CAT1_P_Bc_ND_L"] = DBrad.LA.ToString();
                dr["CAT1_P_Bc_ND_a"] = DBrad.A.ToString();
                dr["CAT1_P_Bc_ND_b"] = DBrad.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(DBrad);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT1_P_Bc_ND_RRGGBB"] = "0x" + Hex;

                //von
                TDVonXYZ.X = VonXYZ.X + TDBg.X;
                TDVonXYZ.Y = VonXYZ.Y + TDBg.Y;
                TDVonXYZ.Z = VonXYZ.Z + TDBg.Z;

                TDVon = PerceptionLib.Color.ToLAB(TDVonXYZ, screenBgWt);
                dr["CAT2_P_Bc_TD_L"] = TDVon.LA.ToString();
                dr["CAT2_P_Bc_TD_a"] = TDVon.A.ToString();
                dr["CAT2_P_Bc_TD_b"] = TDVon.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(TDVon);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT2_P_Bc_TD_RRGGBB"] = "0x" + Hex;

                DVonXYZ.X = VonXYZ.X + DBg.X;
                DVonXYZ.Y = VonXYZ.Y + DBg.Y;
                DVonXYZ.Z = VonXYZ.Z + DBg.Z;

                DVon = PerceptionLib.Color.ToLAB(DVonXYZ, screenBgWt);
                dr["CAT2_P_Bc_ND_L"] = DVon.LA.ToString();
                dr["CAT2_P_Bc_ND_a"] = DVon.A.ToString();
                dr["CAT2_P_Bc_ND_b"] = DVon.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(DVon);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT2_P_Bc_ND_RRGGBB"] = "0x" + Hex;

                // scal

                TDScalXYZ.X = ScalXYZ.X + TDBg.X;
                TDScalXYZ.Y = ScalXYZ.Y + TDBg.Y;
                TDScalXYZ.Z = ScalXYZ.Z + TDBg.Z;

                TDScal = PerceptionLib.Color.ToLAB(TDScalXYZ, screenBgWt);
                dr["CAT3_P_Bc_TD_L"] = TDScal.LA.ToString();
                dr["CAT3_P_Bc_TD_a"] = TDScal.A.ToString();
                dr["CAT3_P_Bc_TD_b"] = TDScal.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(TDScal);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT3_P_Bc_TD_RRGGBB"] = "0x" + Hex;

                DScalXYZ.X = ScalXYZ.X + DBg.X;
                DScalXYZ.Y = ScalXYZ.Y + DBg.Y;
                DScalXYZ.Z = ScalXYZ.Z + DBg.Z;

                DScal = PerceptionLib.Color.ToLAB(DScalXYZ, screenBgWt);
                dr["CAT3_P_Bc_ND_L"] = DScal.LA.ToString();
                dr["CAT3_P_Bc_ND_a"] = DScal.A.ToString();
                dr["CAT3_P_Bc_ND_b"] = DScal.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(DScal);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["CAT3_P_Bc_ND_RRGGBB"] = "0x" + Hex;

                //bin
                TDBinXYZ.X = BinXYZ.X + TDBg.X;
                TDBinXYZ.Y = BinXYZ.Y + TDBg.Y;
                TDBinXYZ.Z = BinXYZ.Z + TDBg.Z;

                TDBin = PerceptionLib.Color.ToLAB(TDBinXYZ, screenBgWt);
                dr["BP_P_Bc_TD_L"] = TDBin.LA.ToString();
                dr["BP_P_Bc_TD_a"] = TDBin.A.ToString();
                dr["BP_P_Bc_TD_b"] = TDBin.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(TDBin);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["BP_P_Bc_TD_RRGGBB"] = "0x" + Hex;

                DBinXYZ.X = BinXYZ.X + DBg.X;
                DBinXYZ.Y = BinXYZ.Y + DBg.Y;
                DBinXYZ.Z = BinXYZ.Z + DBg.Z;

                DBin = PerceptionLib.Color.ToLAB(DBinXYZ, screenBgWt);
                dr["BP_P_Bc_ND_L"] = DBin.LA.ToString();
                dr["BP_P_Bc_ND_a"] = DBin.A.ToString();
                dr["BP_P_Bc_ND_b"] = DBin.B.ToString();
                ab = PerceptionLib.Color.ToRBGFromLAB(DBin);
                Hex = PerceptionLib.Color.RGBtoHEX(ab.R, ab.G, ab.B);
                dr["BP_P_Bc_ND_RRGGBB"] = "0x" + Hex;

                dr["Dist_DM_P_TD"] = (PerceptionLib.Color.ColorDistanceCalAB(TDAcolor, ColorMeasured)).ToString();
                dr["Dist_DM_P_ND"] = (PerceptionLib.Color.ColorDistanceCalAB(DAcolor, ColorMeasured)).ToString();

                dr["Dist_CAT1_P_TD"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, TDBrad)).ToString();
                dr["Dist_CAT1_P_ND"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, DBrad)).ToString();

                dr["Dist_CAT2_P_TD"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, TDVon)).ToString();
                dr["Dist_CAT2_P_ND"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, DVon)).ToString();

                dr["Dist_CAT3_P_TD"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, TDScal)).ToString();
                dr["Dist_CAT3_P_ND"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured, DScal)).ToString();

                dr["Dist_BP_P_TD"] = (PerceptionLib.Color.ColorDistanceCalAB(TDBin, ColorMeasured)).ToString();
                dr["Dist_BP_P_ND"] = (PerceptionLib.Color.ColorDistanceCalAB(DBin, ColorMeasured)).ToString();

                dr["Dist_Fg"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured_fordiff, Acolor)).ToString();
                dr["Dist_CAT1_Fg"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured_fordiff, Brad)).ToString();
                dr["Dist_CAT2_Fg"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured_fordiff, Von)).ToString();
                dr["Dist_CAT3_Fg"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured_fordiff, Scal)).ToString();
                dr["Dist_BP_Fg"] = (PerceptionLib.Color.ColorDistanceCalAB(ColorMeasured_fordiff, Bin)).ToString();

            }

            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = bin.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            btn_ExportGrid.IsEnabled = true;
        }
コード例 #34
0
ファイル: Color.cs プロジェクト: hcilab-um/STColorCorrection
        /// <summary>
        /// same function as above but this does it from XYZ
        /// </summary>
        /// <param name="xyz"></param>
        /// <returns></returns>
        public static Color ToLUV(CIEXYZ xyz)
        {
            Color rColor = new Color();
              Color rColorlab = new Color();
              //CIEXYZ xyz = RGBToXYZ(cRGB);

              rColor.UP = (4 * xyz.X) / (xyz.X + (15 * xyz.Y) + (3 * xyz.Z));
              rColor.VP = (9 * xyz.Y) / (xyz.X + (15 * xyz.Y) + (3 * xyz.Z));

              //rColor.UR = (4 * CIEXYZ.D65.X) / (CIEXYZ.D65.X + (15 * CIEXYZ.D65.Y) + (3 * CIEXYZ.D65.Z));
              //rColor.VR = (9 * CIEXYZ.D65.Y) / (CIEXYZ.D65.X + (15 * CIEXYZ.D65.Y) + (3 * CIEXYZ.D65.Z));

              double yr = xyz.Y / CIEXYZ.D65.Y;
              rColor.L = Lxyz(yr);
              rColor.U = (13 * rColor.L) * (rColor.UP - rColor.UR);
              rColor.V = (13 * rColor.L) * (rColor.VP - rColor.VR);
              rColorlab = ToLAB(xyz);
              rColor.LA = rColorlab.LA;
              rColor.A = rColorlab.A;
              rColor.B = rColorlab.B;
              return rColor;
        }
コード例 #35
0
        private void BgCal_Click(object sender, RoutedEventArgs e)
        {
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\DataGrid\DataGrid\bin\value\Predicted_Bg_input.csv");
            DataTable bin = new DataTable();
            Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
            {
                dtgrid_corrDisplay.Items.Refresh();
                bin = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();

            }));

            double OL, OA, OB, px, py, pz, LL, LA, LB;

            PerceptionLib.Color BgColor = new PerceptionLib.Color();
            PerceptionLib.Color LBgColor = new PerceptionLib.Color();

            foreach (DataRow dr in bin.Rows)
            {
                OL = Convert.ToDouble(dr["BGL"].ToString());
                OA = Convert.ToDouble(dr["BGA"].ToString());
                OB = Convert.ToDouble(dr["BGB"].ToString());

                LL = Convert.ToDouble(dr["LumistyL"].ToString());
                LA = Convert.ToDouble(dr["LumistyA"].ToString());
                LB = Convert.ToDouble(dr["LumistyB"].ToString());

                px = Convert.ToDouble(dr["PX"].ToString());
                py = Convert.ToDouble(dr["PY"].ToString());
                pz = Convert.ToDouble(dr["PZ"].ToString());

                PerceptionLib.CIEXYZ xyz = new CIEXYZ(px, py, pz);

                PerceptionLib.Color PLBgColor = PerceptionLib.Color.ToLAB(xyz);

                BgColor.LA = OL;
                BgColor.A = OA;
                BgColor.B = OB;

                LBgColor.LA = LL;
                LBgColor.A = LA;
                LBgColor.B = LB;

                PerceptionLib.ColorRegion cr = PerceptionLib.Color.ToFindColorRegion(BgColor);

                dr["BGLValue"] = cr.LValueFlag.ToString();
                dr["SaturationValue"] = cr.NetralValueFlag.ToString();
                dr["Region"] = cr.RegionValue.ToString();
                dr["PXYZ_EqDistance"] = (PerceptionLib.Color.ColorDistanceCalAB(PLBgColor, LBgColor)).ToString();
            }
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = bin.DefaultView));
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
            btn_ExportGrid.IsEnabled = true;
        }
コード例 #36
0
        /// <summary>
        /// function to get XYZ vales from CS200
        /// </summary>
        /// <returns></returns>
        public static CIEXYZ StartMeasureXYZ()
        {
            StringBuilder returnString = new StringBuilder(250);
            //measure
            string cMeasure = "MES,1\r\n";
            int    length   = cMeasure.Length;

            int r = CaptureEngine.write64_usb(0, cMeasure, 1, length);

            r = CaptureEngine.read64_usb(0, returnString, 1, 250);

            string waittime = returnString.ToString(5, 2);


            int t = Convert.ToInt32(waittime);

            t = t * 1000;
            t = t - 500;

            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            //take the if out for any other than phone
            //

            System.Threading.Thread.Sleep(t);

            cMeasure = "MDR,3\r\n";
            length   = cMeasure.Length;

            r = CaptureEngine.write64_usb(0, cMeasure, 1, length);
            r = CaptureEngine.read64_usb(0, returnString, 1, 250);

            string error = returnString.ToString(0, 4);

            if (error == "ER21")
            {
                CIEXYZ xyz = new CIEXYZ(0, 0, 0);
                xyz.stdx = t;
                xyz.stdy = 0;
                xyz.stdz = 0;
                return(xyz);
            }

            while (error == "ER02")
            {
                t = t + 300;
                System.Threading.Thread.Sleep(300);
                cMeasure = "MDR,3\r\n";
                length   = cMeasure.Length;

                r     = CaptureEngine.write64_usb(0, cMeasure, 1, length);
                r     = CaptureEngine.read64_usb(0, returnString, 1, 250);
                error = returnString.ToString(0, 4);
            }

            if (error == "ER21")
            {
                CIEXYZ xyz = new CIEXYZ(0, 0, 0);
                xyz.stdx = t;
                xyz.stdy = 0;
                xyz.stdz = 0;
                return(xyz);
            }
            else
            {
                string op = returnString.ToString();
                string x  = returnString.ToString(27, 10);
                string y  = returnString.ToString(39, 10);
                string z  = returnString.ToString(51, 10);

                double X = Convert.ToDouble(x) / 100;
                double Y = Convert.ToDouble(y) / 100;
                double Z = Convert.ToDouble(z) / 100;

                CIEXYZ xyz = new CIEXYZ(X, Y, Z);
                xyz.stdx = t;
                xyz.stdy = 0;
                xyz.stdz = 0;

                return(xyz);
            }
        }