Example #1
0
        protected override SectionedDouble CalcFontData(IEnumerable <PixelPoint> pixels)
        {
            SectionedDouble area = new SectionedDouble();

            foreach (PixelPoint p in pixels)
            {
                double color = LabConverter.ToLab(p.Color).L;
                if (p.X < left)
                {
                    area.Left += color;
                }
                else if (p.X >= right)
                {
                    area.Right += color;
                }
                if (p.Y < top)
                {
                    area.Top += color;
                }
                else if (p.Y >= bottom)
                {
                    area.Bottom += color;
                }
                if (p.X >= left && p.X < right &&
                    p.Y >= top && p.Y < bottom)
                {
                    area.Center += color;
                }
                area.All += color;
            }
            return((area / (fontCounts * 100)).ZeroNaNs);
        }
Example #2
0
        protected override ColorLab CalcImageData(IEnumerable <PixelPoint> pixels, Point start)
        {
            int      count     = 0;
            ColorLab charValue = new ColorLab();

            foreach (PixelPoint p in pixels)
            {
                charValue += LabConverter.ToLab(p.Color);
                count++;
            }
            return(charValue / count);
        }
        protected override double CalcImageData(IEnumerable <PixelPoint> pixels, Point start)
        {
            double intensityTotal = 0;
            double count          = 0;

            foreach (PixelPoint p in pixels)
            {
                intensityTotal += LabConverter.ToLab(p.Color).L;
                count++;
            }
            return(intensityTotal / (count * 100));
        }
Example #4
0
        protected override SectionedLabCounts CalcImageData(IEnumerable <PixelPoint> pixels, Point start)
        {
            /*int leftCount = 0;
             * int rightCount = 0;
             * int topCount = 0;
             * int bottomCount = 0;
             * int centerCount = 0;
             * int allCount = 0;*/
            SectionedDouble counts = new SectionedDouble();
            SectionedLab    area   = new SectionedLab();

            foreach (PixelPoint p in pixels)
            {
                ColorLab color = LabConverter.ToLab(p.Color);
                if (p.X < left)
                {
                    area.Left += color;
                    counts.Left++;
                    //leftCount++;
                }
                else if (p.X >= right)
                {
                    area.Right += color;
                    counts.Right++;
                    //rightCount++;
                }
                if (p.Y < top)
                {
                    area.Top += color;
                    counts.Top++;
                    //topCount++;
                }
                else if (p.Y >= bottom)
                {
                    area.Bottom += color;
                    counts.Bottom++;
                    //bottomCount++;
                }
                if (p.X >= left && p.X < right &&
                    p.Y >= top && p.Y < bottom)
                {
                    area.Center += color;
                    counts.Center++;
                    //centerCount++;
                }
                area.All += color;
                counts.All++;
                //allCount++;
            }
            return(new SectionedLabCounts(area, counts));
        }
Example #5
0
        protected override ColorLab CalcFontData(IEnumerable <PixelPoint> pixels)
        {
            double   count     = 0;
            ColorLab charValue = new ColorLab();
            double   inc       = 1;

            foreach (PixelPoint p in pixels)
            {
                inc        = p.Color.A / 255d;
                charValue += LabConverter.ToLab(p.Color) * inc;
                count     += inc;
            }
            return((charValue / count).ZeroNaNs);
        }
Example #6
0
        protected override SectionedLab CalcFontData(IEnumerable <PixelPoint> pixels)
        {
            SectionedDouble counts = new SectionedDouble();
            SectionedLab    area   = new SectionedLab();
            double          inc    = 1;

            foreach (PixelPoint p in pixels)
            {
                inc = p.Color.A / 255d;
                ColorLab color = LabConverter.ToLab(p.Color) * inc;
                if (p.X < left)
                {
                    area.Left   += color;
                    counts.Left += inc;
                    //leftCount++;
                }
                else if (p.X >= right)
                {
                    area.Right   += color;
                    counts.Right += inc;
                    //rightCount++;
                }
                if (p.Y < top)
                {
                    area.Top   += color;
                    counts.Top += inc;
                    //topCount++;
                }
                else if (p.Y >= bottom)
                {
                    area.Bottom   += color;
                    counts.Bottom += inc;
                    //bottomCount++;
                }
                if (p.X >= left && p.X < right &&
                    p.Y >= top && p.Y < bottom)
                {
                    area.Center   += color;
                    counts.Center += inc;
                    //centerCount++;
                }
                area.All   += color;
                counts.All += inc;
                //allCount++;
            }
            return((area / counts).ZeroNaNs);
        }
Example #7
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);
        }
Example #8
0
        protected override SectionedDoubleCounts CalcImageData(IEnumerable <PixelPoint> pixels, Point start)
        {
            SectionedDouble area = new SectionedDouble();
            //SectionedInt area = new SectionedInt();
            SectionedDouble counts = new SectionedDouble();

            //double inc = 1;
            foreach (PixelPoint p in pixels)
            {
                double color = LabConverter.ToLab(p.Color).L;
                if (p.X < left)
                {
                    area.Left += color;
                    counts.Left++;
                }
                else if (p.X >= right)
                {
                    area.Right += color;
                    counts.Right++;
                }
                if (p.Y < top)
                {
                    area.Top += color;
                    counts.Top++;
                }
                else if (p.Y >= bottom)
                {
                    area.Bottom += color;
                    counts.Bottom++;
                }
                if (p.X >= left && p.X < right &&
                    p.Y >= top && p.Y < bottom)
                {
                    area.Center += color;
                    counts.Center++;
                }
                area.All += color;
                counts.All++;
            }
            return(new SectionedDoubleCounts(area, counts));
        }
Example #9
0
 protected override ColorLab CalcFontData(Color color)
 {
     return(LabConverter.ToLab(color));
 }
Example #10
0
 protected override SectionedDouble CalcFontData(Color color)
 {
     return(new SectionedDouble(LabConverter.ToLab(color).L / 100));
 }
 protected override double CalcFontData(Color color)
 {
     return(LabConverter.ToLab(color).L / 100);
 }
Example #12
0
 protected override SectionedLab CalcFontData(Color color)
 {
     return(new SectionedLab(LabConverter.ToLab(color)));
 }