예제 #1
0
        public static double DeltaE(Rgb img1, Rgb img2, int algorithm)
        {
            //create double for deltaE result
            double deltaE = 0d;

            //Set up a switch statement for switching between selected matching algorithm
            // 0 CIE76
            // 1 CIE94
            // 2 CMC l: C
            // 3 CIE2000
            switch (algorithm)
            {
            case 0:
                deltaE = img1.Compare(img2, new Cie1976Comparison());
                break;

            case 1:
                deltaE = img1.Compare(img2, new Cie94Comparison());
                break;

            case 2:
                deltaE = img1.Compare(img2, new CmcComparison());
                break;

            case 3:
                deltaE = img1.Compare(img2, new CieDe2000Comparison());
                break;
            }

            return(deltaE);
        }
예제 #2
0
        public static OlCategoryColor FindMatchingCategoryColor(Color color)
        {
            var minDistance           = double.MaxValue;
            var matchingCategoryColor = OlCategoryColor.olCategoryColorNone;

            foreach (var cat in ArgbColorByCategoryColor)
            {
                var catColor = Color.FromArgb(cat.Value.ArgbValue);

                var a = new Rgb {
                    R = color.R, G = color.G, B = color.B
                };
                var b = new Rgb {
                    R = catColor.R, G = catColor.G, B = catColor.B
                };

                var curDistance = a.Compare(b, new ColorMine.ColorSpaces.Comparisons.CieDe2000Comparison());

                if (curDistance < minDistance)
                {
                    minDistance           = curDistance;
                    matchingCategoryColor = cat.Key;
                }
            }

            return(matchingCategoryColor);
        }
예제 #3
0
        private static ConsoleColor GetConsoleColor(Color color)
        {
            var bestChoice = ConsoleColor.Black;

            if (color.A < 50)
            {
                return(bestChoice);
            }

            var comparer = new CieDe2000Comparison();
            var labColor = new Rgb()
            {
                R = color.R, G = color.G, B = color.B
            }.To <Lab>();

            var minDiff = Double.MaxValue;

            foreach (var kvp in _colorMap)
            {
                var testColor = new Rgb()
                {
                    R = kvp.Value.R, G = kvp.Value.G, B = kvp.Value.B
                }.To <Lab>();
                var diff = labColor.Compare(testColor, comparer);
                if (diff < minDiff)
                {
                    minDiff    = diff;
                    bestChoice = kvp.Key;
                }
            }
            return(bestChoice);
        }
예제 #4
0
        public static bool IsSimilar(this Color @this, Color other, double threshold = SIMILARITY_THRESHOLD_STRICT)
        {
            /*
             * int rDifference = @this.R - other.R;
             * int bDifference = @this.B - other.B;
             * int gDifference = @this.G - other.G;
             *
             * float rDifferencePercent = ( float )rDifference / 255;
             * float gDifferencePercent = ( float )gDifference / 255;
             * float bDifferencePercent = ( float )bDifference / 255;
             *
             * float difference = ((rDifferencePercent + gDifferencePercent + bDifferencePercent) / 3) * 100;
             */

            var thisRgb = new Rgb
            {
                R = ((double)@this.R / 255),
                G = ((double)@this.G / 255),
                B = ((double)@this.B / 255)
            };

            var otherRgb = new Rgb()
            {
                R = (( double )other.R / 255),
                G = (( double )other.G / 255),
                B = (( double )other.B / 255)
            };

            double deltaE = thisRgb.Compare(otherRgb, new Cie1976Comparison());

            return(deltaE >= -threshold && deltaE <= threshold);
        }
예제 #5
0
        /// <summary>
        /// Returns the custom color nearest to the System color input
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public static PColor FindNearestColor(this Color input)
        {
            PColor resultMSColor  = PColor.WebColors.White;
            var    resultDistance = 255.0;

            //Create ColorMine RGB and LAB variables for comparisons
            Rgb inColoRgb = new Rgb {
                R = input.R, G = input.G, B = input.B
            };
            Lab inColorLab = inColoRgb.To <Lab>();

            foreach (var pcolor in PColor.WebColors.All)
            {
                var comparerLabColor = new CieDe2000Comparison();
                var mineColorRgb     = new Rgb {
                    R = pcolor.SystemColor.R, G = pcolor.SystemColor.G, B = pcolor.SystemColor.B
                };
                Lab mineColorLab = mineColorRgb.To <Lab>();

                //Comare colors and check if closer than previous closest
                var currentDistence = inColoRgb.Compare(mineColorLab, comparerLabColor);
                if (currentDistence == 0)
                {
                    resultMSColor = pcolor;
                    break;
                }
                else if (currentDistence < resultDistance)
                {
                    resultMSColor  = pcolor;
                    resultDistance = currentDistence;
                }
            }

            return(resultMSColor);
        }
