Пример #1
0
        /// <summary>
        /// Function to go from LUV to RGB
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public static RGBValue ToRBG(Color PassedLUV)
        {
            double tempr, tempg, tempb;
            CIEXYZ xyz = LUVToXYZ(PassedLUV);


            RGBValue rgb = new RGBValue();

            double[] Clinear = 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

            //gamma companding
            for (int i = 0; i < 3; i++)
            {
                Clinear[i] = Math.Pow(Clinear[i], (1.0 / 2.2));
            }

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



            rgb.R = (byte)tempr;
            rgb.G = (byte)tempg;
            rgb.B = (byte)tempb;
            return(rgb);
        }
Пример #2
0
        /// <summary>
        /// function to find the Delta e the color difference
        /// </summary>
        /// <param name="c1"></param>
        /// <param name="c2"></param>
        /// <returns></returns>
        public double DistanceCal1(RGBValue c1, RGBValue c2)
        {
            // converting color RGB rep to suit previously written TOLUV function
            System.Drawing.Color C1 = new System.Drawing.Color();
            C1 = System.Drawing.Color.FromArgb((int)c1.R, (int)c1.G, (int)c1.B);
            System.Drawing.Color C2 = new System.Drawing.Color();
            C2 = System.Drawing.Color.FromArgb((int)c2.R, (int)c2.G, (int)c2.B);

            Color Color1 = new Color();
            Color Color2 = new Color();

            //c1 & c2's LUV values
            Color1 = ToLUV(C1);
            Color2 = ToLUV(C2);

            double ΔEuv = Math.Pow((Math.Pow((Color1.L - Color2.L), 2) + Math.Pow((Color1.U - Color2.U), 2) + Math.Pow((Color1.V - Color2.V), 2)), (1.0 / 2.0));

            return(ΔEuv);
            //bool result;
            //if (?Euv>10)
            //    result=false;
            //else
            //    result=true;

            //return result;
        }
        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 CIEXYZ RGBToXYZ(RGBValue cRGB)
        {
            // by the formula given the the web page http://www.brucelindbloom.com/index.html [XYZ]=[M][RGB]
            //In order to properly use this matrix, the RGB values must be linear and in the nominal range [0.0, 1.0].
            // RGB values may first need conversion (for example, dividing by 255 and then raising them to a power)
            // Where M for D65:	 0.4124564  0.3575761  0.1804375
            //0.2126729  0.7151522  0.0721750
            //0.0193339  0.1191920  0.9503041

            //// to make rgb values linear red, green, blue values
            double rLinear = (double)cRGB.R / 255.0;
            double gLinear = (double)cRGB.G / 255.0;
            double bLinear = (double)cRGB.B / 255.0;

            // convert to a sRGB form

            //double r =  Math.Pow((rLinear ), 2.2) ;
            //double g =  Math.Pow((gLinear ), 2.2) ;
            //double b = Math.Pow((bLinear ), 2.2) ;
            double r, g, b;

            if (rLinear > 0.04045)
            {
                r = Math.Pow(((rLinear + 0.055) / 1.055), 2.2);
            }
            else
            {
                r = rLinear / 12.92;
            }

            if (gLinear > 0.04045)
            {
                g = Math.Pow(((gLinear + 0.055) / 1.055), 2.2);
            }
            else
            {
                g = gLinear / 12.92;
            }

            if (bLinear > 0.04045)
            {
                b = Math.Pow(((bLinear + 0.055) / 1.055), 2.2);
            }
            else
            {
                b = bLinear / 12.92;
            }


            return(new CIEXYZ((r * 0.4124564 + g * 0.3575761 + b * 0.1804375),
                              (r * 0.2126729 + g * 0.7151522 + b * 0.0721750),
                              (r * 0.0193339 + g * 0.1191920 + b * 0.9503041)));
        }
Пример #5
0
        /// <summary>
        /// funtion for LAb To RGB
        /// </summary>
        /// <param name="PassedLab"></param>
        /// <returns></returns>
        public static RGBValue ToRBGFromLAB(Color PassedLab)
        {
            int    tempr, tempg, tempb;
            CIEXYZ xyz = LABToXYZ(PassedLab);


            RGBValue rgb = new RGBValue();

            double[] Clinear = 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

            //gamma companding
            for (int i = 0; i < 3; i++)
            {
                Clinear[i] = Math.Pow(Clinear[i], (1.0 / 2.2));
            }

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

            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;
            }


            rgb.R = (byte)(tempr);
            rgb.G = (byte)(tempg);
            rgb.B = (byte)(tempb);
            return(rgb);
        }
