示例#1
0
        protected override double CalcScore(SectionedLabCounts a, SectionedLab b)
        {
            /*double left = Comparer.Compare(a.Lab.Left, TransformLab(b.Lab.Left)) * a.Counts.Left;
             * double right = Comparer.Compare(a.Lab.Right, TransformLab(b.Lab.Right)) * a.Counts.Right;
             * double top = Comparer.Compare(a.Lab.Top, TransformLab(b.Lab.Top)) * a.Counts.Top;
             * double bottom = Comparer.Compare(a.Lab.Bottom, TransformLab(b.Lab.Bottom)) * a.Counts.Bottom;
             * double center = Comparer.Compare(a.Lab.Center, TransformLab(b.Lab.Center)) * a.Counts.Center;
             * double all = Comparer.Compare(a.Lab.All, TransformLab(b.Lab.All)) * a.Counts.All;
             * return left + right + top + bottom + center + all * AllFactor;*/
            /*double left = Comparer.Compare(a.Lab.Left, b.Lab.Left) * a.Counts.Left;
             * double right = Comparer.Compare(a.Lab.Right, b.Lab.Right) * a.Counts.Right;
             * double top = Comparer.Compare(a.Lab.Top, b.Lab.Top) * a.Counts.Top;
             * double bottom = Comparer.Compare(a.Lab.Bottom, b.Lab.Bottom) * a.Counts.Bottom;
             * double center = Comparer.Compare(a.Lab.Center, b.Lab.Center) * a.Counts.Center;
             * double all = Comparer.Compare(a.Lab.All, b.Lab.All) * a.Counts.All;
             * return left + right + top + bottom + center + all * AllFactor;*/
            double left   = Cie76Comparison.CompareS(a.Lab.Left, b.Left) * a.Counts.Left;
            double right  = Cie76Comparison.CompareS(a.Lab.Right, b.Right) * a.Counts.Right;
            double top    = Cie76Comparison.CompareS(a.Lab.Top, b.Top) * a.Counts.Top;
            double bottom = Cie76Comparison.CompareS(a.Lab.Bottom, b.Bottom) * a.Counts.Bottom;
            double center = Cie76Comparison.CompareS(a.Lab.Center, b.Center) * a.Counts.Center;
            double all    = Cie76Comparison.CompareS(a.Lab.All, b.All) * a.Counts.All;

            return(left + right + top + bottom + center + all * AllFactor);
        }
示例#2
0
        private static List <Color> GetMainColorsByLab(IEnumerable <ColorCount> colors, int maxCount, double minDiff, double lWeight = 1d)
        {
            //List<Tuple<Color, ColorLab>> mainColors = new List<Tuple<Color, ColorLab>>();
            List <Color>    results = new List <Color>();
            List <ColorLab> labs    = new List <ColorLab>();

            long lastCount = -1;

            foreach (ColorCount colorCount in colors)
            {
                long     count = colorCount.Count;
                Color    color = colorCount.Color;
                ColorLab lab   = LabConverter.ToLab(color);
                lab.L *= lWeight;

                bool uniqueColorFound = true;
                foreach (ColorLab labOther in labs)
                {
                    double score = Cie76Comparison.CompareS(lab, labOther);

                    if (score < minDiff)
                    {
                        uniqueColorFound = false;
                        break;
                    }
                }
                if (uniqueColorFound)                         // color differs by min ammount of HSL so add to response
                {
                    results.Add(color);
                    labs.Add(lab);
                    if (results.Count == maxCount)
                    {
                        break;
                    }
                }
                lastCount = count;
            }

            Trace.WriteLine($"Colors Found: {results.Count}/{maxCount}");
            return(results);
        }
示例#3
0
 protected override double CalcScore(ColorLab a, ColorLab b)
 {
     //return Comparer.Compare(a, b, true);
     return(Cie76Comparison.CompareS(a, b, true));
 }