Ejemplo n.º 1
0
        static ColorComparer()
        {
            dc = new DistanceComparer();

            nc = new NameComparer();

            sc = new SaturationComparer();

            hc = new HueComparer();

            bc = new BrightnessComparer();

            uc = new UnsortedComparer();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Eliminate colors from the histogram to get closer to the palette colors
        /// </summary>
        /// <param name="colorList">the histogram</param>
        /// <returns>The list of unique colors that will become the palette</returns>
        private static IEnumerable <Color> Cut(IEnumerable <Color> colorList)
        {
            // If there's less or equal to the allowed amount of colors, we're done
            if (colorList.Count() <= PALETTE_MAX_COUNT)
            {
                return(colorList);
            }

            // Create the comparers
            var hueComparer        = new HueComparer();
            var saturationComparer = new SaturationComparer();
            var brightnessComparer = new BrightnessComparer();

            // Get the colors with unique hue, staturation and brightness
            var hue        = colorList.Distinct(hueComparer);
            var saturation = colorList.Distinct(saturationComparer);
            var brightness = colorList.Distinct(brightnessComparer);

            var hueCount        = hue.Count();
            var saturationCount = saturation.Count();
            var brightnessCount = brightness.Count();

            // If there are many distinct hue's in the image, make sure to include most of them and prepare to eliminate more
            if (hueCount > saturationCount && hueCount > brightnessCount)
            {
                return(Cut2(hue, saturationComparer, brightnessComparer));
            }
            // If there are many distinct saturations in the image, make sure to inclode most of them and prepare to eliminate more
            else if (saturationCount > hueCount && saturationCount > brightnessCount)
            {
                return(Cut2(saturation, hueComparer, brightnessComparer));
            }
            // If there are many distinct luminations in the image, make sure to inclode most of them and prepare to eliminate more
            else
            {
                return(Cut2(brightness, hueComparer, saturationComparer));
            }
        }