Пример #6
0
        /// <summary>
        /// funtion to get RGB data which are taken out from the LAB binning
        /// </summary>
        /// <returns></returns>
        public static List <RGBbin> RGBbinedData()
        {
            // List<LABbin> bin = binning();
            List <LABbin> bin   = RGBBinneddData_David();//binning();
            int           count = bin.Count();

            List <RGBbin> BinRGB = new List <RGBbin>();
            // byte[][] BinRGB = new byte[count][];

            RGBValue temp = new RGBValue();
            Color    lab  = new Color();

            // int binCount=0;

            for (int i = 0; i < count; i++)
            {
                lab.L = bin[i].L;
                lab.A = bin[i].A;
                lab.B = bin[i].B;


                temp = ToRBGFromLAB(lab);

                if (temp.R < 0 || temp.R > 255 || temp.B < 0 || temp.B > 255 || temp.G < 0 || temp.G > 255)
                {
                    continue;
                }
                else
                {
                    //BinRGB[binCount].R = (byte)temp.R;
                    //BinRGB[binCount].G= (byte)temp.G;
                    //BinRGB[binCount].B= (byte)temp.B;
                    //binCount++;

                    BinRGB.Add(new RGBbin
                    {
                        R = (byte)temp.R,
                        G = (byte)temp.G,
                        B = (byte)temp.B
                    });
                }
            }

            return(BinRGB);
        }
Пример #7
0
        public static Color ToLAB(RGBValue cRGB)
        {
            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);
        }
Пример #8
0
        public RGBValue gammut(RGBValue cRGB)
        {
            // color 1
            RGBValue Color1 = new RGBValue();
            //color2
            RGBValue Color2 = new RGBValue();

            Color1.R = 0;
            Color1.G = 0;
            Color1.B = 0;

            List <RGBValue> PerceptuallyDiffRGBs = new List <RGBValue>();

            PerceptuallyDiffRGBs.Add(Color1);
            if (PerceptuallyDiffRGBs.Count >= 1)
            {
                Color2.R = (byte)(Color1.R + 1);
                Color2.G = Color1.G;
                Color2.B = Color1.B;
            }


            return(null);
        }
        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;
        }
Пример #10
0
        public RGBValue gammut(RGBValue cRGB)
        {
            // color 1
              RGBValue Color1 = new RGBValue();
              //color2
              RGBValue Color2 = new RGBValue();

              Color1.R = 0;
              Color1.G = 0;
              Color1.B = 0;

              List<RGBValue> PerceptuallyDiffRGBs = new List<RGBValue>();

              PerceptuallyDiffRGBs.Add(Color1);
              if (PerceptuallyDiffRGBs.Count >= 1)
              {

            Color2.R = (byte)(Color1.R + 1);
            Color2.G = Color1.G;
            Color2.B = Color1.B;
              }

              return null;
        }
Пример #11
0
        /// <summary>
        /// function to find the Delta e the color difference
        /// </summary>
        /// <param name="c1"></param>
        /// <param name="c2"></param>
        /// <returns></returns>
        public double DistanceCal1(RGBValue c1, RGBValue c2)
        {
            // converting color RGB rep to suit previously written TOLUV function
            System.Drawing.Color C1 = new System.Drawing.Color();
            C1 = System.Drawing.Color.FromArgb((int)c1.R, (int)c1.G, (int)c1.B);
            System.Drawing.Color C2 = new System.Drawing.Color();
            C2 = System.Drawing.Color.FromArgb((int)c2.R, (int)c2.G, (int)c2.B);

            Color Color1 = new Color();
            Color Color2 = new Color();

            //c1 & c2's LUV values
            Color1 = ToLUV(C1);
            Color2 = ToLUV(C2);

            double ΔEuv = Math.Pow((Math.Pow((Color1.L - Color2.L), 2) + Math.Pow((Color1.U - Color2.U), 2) + Math.Pow((Color1.V - Color2.V), 2)), (1.0 / 2.0));
            return ΔEuv;
            //bool result;
            //if (?Euv>10)
            //    result=false;
            //else
            //    result=true;

            //return result;
        }
Пример #12
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;
        }
