public static int MatchWithBinned(PerceptionLib.Color ColorToCompensate, DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; int i; double closestColor = double.MaxValue; // double closestColorValue = double.MaxValue; //double angleDifference = double.MaxValue; PerceptionLib.Color colorToCompare = new PerceptionLib.Color(); PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); for (int index = 0; index < bin.Rows.Count; index++) { i = index; colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); if (distance >= closestColor) { continue; } //ClosestL = colorToCompare.LA; //ClosestA = colorToCompare.A; //ClosestB = colorToCompare.B; //int BinNUmber1 = index; //colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); //colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); //colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); //colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); //colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); //double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); //if (ColorDistance >= closestColorValue) // continue; //closestColorValue = ColorDistance; closestColor = distance; closestColorInsideTheBin = distance; //closestColorOnAddition = ColorDistance; //HueAngeDifference = angleDifference; BinNUmber = index; } return(BinNUmber); }
public static int MatchWithBinnedColorsBasedOn3D(PerceptionLib.Color ColorToCompensate, DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; int i; double closestColor = double.MaxValue; double closestColorValue = double.MaxValue; PerceptionLib.Color colorToCompare = new PerceptionLib.Color(); double l, a, b; PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); Point3D cX = new Point3D(); Point3D cXPrime = new Point3D(ColorToCompensate.LA, ColorToCompensate.A, ColorToCompensate.B); for (int index = 0; index < bin.Rows.Count; index++) { i = index; l = Convert.ToDouble(bin.Rows[index][9].ToString()); a = Convert.ToDouble(bin.Rows[index][10].ToString()); b = Convert.ToDouble(bin.Rows[index][11].ToString()); Point3D colorInScreen = new Point3D(l, a, b); Vector3D distance = cXPrime - colorInScreen; if (distance.Length >= closestColor) { continue; } colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); if (ColorDistance >= closestColorValue) { continue; } closestColorValue = ColorDistance; cX = colorInScreen; closestColor = distance.Length; BinNUmber = index; } return(BinNUmber); }
public MainWindow() { InitializeComponent(); // sample test code PerceptionLib.Color SampleInputColor = new PerceptionLib.Color(); SampleInputColor.LA = 95.35070839; SampleInputColor.A = -9; SampleInputColor.B = 42.80004413; PerceptionLib.ColorRegion ColorValue = new PerceptionLib.ColorRegion(); ColorValue = PerceptionLib.Color.ToFindColorRegion(SampleInputColor); }
public static double HueAngle(PerceptionLib.Color colorToShow) { double value1 = colorToShow.B / colorToShow.A; //double value1 = -107.9785394 / 78.5459795; double radians = Math.Atan(value1); double ColorToShowangle = radians * (180 / Math.PI); if (ColorToShowangle < 0) { ColorToShowangle = ColorToShowangle + 360; } if (ColorToShowangle >= 360) { ColorToShowangle = ColorToShowangle - 360; } return(ColorToShowangle); }
public static int MatchWithBinnedColors_noSubration(DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; for (int k = 0; k < 1001; k++) { int i; double closestColorValue = double.MaxValue; PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); for (int index = 0; index < bin.Rows.Count; index++) { i = index; int BinNUmber1 = index; colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); colorToComparePlsBG_XYZ = ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); if (ColorDistance >= closestColorValue) { continue; } closestColorValue = ColorDistance; closestColorOnAddition = ColorDistance; BinNUmber = index; string a = bin.Rows[index][1].ToString(); } } return(BinNUmber); }
/// <summary> /// function lakes to lab value to find the huedeffirence between them /// based on :http://www.hunterlab.com/kb/hardware/d25ltvalues.pdf /// </summary> /// <param name="colorToCompare"></param> /// <param name="colorToComparePlsBG"></param> /// <returns></returns> public static double hueDifference(PerceptionLib.Color colorToCompare, PerceptionLib.Color colorToComparePlsBG) { double HueDifference = 0; // difference in L double DifferenceInL = (colorToCompare.LA - colorToComparePlsBG.LA) * (colorToCompare.LA - colorToComparePlsBG.LA); //color equlidin distance calculation double ColorDifference = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, colorToComparePlsBG); ColorDifference = ColorDifference * ColorDifference; //diffence in c calculation double Ca = (colorToCompare.A * colorToCompare.A) + (colorToCompare.B * colorToCompare.B); double colorToCompareC = Math.Sqrt(Ca); if (colorToCompareC > 5) { Ca = (colorToComparePlsBG.A * colorToComparePlsBG.A) + (colorToComparePlsBG.B * colorToComparePlsBG.B); double colorToComparePlsBGC = Math.Sqrt(Ca); if (colorToComparePlsBGC > 5) { double DifferenceInC = Math.Abs(colorToCompareC - colorToComparePlsBGC); DifferenceInC = DifferenceInC * DifferenceInC; HueDifference = Math.Sqrt(ColorDifference - DifferenceInL - DifferenceInC); HueDifferenceFlag = 0; } else { HueDifferenceFlag = 1; } } else { HueDifferenceFlag = 1; } return(HueDifference); }
private static Bin FindForegroundBin(Bin[, ,] profile, Matrix3D navigationMatrix, System.Drawing.Color foregroundRGB) { PerceptionLib.Color foregroundLAB = PerceptionLib.Color.ToLAB(foregroundRGB); int binL = ((int)(Math.Round(foregroundLAB.LA / 5.0)) * 5); int binA = ((int)(Math.Round(foregroundLAB.A / 5.0)) * 5); int binB = ((int)(Math.Round(foregroundLAB.B / 5.0)) * 5); if (binL < 0) { binL = 0; } if (binL > 100) { binL = 100; } if (binA < -86.17385493791946) { binA = -85; } if (binA > 98.2448002875424) { binA = 100; } if (binB < -107.8619171648283) { binB = -110; } if (binB > 94.47705120353054) { binB = 95; } Bin foregroundBin = GetProfileBin(profile, navigationMatrix.Transform(new Point3D(binL, binA, binB))); return(foregroundBin); }
private double CalculateDistance(DataRowView dataRowView, String fromVar, String toVar) { double fromL = Double.Parse(dataRowView[fromVar + "_L"] as String); double froma = Double.Parse(dataRowView[fromVar + "_a"] as String); double fromb = Double.Parse(dataRowView[fromVar + "_b"] as String); PerceptionLib.Color fromColor = new PerceptionLib.Color() { L = fromL, A = froma, B = fromb }; double toL = Double.Parse(dataRowView[toVar + "_L"] as String); double toa = Double.Parse(dataRowView[toVar + "_a"] as String); double tob = Double.Parse(dataRowView[toVar + "_b"] as String); PerceptionLib.Color toColor = new PerceptionLib.Color() { L = toL, A = toa, B = tob }; double distance = PerceptionLib.Color.ColorDistanceCalAB(fromColor, toColor); return(distance); }
private double CalculateDistance(DataRowView dataRowView, String fromVar, String toVar) { double fromL = Double.Parse(dataRowView[fromVar + "_L"] as String); double froma = Double.Parse(dataRowView[fromVar + "_a"] as String); double fromb = Double.Parse(dataRowView[fromVar + "_b"] as String); PerceptionLib.Color fromColor = new PerceptionLib.Color() { L = fromL, A = froma, B = fromb }; double toL = Double.Parse(dataRowView[toVar + "_L"] as String); double toa = Double.Parse(dataRowView[toVar + "_a"] as String); double tob = Double.Parse(dataRowView[toVar + "_b"] as String); PerceptionLib.Color toColor = new PerceptionLib.Color() { L = toL, A = toa, B = tob }; double distance = PerceptionLib.Color.ColorDistanceCalAB(fromColor, toColor); return distance; }
static void Main(string[] args) { try { CudafyModule km = CudafyModule.TryDeserialize(); if (km == null || !km.TryVerifyChecksums()) { km = CudafyTranslator.Cudafy(); km.TrySerialize(); } CudafyTranslator.GenerateDebug = true; // cuda or emulator GPGPU gpu = CudafyHost.GetDevice(CudafyModes.Target, CudafyModes.DeviceId); gpu.LoadModule(km); //set up color profile to have a measure LAB lookup working #region 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:\lev\STColorCorrection\Data\PROFILE\p3700.csv")) { System.Data.DataSet dsResult = parser.GetDataSet(); profile = dsResult.Tables[0]; } } catch { } // #region 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); if (labCoordinate.X == 20 && labCoordinate.Y == 20 && labCoordinate.Z == 22) { Console.WriteLine("empty"); } //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; } #endregion //CVS FILE CREATING AND INICIALIZATION #region //create the CSV file CsvFileWriter output_file_1 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file1.csv"); CsvFileWriter output_file_2 = new CsvFileWriter(@"C:\lev\STColorCorrection\Data\CUDA performance analysis\out_file2.csv"); //create the header CsvRow header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("Cuda BF time"); header.Add("QC_Dist"); header.Add("Cuda QC time"); header.Add("Snake_Dist"); header.Add("Cuda Snake time"); header.Add("DecreaseStep_DS"); header.Add("Cuda DS time"); output_file_1.WriteRow(header); header = new CsvRow(); header.Add("R_fg_in"); header.Add("G_fg_in"); header.Add("B_fg_in"); header.Add("L_fg_in"); header.Add("A_fg_in"); header.Add("B_fg_in"); header.Add("X_bg_in"); header.Add("Y_bg_in"); header.Add("Z_bg_in"); header.Add("BF_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("QC_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("Snake_Dist"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); header.Add("DecreaseStep_DS"); header.Add("R_fg_out"); header.Add("G_fg_out"); header.Add("B_fg_out"); output_file_2.WriteRow(header); //write the header to the CSV file #endregion Random randomGenerater = new Random(); for (int num_colors = 0; num_colors < 500; num_colors++) { //create a new csv row CsvRow new_row_file_1 = new CsvRow(); CsvRow new_row_file_2 = new CsvRow(); //colour selection Byte[] rgb = new Byte[3]; randomGenerater.NextBytes(rgb); System.Drawing.Color foreground = System.Drawing.Color.FromArgb(rgb[0], rgb[1], rgb[2]); Point3D backgroundCIEXYZ = new Point3D(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 foregroundLAB = new PerceptionLib.Color(); foregroundLAB.LA = foregroundBin.measuredLAB.X; foregroundLAB.A = foregroundBin.measuredLAB.Y; foregroundLAB.B = foregroundBin.measuredLAB.Z; //write the input colors #region new_row_file_1.Add(foreground.R.ToString()); new_row_file_1.Add(foreground.G.ToString()); new_row_file_1.Add(foreground.B.ToString()); new_row_file_1.Add(foregroundLAB.LA.ToString()); new_row_file_1.Add(foregroundLAB.A.ToString()); new_row_file_1.Add(foregroundLAB.B.ToString()); new_row_file_1.Add(background.X.ToString()); new_row_file_1.Add(background.Y.ToString()); new_row_file_1.Add(background.Z.ToString()); new_row_file_2.Add(foreground.R.ToString()); new_row_file_2.Add(foreground.G.ToString()); new_row_file_2.Add(foreground.B.ToString()); new_row_file_2.Add(foregroundLAB.LA.ToString()); new_row_file_2.Add(foregroundLAB.A.ToString()); new_row_file_2.Add(foregroundLAB.B.ToString()); new_row_file_2.Add(background.X.ToString()); new_row_file_2.Add(background.Y.ToString()); new_row_file_2.Add(background.Z.ToString()); #endregion //get the brute force values Color.TestingStructure[] results_brute_force = Color.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_brute_force[0].distance.ToString()); new_row_file_1.Add(results_brute_force[0].execution_time.ToString()); Point3D labBin = new Point3D(); labBin.X = results_brute_force[0].Given_R; labBin.Y = results_brute_force[0].Given_G; labBin.Z = results_brute_force[0].Given_B; Bin actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_brute_force[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); quick_corr.TestingStructure[] results_quick_corr = quick_corr.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_quick_corr[0].distance.ToString()); new_row_file_1.Add(results_quick_corr[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_quick_corr[0].Given_R; labBin.Y = results_quick_corr[0].Given_G; labBin.Z = results_quick_corr[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_quick_corr[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); snake.TestingStructure[] results_snake = snake.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_snake[0].distance.ToString()); new_row_file_1.Add(results_snake[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_snake[0].Given_R; labBin.Y = results_snake[0].Given_G; labBin.Z = results_snake[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_snake[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); half_step.TestingStructure[] results_half_step = half_step.CorrectColour(foreground, background.X, background.Y, background.Z); new_row_file_1.Add(results_half_step[0].distance.ToString()); new_row_file_1.Add(results_half_step[0].execution_time.ToString()); labBin = new Point3D(); labBin.X = results_half_step[0].Given_R; labBin.Y = results_half_step[0].Given_G; labBin.Z = results_half_step[0].Given_B; actualBin = GetProfileBin(p3700, labBin); new_row_file_2.Add(results_half_step[0].distance.ToString()); new_row_file_2.Add(actualBin.binRGB.X.ToString()); new_row_file_2.Add(actualBin.binRGB.Y.ToString()); new_row_file_2.Add(actualBin.binRGB.Z.ToString()); //write the results output_file_1.WriteRow(new_row_file_1); output_file_2.WriteRow(new_row_file_2); } //Color.Execute(); //quick_corr.Execute(); //close the CSV files output_file_1.Close(); output_file_2.Close(); Console.WriteLine("Done!"); } catch (Exception ex) { Console.WriteLine(ex); } theEnd: Console.ReadKey(); }
private void Button_Click_Refresh(object sender, RoutedEventArgs e) { if (dataView == null) { MessageBox.Show("Need to import data!"); return; } if (cbFrom.SelectedIndex == -1 || cbTo.SelectedIndex == -1) { MessageBox.Show("Please select from and to variables"); return; } ApplyFilters(); cvHeatMap.Children.Clear(); foreach (HeatMapData heatMapData in heatMap) { heatMapData.DataSize = 0; heatMapData.DataSum = 0; heatMapData.IsOutsideGammut = false; } foreach (DataRowView dataRowView in dataView) { var x_value = Double.Parse(dataRowView[Settings.Default.XColumnName].ToString()); var y_value = Double.Parse(dataRowView[Settings.Default.YColumnName].ToString()); int col = (int)((HeatMapData.GRID_SIZE * (x_value + 100) / Settings.Default.DataMapWidth)); int row = HeatMapData.GRID_SIZE - (int)((HeatMapData.GRID_SIZE * (y_value + 100) / Settings.Default.DataMapHeight)) - 1; var heatMapData = heatMap[row, col]; String IntensitySelection = (cbIntensity.SelectedItem as ComboBoxItem).Tag as String; if (IntensitySelection != "0") { double intensity = Double.Parse(dataRowView["Fg_L"] as String); if (IntensitySelection == "1" && intensity < 50) { continue; } if (IntensitySelection == "-1" && intensity >= 50) { continue; } } // to slect a color from a perticular region PerceptionLib.Color ColorFromData = new PerceptionLib.Color(); ColorFromData.LA = Double.Parse(dataRowView["Fg_L"] as String); ColorFromData.A = Double.Parse(dataRowView["Fg_a"] as String); ColorFromData.B = Double.Parse(dataRowView["Fg_b"] as String); PerceptionLib.ColorRegion RegionObj = PerceptionLib.Color.ToFindColorRegion(ColorFromData); //foreach (Object selecteditem in ListColorRegion.SelectedItems) //{ // String RegionSelection = (ListColorRegion.SelectedItems as ListBoxItem).Tag as String; // if (RegionSelection != "0") // { // if (RegionSelection == "1" && RegionObj.RegionValue != 1) // continue; // if (RegionSelection == "2" && RegionObj.RegionValue != 2) // continue; // if (RegionSelection == "3" && RegionObj.RegionValue != 3) // continue; // if (RegionSelection == "4" && RegionObj.RegionValue != 4) // continue; // if (RegionSelection == "5" && RegionObj.RegionValue != 5) // continue; // if (RegionSelection == "6" && RegionObj.RegionValue != 6) // continue; // } //} string NuteralSelection = (cbNuetral.SelectedItem as ComboBoxItem).Tag as String; if (NuteralSelection != "0") { if (NuteralSelection == "1" && RegionObj.NetralValueFlag != 0) { continue; } if (NuteralSelection == "-1" && RegionObj.NetralValueFlag == 0) { continue; } } String RegionSel = (cbColorRegion.SelectedItem as ComboBoxItem).Tag as String; if (RegionSel != "0") { if (RegionSel == "1" && RegionObj.RegionValue != 1) { continue; } if (RegionSel == "2" && RegionObj.RegionValue != 2) { continue; } if (RegionSel == "3" && RegionObj.RegionValue != 3) { continue; } if (RegionSel == "4" && RegionObj.RegionValue != 4) { continue; } if (RegionSel == "5" && RegionObj.RegionValue != 5) { continue; } if (RegionSel == "6" && RegionObj.RegionValue != 6) { continue; } } heatMapData.DataSum += CalculateDistance(dataRowView, cbFrom.SelectedItem as String, cbTo.SelectedItem as String); heatMapData.DataSize++; } CorrectMap(); DrawMap(); }
/// <summary> /// funtion to calcullate bin number /// </summary> /// <param name="ColorToCompensate"></param> /// <param name="bin"></param> /// <returns></returns> public static int MatchWithBinnedColors(PerceptionLib.Color ColorToCompensate, DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; int i; double closestColor = double.MaxValue; double closestColorValue = double.MaxValue; double angleDifference = double.MaxValue; PerceptionLib.Color colorToCompare = new PerceptionLib.Color(); PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); for (int index = 0; index < bin.Rows.Count; index++) { i = index; colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); if (distance >= closestColor) { continue; } ClosestL = colorToCompare.LA; ClosestA = colorToCompare.A; ClosestB = colorToCompare.B; int BinNUmber1 = index; colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); if (ColorDistance >= closestColorValue) { continue; } closestColorValue = ColorDistance; closestColor = distance; closestColorInsideTheBin = distance; closestColorOnAddition = ColorDistance; HueAngeDifference = angleDifference; BinNUmber = index; } //if (closestColorOnAddition >= 5) //{ // double LA = Convert.ToDouble(bin.Rows[BinNUmber][9].ToString()); // double A = Convert.ToDouble(bin.Rows[BinNUmber][10].ToString()); // double B = Convert.ToDouble(bin.Rows[BinNUmber][11].ToString()); // for (int index = 0; index < bin.Rows.Count; index++) // { // colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); // colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); // colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); // if (colorToCompare.LA <= LA + 4 & colorToCompare.LA >= LA - 4) // { // colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); // colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); // colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); // colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); // colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); // double colorToShowAngle = HueAngle(ColorToShow); // double colorToCompareangle = HueAngle(colorToComparePlsBG); // double angleDiff = Math.Abs(colorToShowAngle - colorToCompareangle); // if (angleDiff >= angleDifference) // continue; // double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); // double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); // angleDifference = angleDiff; // closestColorValue = ColorDistance; // closestColor = distance; // closestColorInsideTheBin = distance; // closestColorOnAddition = ColorDistance; // HueAngeDifference = angleDifference; // BinNUmber = index; // } // } //} //if (closestColorOnAddition >= 5) //{ // double LA = Convert.ToDouble(bin.Rows[BinNUmber][9].ToString()); // double A = Convert.ToDouble(bin.Rows[BinNUmber][10].ToString()); // double B = Convert.ToDouble(bin.Rows[BinNUmber][11].ToString()); // for (int index = 0; index < bin.Rows.Count; index++) // { // colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); // colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); // colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); // if (colorToCompare.LA <= LA + 4 & colorToCompare.LA >= LA - 4) // { // colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); // colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); // colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); // colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); // colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); // double hueDiff = hueDifference(colorToCompare, colorToComparePlsBG); // if (HueDifferenceFlag != 1) // { // if (hueDiff >= angleDifference) // continue; // double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); // double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); // angleDifference = hueDiff; // closestColorValue = ColorDistance; // closestColor = distance; // closestColorInsideTheBin = distance; // closestColorOnAddition = ColorDistance; // HueAngeDifference = angleDifference; // BinNUmber = index; // } // } // } //} return(BinNUmber); }
public static int MatchWithBinnedColors_noSubration(DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; for (int k = 0; k < 1001; k++) { int i; double closestColorValue = double.MaxValue; PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); for (int index = 0; index < bin.Rows.Count; index++) { i = index; int BinNUmber1 = index; colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); colorToComparePlsBG_XYZ = ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); if (ColorDistance >= closestColorValue) continue; closestColorValue = ColorDistance; closestColorOnAddition = ColorDistance; BinNUmber = index; string a = bin.Rows[index][1].ToString(); } } return BinNUmber; }
/// <summary> /// funtion to calcullate bin number /// </summary> /// <param name="ColorToCompensate"></param> /// <param name="bin"></param> /// <returns></returns> public static int MatchWithBinnedColors(PerceptionLib.Color ColorToCompensate, DataTable bin, PerceptionLib.CIEXYZ BG, PerceptionLib.Color ColorToShow) { int BinNUmber = 0; int i; double closestColor = double.MaxValue; double closestColorValue = double.MaxValue; double angleDifference = double.MaxValue; PerceptionLib.Color colorToCompare = new PerceptionLib.Color(); PerceptionLib.CIEXYZ colorToCompareXYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.CIEXYZ colorToComparePlsBG_XYZ = new PerceptionLib.CIEXYZ(0, 0, 0); PerceptionLib.Color colorToComparePlsBG = new PerceptionLib.Color(); for (int index = 0; index < bin.Rows.Count; index++) { i = index; colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); if (distance >= closestColor) continue; ClosestL = colorToCompare.LA; ClosestA = colorToCompare.A; ClosestB = colorToCompare.B; int BinNUmber1 = index; colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); colorToComparePlsBG_XYZ = ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); if (ColorDistance >= closestColorValue) continue; closestColorValue = ColorDistance; closestColor = distance; closestColorInsideTheBin = distance; closestColorOnAddition = ColorDistance; HueAngeDifference = angleDifference; BinNUmber = index; } //if (closestColorOnAddition >= 5) //{ // double LA = Convert.ToDouble(bin.Rows[BinNUmber][9].ToString()); // double A = Convert.ToDouble(bin.Rows[BinNUmber][10].ToString()); // double B = Convert.ToDouble(bin.Rows[BinNUmber][11].ToString()); // for (int index = 0; index < bin.Rows.Count; index++) // { // colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); // colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); // colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); // if (colorToCompare.LA <= LA + 4 & colorToCompare.LA >= LA - 4) // { // colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); // colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); // colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); // colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); // colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); // double colorToShowAngle = HueAngle(ColorToShow); // double colorToCompareangle = HueAngle(colorToComparePlsBG); // double angleDiff = Math.Abs(colorToShowAngle - colorToCompareangle); // if (angleDiff >= angleDifference) // continue; // double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); // double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); // angleDifference = angleDiff; // closestColorValue = ColorDistance; // closestColor = distance; // closestColorInsideTheBin = distance; // closestColorOnAddition = ColorDistance; // HueAngeDifference = angleDifference; // BinNUmber = index; // } // } //} //if (closestColorOnAddition >= 5) //{ // double LA = Convert.ToDouble(bin.Rows[BinNUmber][9].ToString()); // double A = Convert.ToDouble(bin.Rows[BinNUmber][10].ToString()); // double B = Convert.ToDouble(bin.Rows[BinNUmber][11].ToString()); // for (int index = 0; index < bin.Rows.Count; index++) // { // colorToCompare.LA = Convert.ToDouble(bin.Rows[index][9].ToString()); // colorToCompare.A = Convert.ToDouble(bin.Rows[index][10].ToString()); // colorToCompare.B = Convert.ToDouble(bin.Rows[index][11].ToString()); // if (colorToCompare.LA <= LA + 4 & colorToCompare.LA >= LA - 4) // { // colorToCompareXYZ.X = Convert.ToDouble(bin.Rows[index][12].ToString()); // colorToCompareXYZ.Y = Convert.ToDouble(bin.Rows[index][13].ToString()); // colorToCompareXYZ.Z = Convert.ToDouble(bin.Rows[index][14].ToString()); // colorToComparePlsBG_XYZ = Util.ColorSpaceConverter.AddXYZ(colorToCompareXYZ, BG); // colorToComparePlsBG = PerceptionLib.Color.ToLUV(colorToComparePlsBG_XYZ); // double hueDiff = hueDifference(colorToCompare, colorToComparePlsBG); // if (HueDifferenceFlag != 1) // { // if (hueDiff >= angleDifference) // continue; // double ColorDistance = PerceptionLib.Color.ColorDistanceCalAB(colorToComparePlsBG, ColorToShow); // double distance = PerceptionLib.Color.ColorDistanceCalAB(colorToCompare, ColorToCompensate); // angleDifference = hueDiff; // closestColorValue = ColorDistance; // closestColor = distance; // closestColorInsideTheBin = distance; // closestColorOnAddition = ColorDistance; // HueAngeDifference = angleDifference; // BinNUmber = index; // } // } // } //} return BinNUmber; }
/// <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); }