コード例 #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);
        }
コード例 #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);
        }
        static double LabDistance(Color rgb1, Color rgb2)
        {
            Lab lab1 = new Lab(), lab2 = new Lab();

            LabConverter.ToColorSpace(new Rgb {
                R = rgb1.R, G = rgb1.G, B = rgb1.B
            }, lab1);
            LabConverter.ToColorSpace(new Rgb {
                R = rgb2.R, G = rgb2.G, B = rgb2.B
            }, lab2);
            return(Math.Pow(lab2.L - lab1.L, 2) + Math.Pow(lab2.A - lab1.A, 2) + Math.Pow(lab2.B - lab1.B, 2));
        }
コード例 #4
0
        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));
        }
コード例 #5
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));
        }
コード例 #6
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);
        }
コード例 #7
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);
        }
コード例 #8
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);
        }
コード例 #9
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));
        }
コード例 #10
0
 public override IRgb ToRgb()
 {
     return(LabConverter.ToColor(this));
 }
コード例 #11
0
 public override void Initialize(IRgb color)
 {
     LabConverter.ToColorSpace(color, this);
 }
コード例 #12
0
 protected override ColorLab CalcFontData(Color color)
 {
     return(LabConverter.ToLab(color));
 }
コード例 #13
0
 protected override SectionedDouble CalcFontData(Color color)
 {
     return(new SectionedDouble(LabConverter.ToLab(color).L / 100));
 }
コード例 #14
0
 protected override double CalcFontData(Color color)
 {
     return(LabConverter.ToLab(color).L / 100);
 }
コード例 #15
0
 protected override SectionedLab CalcFontData(Color color)
 {
     return(new SectionedLab(LabConverter.ToLab(color)));
 }