Пример #13
0
        public static List <LABbin> RGBBinneddData_David()
        {
            List <LABbin> binedLabValues  = new List <LABbin>();
            List <LABbin> ReturnLabValues = new List <LABbin>();

            //List<double> lbin = new List<double>();
            //List<double> bina = new List<double>();
            //List<double> binb = new List<double>();
            OriginalRGB = new List <RGBbin>();

            for (int rgb = 0; rgb < (1 + 0x00FFFFFF); rgb = rgb + 1)
            {
                Color lab = new Color();

                RGBValue RGB = new RGBValue();

                int r = (rgb & 0x00FF0000) >> 16;
                RGB.R = Convert.ToByte(r);

                int g = (rgb & 0x0000FF00) >> 8;
                RGB.G = Convert.ToByte(g);

                int b = (rgb & 0x000000FF);
                RGB.B = (byte)(b);

                lab = ToLAB(RGB);

                double Lbin = (double)((int)(Math.Round(lab.LA / 5.0)) * 5);
                double Abin = (double)((int)(Math.Round(lab.A / 5.0)) * 5);
                double Bbin = (double)((int)(Math.Round(lab.B / 5.0)) * 5);

                if (Lbin < 0)
                {
                    Lbin = 0;
                }
                if (Lbin > 100)
                {
                    Lbin = 100;
                }
                if (Abin < -86.17385493791946)
                {
                    Abin = -86.17385493791946;
                }
                if (Abin > 98.2448002875424)
                {
                    Abin = 98.2448002875424;
                }
                if (Bbin < -107.8619171648283)
                {
                    Bbin = -107.8619171648283;
                }
                if (Bbin > 94.47705120353054)
                {
                    Bbin = 94.47705120353054;
                }

                //lbin=Lbin;
                //List<LABbin> temp = new List<LABbin>();

                //temp.Add(new LABbin
                //{

                //  L = Lbin,
                //  A = Abin,
                //  B = Bbin

                //});

                int checkForDublicate = 0;
                //
                for (int i = 0; i < binedLabValues.Count; i++)
                {
                    if (binedLabValues[i].L == Lbin && binedLabValues[i].A == Abin && binedLabValues[i].B == Bbin)
                    {
                        checkForDublicate = 1;
                        break;
                    }
                }

                if (checkForDublicate != 1)
                {
                    binedLabValues.Add(new LABbin
                    {
                        L = Lbin,
                        A = Abin,
                        B = Bbin
                    });

                    OriginalRGB.Add(new RGBbin
                    {
                        R = (byte)RGB.R,
                        G = (byte)RGB.G,
                        B = (byte)RGB.B
                    });
                }
            }

            ReturnLabValues = binedLabValues.Distinct().ToList();

            return(binedLabValues);
        }
Пример #14
0
        public static CIEXYZ RGBToXYZ(RGBValue cRGB)
        {
            // by the formula given the the web page http://www.brucelindbloom.com/index.html [XYZ]=[M][RGB]
              //In order to properly use this matrix, the RGB values must be linear and in the nominal range [0.0, 1.0].
              // RGB values may first need conversion (for example, dividing by 255 and then raising them to a power)
              // Where M for D65:	 0.4124564  0.3575761  0.1804375
              //0.2126729  0.7151522  0.0721750
              //0.0193339  0.1191920  0.9503041

              //// to make rgb values linear red, green, blue values
              double rLinear = (double)cRGB.R / 255.0;
              double gLinear = (double)cRGB.G / 255.0;
              double bLinear = (double)cRGB.B / 255.0;

              // convert to a sRGB form

              //double r =  Math.Pow((rLinear ), 2.2) ;
              //double g =  Math.Pow((gLinear ), 2.2) ;
              //double b = Math.Pow((bLinear ), 2.2) ;
              double r, g, b;

              if (rLinear > 0.04045)
            r = Math.Pow(((rLinear + 0.055) / 1.055), 2.2);
              else
            r = rLinear / 12.92;

              if (gLinear > 0.04045)
            g = Math.Pow(((gLinear + 0.055) / 1.055), 2.2);
              else
            g = gLinear / 12.92;

              if (bLinear > 0.04045)
            b = Math.Pow(((bLinear + 0.055) / 1.055), 2.2);
              else
            b = bLinear / 12.92;

              return new CIEXYZ((r * 0.4124564 + g * 0.3575761 + b * 0.1804375),
                        (r * 0.2126729 + g * 0.7151522 + b * 0.0721750),
                        (r * 0.0193339 + g * 0.1191920 + b * 0.9503041));
        }
