private void radioButton_CheckedChanged(object sender, EventArgs e)
        {
            if (rbtnRgbEuclid.Checked)
            {
                currentColorSpaceForFormula = ConfigPCT.ColorSpace.RGB;
                currentDistanceFormulaRGB   = ConfigPCT.FormulaRGB.RGB_Euclid;
            }
            else if (rbtnCIE76.Checked)
            {
                currentColorSpaceForFormula = ConfigPCT.ColorSpace.Lab;
                currentDistanceFormulaLab   = ConfigPCT.FormulaLab.Lab_CIE76;
            }
            else if (rbtnCMCIC.Checked)
            {
                currentColorSpaceForFormula = ConfigPCT.ColorSpace.Lab;
                currentDistanceFormulaLab   = ConfigPCT.FormulaLab.Lab_CMCIC;
            }
            else if (rbtnCIE94.Checked)
            {
                currentColorSpaceForFormula = ConfigPCT.ColorSpace.Lab;
                currentDistanceFormulaLab   = ConfigPCT.FormulaLab.Lab_CIE94;
            }
            else if (rbtnCIE2000.Checked)
            {
                currentColorSpaceForFormula = ConfigPCT.ColorSpace.Lab;
                currentDistanceFormulaLab   = ConfigPCT.FormulaLab.Lab_CIE2000;
            }

            panel1.Refresh();
        }
Ejemplo n.º 2
0
        // force to use a formula to calculate
        public static int ColorKNN(Color c, List <Color> listColor, ConfigPCT.ColorSpace colorSpace, ConfigPCT.FormulaRGB formulaRGBForUse, ConfigPCT.FormulaLab formulaLabForUse)
        {
            if (listColor == null || listColor.Count == 0)
            {
                return(-1);
            }

            CalDistanceLabDlgt calDistanceHandlerLocal = null;

            if (colorSpace == ConfigPCT.ColorSpace.Lab)
            {
                if (formulaLabForUse == ConfigPCT.FormulaLab.Lab_CIE76)
                {
                    calDistanceHandlerLocal = CalDistance_CIE76;
                }
                else if (formulaLabForUse == ConfigPCT.FormulaLab.Lab_CMCIC)
                {
                    calDistanceHandlerLocal = CalDistance_CMCIC;
                }
                else if (formulaLabForUse == ConfigPCT.FormulaLab.Lab_CIE94)
                {
                    calDistanceHandlerLocal = CalDistance_CIE94;
                }
                else if (formulaLabForUse == ConfigPCT.FormulaLab.Lab_CIE2000)
                {
                    calDistanceHandlerLocal = CalDistance_CIE2000;
                }
            }

            Lab labColor = ColorHelper.RgbToLab(new Rgb {
                R = c.R, G = c.G, B = c.B
            });
            double minDistance;

            if (colorSpace == ConfigPCT.ColorSpace.RGB)
            {
                minDistance = CalDistance_RGBEuclid(c, listColor[0]);
            }
            else
            {
                minDistance = calDistanceHandlerLocal(labColor, ColorHelper.RgbToLab(new Rgb {
                    R = listColor[0].R, G = listColor[0].G, B = listColor[0].B
                }));
            }

            int size       = listColor.Count;
            int indexColor = 0;

            for (int i = 1; i < size; i++)
            {
                double dis;
                if (colorSpace == ConfigPCT.ColorSpace.RGB)
                {
                    dis = CalDistance_RGBEuclid(c, listColor[i]);
                }
                else
                {
                    dis = calDistanceHandlerLocal(labColor, ColorHelper.RgbToLab(new Rgb {
                        R = listColor[i].R, G = listColor[i].G, B = listColor[i].B
                    }));
                }

                if (dis < minDistance)
                {
                    minDistance = dis;
                    indexColor  = i;
                }
            }
            return(indexColor);
        }