Ejemplo n.º 1
0
        // Distance between two colors in Y'UV plane
        public static double DistanceTo(this YUVColor color1, YUVColor color2)
        {
            var o1 = Math.Pow (color1.U - color2.U, 2);
            var o2 = Math.Pow (color1.V - color2.V, 2);

            return Math.Sqrt (o1 + o2);
        }
Ejemplo n.º 2
0
        // Distance between two colors in Y'UV plane
        public static double DistanceTo(this YUVColor color1, YUVColor color2)
        {
            var o1 = Math.Pow(color1.U - color2.U, 2);
            var o2 = Math.Pow(color1.V - color2.V, 2);

            return(Math.Sqrt(o1 + o2));
        }
Ejemplo n.º 3
0
        public static int IndexOfItemWithColorFromRange(this List <PixelColor> list, YUVColor color, double range)
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Color.DistanceTo(color) <= range)
                {
                    // In range!
                    return(i);
                }
            }

            return(-1);
        }
Ejemplo n.º 4
0
        // Darkens color by specified distance
        public static YUVColor DarkenByDistane(this YUVColor color, float distance)
        {
            YUVColor result = (YUVColor)color.Clone();

            result.Y -= distance;

            if (result.Y < 0)
            {
                // Y value can't be < 0
                result.Y = 0.15f;
            }

            return(result);
        }
Ejemplo n.º 5
0
        // Lighttens color by specified distance
        public static YUVColor LighttenByDistane(this YUVColor color, float distance)
        {
            YUVColor result = (YUVColor)color.Clone();

            result.Y += distance;

            if (result.Y > 1)
            {
                // Y value can't be > 1
                result.Y = 0.85f;
            }

            return(result);
        }
Ejemplo n.º 6
0
        // Returns color that is at specified distance from specified color in Y'UV plane
        public static YUVColor ColorAtDistanceFrom(this YUVColor color, YUVColor referenceColor, float distance)
        {
            YUVColor result = new YUVColor() {Y = color.Y, U = color.U, V = color.V};

            if(color.Y > referenceColor.Y)
            {
                // Need to increase color.Y value
                result.Y = referenceColor.Y + distance;
            }
            else
            {
                // Need to decrease color.Y value
                result.Y = referenceColor.Y - distance;
            }

            return result;
        }
Ejemplo n.º 7
0
        // Returns color that is at specified distance from specified color in Y'UV plane
        public static YUVColor ColorAtDistanceFrom(this YUVColor color, YUVColor referenceColor, float distance)
        {
            YUVColor result = new YUVColor()
            {
                Y = color.Y, U = color.U, V = color.V
            };

            if (color.Y > referenceColor.Y)
            {
                // Need to increase color.Y value
                result.Y = referenceColor.Y + distance;
            }
            else
            {
                // Need to decrease color.Y value
                result.Y = referenceColor.Y - distance;
            }

            return(result);
        }