Пример #15
0
        public static List<LABbin> RGBBinneddData_David()
        {
            List<LABbin> binedLabValues = new List<LABbin>();
              List<LABbin> ReturnLabValues = new List<LABbin>();

              //List<double> lbin = new List<double>();
              //List<double> bina = new List<double>();
              //List<double> binb = new List<double>();

              for (int rgb = 0; rgb < (1 + 0x00FFFFFF); rgb = rgb + 1)
              {
            Color lab = new Color();

            RGBValue RGB = new RGBValue();

            int r = (rgb & 0x00FF0000) >> 16;
            RGB.R = Convert.ToByte(r);

            int g = (rgb & 0x0000FF00) >> 8;
            RGB.G = Convert.ToByte(g);

            int b = (rgb & 0x000000FF);
            RGB.B = (byte)(b);

            lab = ToLAB(RGB);

            double Lbin = (double)((int)(Math.Round(lab.LA / 5.0)) * 5);
            double Abin = (double)((int)(Math.Round(lab.A / 5.0)) * 5);
            double Bbin = (double)((int)(Math.Round(lab.B / 5.0)) * 5);

            if (Lbin < 0)
              Lbin = 0;
            if (Lbin > 100)
              Lbin = 100;
            if (Abin < -86.17385493791946)
              Abin = -86.17385493791946;
            if (Abin > 98.2448002875424)
              Abin = 98.2448002875424;
            if (Bbin < -107.8619171648283)
              Bbin = -107.8619171648283;
            if (Bbin > 94.47705120353054)
              Bbin = 94.47705120353054;

            //lbin=Lbin;
            //List<LABbin> temp = new List<LABbin>();

            //temp.Add(new LABbin
            //{

            //  L = Lbin,
            //  A = Abin,
            //  B = Bbin

            //});

            int checkForDublicate = 0;
            for (int i = 0; i < binedLabValues.Count; i++)
            {
              if (binedLabValues[i].L == Lbin && binedLabValues[i].A == Abin && binedLabValues[i].B == Bbin)
              {
            checkForDublicate = 1;
            break;
              }

            }

            if (checkForDublicate != 1)
            {
              binedLabValues.Add(new LABbin
              {
            L = Lbin,
            A = Abin,
            B = Bbin

              });
            }

              }

              ReturnLabValues = binedLabValues.Distinct().ToList();

              return binedLabValues;
        }
Пример #16
0
        /// <summary>
        /// funtion to get RGB data which are taken out from the LAB binning
        /// </summary>
        /// <returns></returns>
        public static List<RGBbin> RGBbinedData()
        {
            // List<LABbin> bin = binning();
              List<LABbin> bin = RGBBinneddData_David();//binning();
              int count = bin.Count();

              List<RGBbin> BinRGB = new List<RGBbin>();
              // byte[][] BinRGB = new byte[count][];

              RGBValue temp = new RGBValue();
              Color lab = new Color();

              // int binCount=0;

              for (int i = 0; i < count; i++)
              {

            lab.L = bin[i].L;
            lab.A = bin[i].A;
            lab.B = bin[i].B;

            temp = ToRBGFromLAB(lab);

            if (temp.R < 0 || temp.R > 255 || temp.B < 0 || temp.B > 255 || temp.G < 0 || temp.G > 255)
            {
              continue;
            }
            else
            {
              //BinRGB[binCount].R = (byte)temp.R;
              //BinRGB[binCount].G= (byte)temp.G;
              //BinRGB[binCount].B= (byte)temp.B;
              //binCount++;

              BinRGB.Add(new RGBbin
              {
            R = (byte)temp.R,
            G = (byte)temp.G,
            B = (byte)temp.B

              });
            }

              }

              return BinRGB;
        }
