Example #1
0
 /// <summary>
 /// Converts CIEXYZ to CIEYxy structure.
 /// </summary>
 public static CIEYxy XYZtoYxy(CIEXYZ xyz)
 {
     return XYZtoYxy(xyz.X, xyz.Y, xyz.Z);
 }
Example #2
0
 /// <summary>
 /// Converts CIEXYZ to RGB structure.
 /// </summary>
 public static RGB XYZtoRGB(CIEXYZ xyz)
 {
     return XYZtoRGB(xyz.X, xyz.Y, xyz.Z);
 }
Example #3
0
 /// <summary>
 /// Converts CIEXYZ to CIELab structure.
 /// </summary>
 public static CIELab XYZtoLab(CIEXYZ xyz)
 {
     return XYZtoLab(xyz.X, xyz.Y, xyz.Z);
 }
 /// <summary>
 /// Converts CIEXYZ to RGB structure.
 /// </summary>
 public static RGB XYZtoRGB(CIEXYZ xyz)
 {
     return(XYZtoRGB(xyz.X, xyz.Y, xyz.Z));
 }
Example #5
0
        private void btn_1024x768_Click(object sender, RoutedEventArgs e)
        {
            Matrix3D navigationMatrix = new Matrix3D();

            navigationMatrix.Translate(new Vector3D(0, 100, 110));
            navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5));

            //2- Load the profile in a three dimensional array
            Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB];
            for (int l = 0; l < RANGEL; l++)
            {
                for (int a = 0; a < RANGEA; a++)
                {
                    for (int b = 0; b < RANGEB; b++)
                    {
                        p3700[l, a, b] = new Bin(l, a, b);
                    }
                }
            }

            try
            {
                // add the csv bin file
                using (GenericParserAdapter parser = new GenericParserAdapter(@"C:\Users\jhincapie\Desktop\Projects\STColorCorrection\Data\PROFILE\p3700.csv"))
                {
                    System.Data.DataSet dsResult = parser.GetDataSet();
                    profile = dsResult.Tables[0];
                }
            }
            catch
            { }

            for (int i = 1; i < profile.Rows.Count; i++)
            {
                //lab vale as got form profile index
                Point3D labBin = new Point3D();
                labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString());
                labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString());
                labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString());

                //trasfered points
                Point3D labCoordinate = navigationMatrix.Transform(labBin);

                //gets the bin to fill up
                Bin actualBin = GetProfileBin(p3700, labCoordinate);

                //bin RGB Value
                actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString());
                actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString());
                actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString());

                //Measure Lab Values
                actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString());
                actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString());
                actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString());

                //measured XYZ Values
                actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString());
                actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString());
                actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString());

                //is empty check
                actualBin.isEmpty = false;
            }

            Stopwatch stop2 = new Stopwatch();

            stop2.Start();

            // to create a random number
            Random randomGenerater = new Random();

            for (int i = 0; i < 1024; i++)
            {
                for (int j = 0; j < 768; j++)
                {
                    Byte[] rgb = new Byte[3];
                    randomGenerater.NextBytes(rgb);
                    System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]);

                    PerceptionLib.CIEXYZ backgroundCIEXYZ = new CIEXYZ(0, 0, 0);
                    backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504;
                    backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000;
                    backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888;
                    Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z);

                    Bin foregroundBin      = FindForegroundBin(p3700, navigationMatrix, foreground);
                    PerceptionLib.Color fg = new PerceptionLib.Color();

                    //fg measured LAB value
                    fg.LA = foregroundBin.measuredLAB.X;
                    fg.A  = foregroundBin.measuredLAB.Y;
                    fg.B  = foregroundBin.measuredLAB.Z;

                    Bin corretedColorQCHS = QuickCorrection(p3700, navigationMatrix, foreground, background, HalfTheStep);
                }
            }

            stop2.Stop();
            Console.WriteLine(stop2.ElapsedMilliseconds);
        }