예제 #6
0
        public static double GetDelta(this Color color1, Color color2)
        {
            var a = new Rgb {
                R = color1.R, G = color1.G, B = color1.B
            };
            var b = new Rgb {
                R = color2.R, G = color2.G, B = color2.B
            };
            var delta = a.Compare(b, new CieDe2000Comparison());

            return(delta);
        }
예제 #7
0
        public static double Compare(this Color color, Color colorCompare, ColorCompareOption option)
        {
            var rgbColor   = new Rgb(color.R, color.G, color.B);
            var rgbCompare = new Rgb(colorCompare.R, colorCompare.G, colorCompare.B);

            switch (option)
            {
            case ColorCompareOption.CIE2000:
                return(rgbColor.Compare(rgbCompare, new CieDe2000Comparison()));

            default:
                DebugUtils.Break();
                return(-1);
            }
        }
예제 #8
0
 string ValidateSiteBackgroundColour()
 {
     if (SiteBackgroundColour == null)
     {
         return(Strings.StudySiteDataModel_Error_NoColour);
     }
     if (AllLocalSites.StudySitesData.Any(s => s.Id != Id && s.SiteBackgroundRgb != null && s.SiteBackgroundRgb.Compare(SiteBackgroundRgb, this.ColourSpacecomparison) < minColourDif))
     {
         return(Strings.GetAppSettingsModel_Error_DuplicateColours);
     }
     if (ErrorColour.Compare(SiteBackgroundRgb, this.ColourSpacecomparison) < minContrastDif)
     {
         return(Strings.StudySiteDataModel_Error_BackgroundAndErrorMatch);
     }
     return(null);
 }
예제 #9
0
        private double CalculateColorDistance(int argb1, int argb2)
        {
            int r1 = (argb1 >> 16) & 255;
            int g1 = (argb1 >> 8) & 255;
            int b1 = argb1 & 255;

            int r2 = (argb2 >> 16) & 255;
            int g2 = (argb2 >> 8) & 255;
            int b2 = argb2 & 255;

            switch (ImageComparisonMethod)
            {
            case ImageComparisonMethod.Euclidean:
            default:

                int cR = r1 - r2;
                int cG = g1 - g2;
                int cB = b1 - b2;

                return(Math.Sqrt(cR * cR + cG * cG + cB * cB));

            case ImageComparisonMethod.Manhattan:

                return(Math.Abs(r2 - r1) + Math.Abs(g2 - g1) + Math.Abs(b2 - b1));

            case ImageComparisonMethod.Improved:

                Rgb LColor1 = new Rgb
                {
                    R = (argb1 >> 16) & 255,
                    G = (argb1 >> 8) & 255,
                    B = argb1 & 255
                };

                Rgb LColor2 = new Rgb
                {
                    R = (argb2 >> 16) & 255,
                    G = (argb2 >> 8) & 255,
                    B = argb2 & 255
                };

                return(LColor1.Compare(LColor2, ColorSpaceComparisonMethod));
            }
        }
예제 #10
0
        public double CompareImages(string voronoiPath, string originalImagePath)
        {
            var deltaEList     = new List <double>();
            var voronoiBitmap  = Image.FromFile(voronoiPath) as Bitmap;
            var originalBitmap = Image.FromFile(originalImagePath) as Bitmap;

            for (var x = 0; x < voronoiBitmap.Width; x++)
            {
                for (var y = 0; y < voronoiBitmap.Height; y++)
                {
                    var voronoiPixelColor = voronoiBitmap.GetPixel(x, y);
                    var voronoiRgb        = new Rgb {
                        R = voronoiPixelColor.R, B = voronoiPixelColor.B, G = voronoiPixelColor.G
                    };
                    var originalPixelColor = originalBitmap.GetPixel(x, y);
                    var originalRgb        = new Rgb {
                        R = originalPixelColor.R, B = originalPixelColor.B, G = originalPixelColor.G
                    };
                    var deltaE = voronoiRgb.Compare(originalRgb, new CieDe2000Comparison());
                    deltaEList.Add(deltaE);
                }
            }
            return(deltaEList.Average());
        }