Пример #17
0
        /// <summary>
        /// To find which quadrant
        /// </summary>
        /// <param name="colorToShow"></param>
        /// <returns></returns>
        public static ColorRegion ToFindColorRegion(PerceptionLib.Color colorToShow)
        {
            ColorRegion ColorValues = new ColorRegion();

              // to find if its within nuteral region
              //////////////////////////////////////////////////////////////////////////////////////////////////////////////
              double CylinderRadius = 23; //3 JND
              double NuetralL = Convert.ToInt32(colorToShow.LA);

              // nuetral color near the input color
              Color NuetralValue = new Color();
              NuetralValue.LA = NuetralL;
              NuetralValue.A = 0;
              NuetralValue.B = 0;

              double Distacne = ColorDistanceCalAB(colorToShow, NuetralValue);

              if (Distacne <= CylinderRadius)
            ColorValues.NetralValueFlag=0;
              else
            ColorValues.NetralValueFlag=1;

              // to find L region (High or Low)
              //////////////////////////////////////////////////////////////////////////////////////////////////////////////

              //LValueFlag=0 for L Less than 50 and 1 for other wise
              if (NuetralL < 50)
            ColorValues.LValueFlag = 0;
              else
            ColorValues.LValueFlag = 1;

              // to find which Quadrant color belongs to
              //////////////////////////////////////////////////////////////////////////////////////////////////////////////
              // to calculate the hue angle

              /// <summary>
              /// RegionValue=1 then RegionValue =Red-Yellow
              /// RegionValue=2 then RegionValue =Yellow-Green
              /// RegionValue=3 then RegionValue =Green-Cyan
              /// RegionValue=4 then RegionValue =Cyan-Blue
              /// RegionValue=5 then RegionValue =Blue-Magenta
              /// RegionValue=6 then RegionValue =Magenta-Red
              /// RegionValue=6 then RegionValue =ERROR
              /// </summary>
              ///

              RGBValue ColorVal = new RGBValue();
              ColorVal=ToRBGFromLAB(colorToShow);

              if (ColorVal.R >= ColorVal.G && ColorVal.G>= ColorVal.B)
            ColorValues.RegionValue = 1;
              else if (ColorVal.G > ColorVal.R && ColorVal.R >= ColorVal.B)
            ColorValues.RegionValue = 2;
              else if (ColorVal.G >= ColorVal.B && ColorVal.B > ColorVal.R)
            ColorValues.RegionValue = 3;
              else if (ColorVal.B > ColorVal.G && ColorVal.G > ColorVal.R)
            ColorValues.RegionValue = 4;
              else if (ColorVal.B > ColorVal.R && ColorVal.R >= ColorVal.G)
            ColorValues.RegionValue = 5;
              else if (ColorVal.R >= ColorVal.B && ColorVal.B > ColorVal.G)
            ColorValues.RegionValue = 6;
              //error check
              else
            ColorValues.RegionValue = 0;

              //calculation using lab hue formula -- found not working for the Preucil circle
              //double Hue = HueAngle(colorToShow);
              //if (0 <= Hue && Hue < 60)
              //  ColorValues.QuatarentValue = 1;
              //else if(60 <= Hue && Hue < 120)
              //  ColorValues.QuatarentValue = 2;
              //else if (120 <= Hue && Hue < 180)
              //  ColorValues.QuatarentValue = 3;
              //else if (180 <= Hue && Hue < 240)
              //  ColorValues.QuatarentValue = 4;
              //else if (240 <= Hue && Hue < 300)
              //  ColorValues.QuatarentValue = 5;
              //else if (300 <= Hue && Hue < 0)
              //  ColorValues.QuatarentValue = 6;
              //  //error check
              //else
              //  ColorValues.QuatarentValue = 0;

              return ColorValues;
        }
Пример #18
0
        private void DisplayMeasuredValuesFromCs200()
        {
            DateTime Start = DateTime.Now;
              //ad this sleep to normal code other than phone
            //System.Threading.Thread.Sleep(100);
              DateTime Start1 = DateTime.Now;

              //dont ad  normal code other than phone
              //ColorMeasuredXYZ = PerceptionLib.Cs200Connection.StartMeasureXYZForPhone();

              ColorMeasuredXYZ = PerceptionLib.Cs200Connection.StartMeasureXYZ();
              //ColorMeasuredXYZ = PerceptionLib.Cs200Connection.StartAVGMeasureXYZ9();
              //ColorMeasuredXYZ = PerceptionLib.Cs200Connection.StartAVGMeasureXYZ2();
              //ColorMeasuredXYZ = PerceptionLib.Cs200Connection.StartAVGMeasureXYZ3();

              time4 = DateTime.Now.Subtract(Start1).ToString();
              ColorMeasured = PerceptionLib.Color.ToLUV(ColorMeasuredXYZ);

              PerceptionLib.RGBValue RGB = new PerceptionLib.RGBValue();

              RGB = PerceptionLib.Color.ToRBG(ColorMeasured);
              MR = RGB.R;
              MG = RGB.G;
              MB = RGB.B;

              //to display the color in the rectangle
              //Dispatcher.Invoke(new Action(() => Rectangle_Captured.Fill = new SolidColorBrush((System.Windows.Media.Color.FromRgb(RGB.R, RGB.G, RGB.B)))));

              time3 = DateTime.Now.Subtract(Start).ToString();
        }
Пример #19
0
        private void Btn_UseGridData_Click(object sender, RoutedEventArgs e)
        {
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\STColorPerception\bin\bin8.csv");
              dtgrid_corrDisplay.IsEnabled = false;

              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();
              ThreadPool.QueueUserWorkItem(ignored =>
              {

            //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(DispatcherPriority.Send, new Action(() => {
            ColorCapturedUpdate();
              }));
               // System.Threading.Thread.Sleep(1000);
              Dispatcher.Invoke(DispatcherPriority.Normal, new Action(() => {
            //StartCapture();
            colorMeasured = StartCapture1();
            DisplayMeasuredValues();
              }));
              //           System.Windows.Forms.Application.DoEvents();

              DifferenceCalculation();

              //bradcolor=

              // 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[i][13] = ColorDifference.L.ToString();
              //dt.Rows[i][14] = ColorDifference.U.ToString();
              //dt.Rows[i][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(BradXYZ);
              //VonRGB = PerceptionLib.Color.ToRBG(VonXYZ);
              //scalingRGB = PerceptionLib.Color.ToRBG(ScalingXYZ);

              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();

              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()) }
              });

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

              // System.Threading.Thread.Sleep(10000);
            }

            // grid is populated with new datatable which has luv values
            Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = dt.DefaultView));
            Dispatcher.Invoke(new Action(() => 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()) }
              });
            }
              });
              btn_ExportGrid.IsEnabled = true;

              dtgrid_corrDisplay.IsEnabled = true;
              dataTable = dt;
        }
