Beispiel #1
0
 public static void InitPCT()
 {
     if (ConfigPCT.COLOR_SPACE_USING == ConfigPCT.ColorSpace.Lab)
     {
         if (ConfigPCT.FORMULA_LAB_USING == ConfigPCT.FormulaLab.Lab_CIE76)
         {
             calDistanceLabHandler = CalDistance_CIE76;
         }
         else if (ConfigPCT.FORMULA_LAB_USING == ConfigPCT.FormulaLab.Lab_CMCIC)
         {
             calDistanceLabHandler = CalDistance_CMCIC;
         }
         else if (ConfigPCT.FORMULA_LAB_USING == ConfigPCT.FormulaLab.Lab_CIE94)
         {
             calDistanceLabHandler = CalDistance_CIE94;
         }
         else if (ConfigPCT.FORMULA_LAB_USING == ConfigPCT.FormulaLab.Lab_CIE2000)
         {
             calDistanceLabHandler = CalDistance_CIE2000;
         }
     }
 }
Beispiel #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);
        }