Example #6
0
        private void btn_Start_Click(object sender, RoutedEventArgs e)
        {
            Matrix3D navigationMatrix = new Matrix3D();

            navigationMatrix.Translate(new Vector3D(0, 100, 110));
            navigationMatrix.Scale(new Vector3D((double)1 / 5, (double)1 / 5, (double)1 / 5));

            //2- Load the profile in a three dimensional array
            Bin[, ,] p3700 = new Bin[RANGEL, RANGEA, RANGEB];
            for (int l = 0; l < RANGEL; l++)
            {
                for (int a = 0; a < RANGEA; a++)
                {
                    for (int b = 0; b < RANGEB; b++)
                    {
                        p3700[l, a, b] = new Bin(l, a, b);
                    }
                }
            }

            try
            {
                // add the csv bin file
                using (GenericParserAdapter parser = new GenericParserAdapter(Environment.CurrentDirectory + @"\..\..\..\..\..\Data\PROFILE\IdealProfile.csv"))
                {
                    System.Data.DataSet dsResult = parser.GetDataSet();
                    profile = dsResult.Tables[0];
                }
            }
            catch
            { }

            for (int i = 1; i < profile.Rows.Count; i++)
            {
                //lab vale as got form profile index
                Point3D labBin = new Point3D();
                labBin.X = Convert.ToDouble(profile.Rows[i][0].ToString());
                labBin.Y = Convert.ToDouble(profile.Rows[i][1].ToString());
                labBin.Z = Convert.ToDouble(profile.Rows[i][2].ToString());

                //trasfered points
                Point3D labCoordinate = navigationMatrix.Transform(labBin);

                //gets the bin to fill up
                Bin actualBin = GetProfileBin(p3700, labCoordinate);

                //bin RGB Value
                actualBin.binRGB.X = Convert.ToByte(profile.Rows[i][9].ToString());
                actualBin.binRGB.Y = Convert.ToByte(profile.Rows[i][10].ToString());
                actualBin.binRGB.Z = Convert.ToByte(profile.Rows[i][11].ToString());

                //Measure Lab Values
                actualBin.measuredLAB.X = Convert.ToDouble(profile.Rows[i][3].ToString());
                actualBin.measuredLAB.Y = Convert.ToDouble(profile.Rows[i][4].ToString());
                actualBin.measuredLAB.Z = Convert.ToDouble(profile.Rows[i][5].ToString());

                //measured XYZ Values
                actualBin.measuredXYZ.X = Convert.ToDouble(profile.Rows[i][6].ToString());
                actualBin.measuredXYZ.Y = Convert.ToDouble(profile.Rows[i][7].ToString());
                actualBin.measuredXYZ.Z = Convert.ToDouble(profile.Rows[i][8].ToString());

                //is empty check
                actualBin.isEmpty = false;
            }

            //3- Get the parameters: foreground and background
            //System.Drawing.Color foreground = System.Drawing.Color.FromArgb(150, 150, 150);
            //PerceptionLib.CIEXYZ background = new CIEXYZ(0.2146, 0.43125, 0.07595); //RGB: 0	199	0 - greenish

            /////////////////
            //code for comarison
            //populate template in datagrid
            PopulateGrid(Environment.CurrentDirectory + @"\..\..\..\..\..\Data\PROFILE\Comparison_Template.txt");
            DataTable template = new DataTable();

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

            // to create a random number
            Random randomGenerater = new Random();

            for (int i = 0; i < 1000; i++)
            {
                Byte[] rgb = new Byte[3];
                randomGenerater.NextBytes(rgb);
                System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]);

                PerceptionLib.CIEXYZ backgroundCIEXYZ = new CIEXYZ(0, 0, 0);
                backgroundCIEXYZ.X = randomGenerater.NextDouble() * 0.9504;
                backgroundCIEXYZ.Y = randomGenerater.NextDouble() * 1.0000;
                backgroundCIEXYZ.Z = randomGenerater.NextDouble() * 1.0888;
                Point3D background = new Point3D(backgroundCIEXYZ.X, backgroundCIEXYZ.Y, backgroundCIEXYZ.Z);

                try
                {
                    Bin foregroundBin = FindForegroundBin(p3700, navigationMatrix, foreground);
                    PerceptionLib.Color foregroundLAB = new PerceptionLib.Color();

                    //fg measured LAB value
                    foregroundLAB.LA = foregroundBin.measuredLAB.X;
                    foregroundLAB.A  = foregroundBin.measuredLAB.Y;
                    foregroundLAB.B  = foregroundBin.measuredLAB.Z;

                    Stopwatch stop1 = new Stopwatch();
                    stop1.Start();
                    Bin corretedColorBF = null;
                    corretedColorBF = BruteForceCorrection(p3700, navigationMatrix, foreground, background);
                    stop1.Stop();

                    Stopwatch stop2 = new Stopwatch();
                    stop2.Start();
                    Bin corretedColorQCHS = QuickCorrection(p3700, navigationMatrix, foreground, background, HalfTheStep);
                    stop2.Stop();

                    Stopwatch stop3 = new Stopwatch();
                    stop3.Start();
                    Bin corretedColorQCD = QuickCorrection(p3700, navigationMatrix, foreground, background, DecreaseTheStep);
                    stop3.Stop();

                    Stopwatch stop4 = new Stopwatch();
                    stop4.Start();
                    Bin corretedColorSC = SnakeCorrection(p3700, navigationMatrix, foreground, background);
                    stop4.Stop();

                    DataRow newRow = template.NewRow();
                    newRow["FgR"] = foreground.R.ToString();
                    newRow["FgG"] = foreground.G.ToString();
                    newRow["FgB"] = foreground.B.ToString();

                    newRow["BgX"] = background.X.ToString();
                    newRow["BgY"] = background.Y.ToString();
                    newRow["BgZ"] = background.Z.ToString();

                    newRow["FgL"]  = foregroundLAB.LA.ToString();
                    newRow["FgA"]  = foregroundLAB.A.ToString();
                    newRow["Fg_B"] = foregroundLAB.B.ToString();

                    newRow["BFL"]    = corretedColorBF.binLAB.X.ToString();
                    newRow["BFA"]    = corretedColorBF.binLAB.Y.ToString();
                    newRow["BFB"]    = corretedColorBF.binLAB.Z.ToString();
                    newRow["BFDis"]  = corretedColorBF.distanceLAB.ToString();
                    newRow["BFTime"] = stop1.ElapsedTicks.ToString();

                    newRow["QCHSL"]      = corretedColorQCHS.binLAB.X.ToString();
                    newRow["QCHSA"]      = corretedColorQCHS.binLAB.Y.ToString();
                    newRow["QCHSB"]      = corretedColorQCHS.binLAB.Z.ToString();
                    newRow["QCHSCycles"] = corretedColorQCHS.cycles;
                    newRow["QCHSDis"]    = corretedColorQCHS.distanceLAB.ToString();
                    newRow["QCHSOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorQCHS.distanceLAB);
                    newRow["QCHSTime"]   = stop2.ElapsedTicks.ToString();
                    newRow["QCHSRatio"]  = (stop1.ElapsedTicks / stop2.ElapsedTicks).ToString();

                    newRow["QCDL"]      = corretedColorQCD.binLAB.X.ToString();
                    newRow["QCDA"]      = corretedColorQCD.binLAB.Y.ToString();
                    newRow["QCDB"]      = corretedColorQCD.binLAB.Z.ToString();
                    newRow["QCDCycles"] = corretedColorQCD.cycles;
                    newRow["QCDDis"]    = corretedColorQCD.distanceLAB.ToString();
                    newRow["QCDOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorQCD.distanceLAB);
                    newRow["QCDTime"]   = stop3.ElapsedTicks.ToString();
                    newRow["QCDRatio"]  = (stop1.ElapsedTicks / stop3.ElapsedTicks).ToString();

                    newRow["SCL"]      = corretedColorSC.binLAB.X.ToString();
                    newRow["SCA"]      = corretedColorSC.binLAB.Y.ToString();
                    newRow["SCB"]      = corretedColorSC.binLAB.Z.ToString();
                    newRow["SCCycles"] = corretedColorSC.cycles;
                    newRow["SCDis"]    = corretedColorSC.distanceLAB.ToString();
                    newRow["SCOffSet"] = Math.Abs(corretedColorBF.distanceLAB - corretedColorSC.distanceLAB);
                    newRow["SCTime"]   = stop4.ElapsedTicks.ToString();
                    newRow["SCRatio"]  = (stop1.ElapsedTicks / stop4.ElapsedTicks).ToString();

                    template.Rows.Add(newRow);
                }
                catch
                { Console.WriteLine(""); }
            }

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