Пример #20
0
        private void Btn_StdColorData_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\StdColortriangle.txt");
              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 = 20;
              //FgNo = 27;
              FgNo = 61;

              // 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:
              BgColor = new PerceptionLib.Color();
              bgcolour.L = 65;
              bgcolour.UP = 0.275;
              bgcolour.VP = 0.485;
              bgcolour.U = (13 * bgcolour.L) * (bgcolour.UP - bgcolour.UR);
              bgcolour.V = (13 * bgcolour.L) * (bgcolour.VP - bgcolour.VR);

              rgb = PerceptionLib.Color.ToRBG(bgcolour);
              BgR = rgb.R;
              BgG = rgb.G;
              BgB = rgb.B;
              break;
            //Foliage
            case 2:
              BgColor = new PerceptionLib.Color();
              bgcolour.L = 65;
              bgcolour.UP = 0.123;
              bgcolour.VP = 0.531;
              bgcolour.U = (13 * bgcolour.L) * (bgcolour.UP - bgcolour.UR);
              bgcolour.V = (13 * bgcolour.L) * (bgcolour.VP - bgcolour.VR);

              rgb = PerceptionLib.Color.ToRBG(bgcolour);
              BgR = rgb.R;
              BgG = rgb.G;
              BgB = rgb.B;
              break;
            //Sidewalk
            case 3:
              BgColor = new PerceptionLib.Color();
              bgcolour.L = 65;
              bgcolour.UP = 0.211;
              bgcolour.VP = 0.489;
              bgcolour.U = (13 * bgcolour.L) * (bgcolour.UP - bgcolour.UR);
              bgcolour.V = (13 * bgcolour.L) * (bgcolour.VP - bgcolour.VR);

              rgb = PerceptionLib.Color.ToRBG(bgcolour);
              BgR = rgb.R;
              BgG = rgb.G;
              BgB = rgb.B;

              break;

            //Pavement
            case 4:
              BgColor = new PerceptionLib.Color();
              bgcolour.L = 65;
              bgcolour.UP = 0.203;
              bgcolour.VP = 0.470;
              bgcolour.U = (13 * bgcolour.L) * (bgcolour.UP - bgcolour.UR);
              bgcolour.V = (13 * bgcolour.L) * (bgcolour.VP - bgcolour.VR);

              rgb = PerceptionLib.Color.ToRBG(bgcolour);
              BgR = rgb.R;
              BgG = rgb.G;
              BgB = rgb.B;
              break;

            //vaiants of blue
            case 5:
              BgR = 0;
              BgG = 0;
              BgB = 255;
              break;

            case 6:
              BgR = 0;
              BgG = 0;
              BgB = 225;
              break;

            case 7:
              BgR = 100;
              BgG = 0;
              BgB = 255;
              break;

            case 8:
              BgR = 0;
              BgG = 100;
              BgB = 255;
              break;

            //variants of green

            case 9:
              BgR = 0;
              BgG = 255;
              BgB = 0;
              break;

            case 10:
              BgR = 0;
              BgG = 225;
              BgB = 0;
              break;

            case 11:
              BgR = 100;
              BgG = 255;
              BgB = 0;
              break;

            case 12:
              BgR = 0;
              BgG = 255;
              BgB = 100;
              break;

            //yellow

            case 13:
              BgR = 255;
              BgG = 255;
              BgB = 0;
              break;

            case 14:
              BgR = 200;
              BgG = 200;
              BgB = 0;
              break;

            case 15:
              BgR = 200;
              BgG = 255;
              BgB = 0;
              break;

            //red
            case 16:
              BgR = 255;
              BgG = 0;
              BgB = 0;
              break;

            case 17:
              BgR = 200;
              BgG = 0;
              BgB = 0;
              break;

            case 18:
              BgR = 255;
              BgG = 100;
              BgB = 0;
              break;

            case 19:
              BgR = 255;
              BgG = 0;
              BgB = 100;
              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()));

            DifferenceCalculation();

            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;

              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();

              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][11].ToString()), VP = Convert.ToDouble(dt.Rows[j][12].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][19].ToString());
            BgG = Convert.ToByte(dt.Rows[i * FgNo][20].ToString());
            BgB = Convert.ToByte(dt.Rows[i * FgNo][21].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;

            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();

            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
            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][22] = dt.Rows[(totalRow) + i - 1][22].ToString();
            dt.Rows[rowNo][23] = dt.Rows[(totalRow) + i - 1][23].ToString();
            dt.Rows[rowNo][24] = dt.Rows[(totalRow) + i - 1][24].ToString();
            dt.Rows[rowNo][25] = dt.Rows[(totalRow) + i - 1][25].ToString();
            dt.Rows[rowNo][26] = dt.Rows[(totalRow) + i - 1][26].ToString();
            dt.Rows[rowNo][27] = dt.Rows[(totalRow) + i - 1][27].ToString();
            dt.Rows[rowNo][28] = dt.Rows[(totalRow) + i - 1][28].ToString();
            dt.Rows[rowNo][29] = dt.Rows[(totalRow) + i - 1][29].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();
        }