예제 #11
0
    //public void StartForBucle(Rgb a, Rgb b, uint[] values, Color[] textura1, Color32 tempColor1, List<string> palabras,  System.Action<string> callbackOnFinish)
    //{
    //    StartCoroutine(BucleFor(a, b, values, textura1, tempColor1, palabras, callbackOnFinish));
    //}

    IEnumerator BucleFor(Rgb a, Rgb b, int[] values, Color32[] textura1, Color32 tempColor1, List <string> palabras, TextureHolder textureHold)
    {
        var negro = new Rgb {
            R = 0, G = 0, B = 0
        };

        // int[,] values2 = new int[3, 4];


        for (int i = 0; i < values.Length; i++)
        {
            values[i] = 0;
        }


        for (int i = 0; i < textura1.Length; i++)
        {
            tempColor1 = textura1[i];

            a.R = tempColor1.r;
            a.G = tempColor1.g;
            a.B = tempColor1.b;

            if (i % 10000 == 0)
            {
                // Debug.Log("Esperando...");
                fillAmount.fillAmount = i / (float)textura1.Length;
                //Debug.Log((float)i / textura1.Length * 3);
                yield return(null);
            }

            if ((int)a.Compare(negro, new Cie1976Comparison()) == 0)
            {
                //Debug.Log("Negro");
                continue;
            }



            //for (int k = 0; k < 3; k++)
            //{
            for (int j = 0; j < 3; j++)
            {
                b.R = colores[j].r;
                b.G = colores[j].g;
                b.B = colores[j].b;

                values[j] += (int)a.Compare(b, new Cie1976Comparison());
            }
            //}

            //Debug.Log("Value: " + values[j] + "\nColor " + colores[j]);
        }


        //el valor mas pequeño significa que es más cercano al Color original


        //for (int i = 0; i < values.Length; i++)
        //{
        //    if (values[i] < low)
        //        low = values[i];
        //}

        int low = Mathf.Max(values);

        ////values2[0, 3] = Mathf.Min(values2[0, 0], values2[0, 1], values2[0, 2]);
        ////values2[1, 3] = Mathf.Min(values2[1, 0], values2[1, 1], values2[1, 2]);
        ////values2[2, 3] = Mathf.Min(values2[2, 0], values2[2, 1], values2[2, 2]);

        ////low = Mathf.Min(values2[0, 3], values2[1, 3], values2[2, 3]);
        ////for (int k = 0; k < 3; k++)
        ////{
        ////    if (low == values2[k, 3])
        ////    {
        ////        Debug.Log("<color=yellow>" + k + "</color>" +
        ////        "\nPalabra " + palabras[0] + " Values " + values2[0, 3] + "\t" + values2[1, 0] + "\t" + values2[2, 2] +
        ////        "\nPalabra " + palabras[1] + " Values " + values2[1, 3] + "\t" + values2[1, 0] + "\t" + values2[2, 2] +
        ////        "\nPalabra " + palabras[2] + " Values " + values2[2, 3] + "\t" + values2[1, 0] + "\t" + values2[2, 2]);

        ////        textureHold.palabra = palabras[k];
        ////        break;
        ////    }

        ////}

        //Random.InitState((int)(low*Random.value));

        textureHold.palabra = palabras[Random.Range(0, 3)];

        //for (int i = 0; i < values.Length; i++)
        //{
        //    if (values[i] == low)
        //    {
        //        Debug.Log("<color=yellow>" + i + "</color>" +
        //        "\nPalabra " + palabras[0] + " Values " + values[0] +
        //        "\nPalabra " + palabras[1] + " Values " + values[1] +
        //        "\nPalabra " + palabras[2] + " Values " + values[2]);

        //        textureHold.palabra = palabras[i];
        //        break;
        //        //SetText("a");
        //    }
        //}
    }