Пример #21
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;
        }
Пример #22
0
        private void button11_Click(object sender, RoutedEventArgs e)
        {
            PopulateGrid(@"C:\see-through-project\gt\STColorCorrection\Src\DataGrid\DataGrid\data\Ds_correction.txt");
              DataTable DS = new DataTable();
              Dispatcher.Invoke(DispatcherPriority.Render, new Action(() =>
              {
            dtgrid_corrDisplay.Items.Refresh();
            DS = ((DataView)dtgrid_corrDisplay.ItemsSource).ToTable();
              }));

              List<LABbin> bin =PerceptionLib.Color.RGBBinneddData_David();

              int count = bin.Count();

              //int temp = -1;
              DataRow newRow;
              for (int i = 0; i < count; i++)
              {

            newRow = DS.NewRow();
            newRow[0] = bin[i].L.ToString();
            newRow[1] = bin[i].A.ToString();
            newRow[2] = bin[i].B.ToString();
            newRow[3] = PerceptionLib.Color.OriginalRGB[i].R.ToString();
            newRow[4] = PerceptionLib.Color.OriginalRGB[i].G.ToString();
            newRow[5] = PerceptionLib.Color.OriginalRGB[i].B.ToString();

            DS.Rows.Add(newRow);
              }
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = DS.DefaultView));
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));

              PerceptionLib.Color lab = new PerceptionLib.Color();
              RGBValue temp = new RGBValue();

              for (int i = 0; i < DS.Rows.Count; i++)
              {
            lab.LA = bin[i].L;
            lab.A = bin[i].A;
            lab.B = bin[i].B;

            temp = PerceptionLib.Color.ToRBGFromLAB(lab);

            if (temp.R < 0 || temp.R > 255 || temp.B < 0 || temp.B > 255 || temp.G < 0 || temp.G > 255)
            {
              continue;
            }
            else
            {
              //BinRGB[binCount].R = (byte)temp.R;
              //BinRGB[binCount].G= (byte)temp.G;
              //BinRGB[binCount].B= (byte)temp.B;
              //binCount++;

              DS.Rows[i][6] = temp.R.ToString();
              DS.Rows[i][7] = temp.G.ToString();
              DS.Rows[i][8] = temp.B.ToString();

            }

              }
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.ItemsSource = DS.DefaultView));
              Dispatcher.Invoke(new Action(() => dtgrid_corrDisplay.Items.Refresh()));
        }
Пример #23
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;
        }
Пример #24
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;
        }
Пример #25
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;
        }
Пример #26
0
        /// <summary>
        /// To find which quadrant
        /// </summary>
        /// <param name="colorToShow"></param>
        /// <returns></returns>
        public static ColorRegion ToFindColorRegion(Color colorToShow)
        {
            ColorRegion ColorValues = new ColorRegion();

            // to find if its within nuteral region
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            double CylinderRadius = 23; //3 JND
            double NuetralL       = Convert.ToInt32(colorToShow.LA);

            // nuetral color near the input color
            Color NuetralValue = new Color();

            NuetralValue.LA = NuetralL;
            NuetralValue.A  = 0;
            NuetralValue.B  = 0;



            double Distacne = ColorDistanceCalAB(colorToShow, NuetralValue);

            //NetralValueFlag=0 for for inside the nuetral region  and 1 for other wise

            if (Distacne <= CylinderRadius)
            {
                ColorValues.NetralValueFlag = 0;
            }
            else if (Distacne <= 40)
            {
                ColorValues.NetralValueFlag = 1;
            }
            else if (Distacne <= 60)
            {
                ColorValues.NetralValueFlag = 2;
            }
            else if (Distacne <= 80)
            {
                ColorValues.NetralValueFlag = 3;
            }
            else if (Distacne <= 100)
            {
                ColorValues.NetralValueFlag = 4;
            }
            else
            {
                ColorValues.NetralValueFlag = 5;
            }
            //else
            //  ColorValues.NetralValueFlag = 1;

            // to find L region (High or Low)
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////

            //LValueFlag=0 for L Less than 50 and 1 for other wise
            if (NuetralL < 50)
            {
                ColorValues.LValueFlag = 0;
            }
            else
            {
                ColorValues.LValueFlag = 1;
            }


            // to find which Quadrant color belongs to
            //////////////////////////////////////////////////////////////////////////////////////////////////////////////
            // to calculate the hue angle


            /// <summary>
            /// RegionValue=1 then RegionValue =Red-Yellow
            /// RegionValue=2 then RegionValue =Yellow-Green
            /// RegionValue=3 then RegionValue =Green-Cyan
            /// RegionValue=4 then RegionValue =Cyan-Blue
            /// RegionValue=5 then RegionValue =Blue-Magenta
            /// RegionValue=6 then RegionValue =Magenta-Red
            /// RegionValue=6 then RegionValue =ERROR
            /// </summary>
            ///

            RGBValue ColorVal = new RGBValue();

            ColorVal = ToRBGFromLAB(colorToShow);

            if (ColorVal.R >= ColorVal.G && ColorVal.G >= ColorVal.B)
            {
                ColorValues.RegionValue = 1;
            }
            else if (ColorVal.G > ColorVal.R && ColorVal.R >= ColorVal.B)
            {
                ColorValues.RegionValue = 2;
            }
            else if (ColorVal.G >= ColorVal.B && ColorVal.B > ColorVal.R)
            {
                ColorValues.RegionValue = 3;
            }
            else if (ColorVal.B > ColorVal.G && ColorVal.G > ColorVal.R)
            {
                ColorValues.RegionValue = 4;
            }
            else if (ColorVal.B > ColorVal.R && ColorVal.R >= ColorVal.G)
            {
                ColorValues.RegionValue = 5;
            }
            else if (ColorVal.R >= ColorVal.B && ColorVal.B > ColorVal.G)
            {
                ColorValues.RegionValue = 6;
            }
            //error check
            else
            {
                ColorValues.RegionValue = 0;
            }


            //calculation using lab hue formula -- found not working for the Preucil circle
            //double Hue = HueAngle(colorToShow);
            //if (0 <= Hue && Hue < 60)
            //  ColorValues.QuatarentValue = 1;
            //else if(60 <= Hue && Hue < 120)
            //  ColorValues.QuatarentValue = 2;
            //else if (120 <= Hue && Hue < 180)
            //  ColorValues.QuatarentValue = 3;
            //else if (180 <= Hue && Hue < 240)
            //  ColorValues.QuatarentValue = 4;
            //else if (240 <= Hue && Hue < 300)
            //  ColorValues.QuatarentValue = 5;
            //else if (300 <= Hue && Hue < 0)
            //  ColorValues.QuatarentValue = 6;
            //  //error check
            //else
            //  ColorValues.QuatarentValue = 0;
            return(ColorValues);
        }
Пример #27
0
        /// <summary>
        /// funtion for LAb To RGB
        /// </summary>
        /// <param name="PassedLab"></param>
        /// <returns></returns>
        public static RGBValue ToRBGFromLAB(Color PassedLab)
        {
            int tempr, tempg, tempb;
              CIEXYZ xyz = LABToXYZ(PassedLab);

              RGBValue rgb = new RGBValue();

              double[] Clinear = 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

              //gamma companding
              for (int i = 0; i < 3; i++)
              {
            Clinear[i] = Math.Pow(Clinear[i], (1.0 / 2.2));
              }

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

              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;
              }

              rgb.R = (byte)(tempr);
              rgb.G = (byte)(tempg);
              rgb.B = (byte)(tempb);
              return rgb;
        }
Пример #28
0
        public static Color ToLAB(RGBValue cRGB)
        {
            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;
        }
Пример #29
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;
        }
Пример #30
0
        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);
        }
Пример #31
0
        /// <summary>
        /// Function to go from LUV to RGB
        /// </summary>
        /// <param name="a"></param>
        /// <returns></returns>
        public static RGBValue ToRBG(Color PassedLUV)
        {
            double tempr, tempg, tempb;
              CIEXYZ xyz = LUVToXYZ(PassedLUV);

              RGBValue rgb = new RGBValue();

              double[] Clinear = 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

              //gamma companding
              for (int i = 0; i < 3; i++)
              {

            Clinear[i] = Math.Pow(Clinear[i], (1.0 / 2.2));
              }

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

              rgb.R = (byte)tempr;
              rgb.G = (byte)tempg;
              rgb.B = (byte)tempb;
              return rgb;
        }
Пример #32
0
        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;
        }
Пример #33
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();
        }