コード例 #1
0
    public void CompareTexturesToColor()
    {
        // get chosen color to to compare
        globalColorToCompare = colorDisk.pointer.GetComponentInChildren <Image>().color;

        // methods library
        ColorLibrary library = new ColorLibrary();

        // array of difference
        float[] differenceIntensity = new float[allImages.image.Length];

        // compare all images according to HSV method
        for (int i = 0; i < allImages.image.Length; i++)
        {
            float     totalDifference    = 0;
            Color32[] histogramOfTexture = histogramGenerator.CreateHistogram(allImages.image[i]);

            for (int c = 0; c < histogramOfTexture.Length; c++)
            {
                totalDifference += (histogramOfTexture.Length - c) *
                                   library.DifferenceValueLAB(globalColorToCompare, histogramOfTexture[c]);
            }

            totalDifference       /= histogramOfTexture.Length * (histogramOfTexture.Length + 1) / 2;
            differenceIntensity[i] = totalDifference;
        }

        Array.Sort(differenceIntensity, allImages.image);
    }
コード例 #2
0
        public void GetHistogram()
        {
            // step 1
            string sample = "oh who lives in a pineapple under the sea spongebob square pants";

            string[] bigrams = histogramGenerator.FindBigrams(sample);
            // step 2
            Dictionary <string, int> histogram = histogramGenerator.CreateHistogram(bigrams);

            Assert.Equal(11, histogram.Count);
            Assert.True(histogram.ContainsKey("pineapple under"));
        }
コード例 #3
0
    private void ColorBar(Texture2D texture)
    {
        Color32[] colorOfTexture     = histogram.CreateHistogram(texture);
        int[]     frequencyOfTexture = histogram.frequencyOfColors;

        float n = 1;

        for (int i = 0; i < colorOfTexture.Length; i++)
        {
            colorOfTexture[i].a = 255;

            for (int j = 0; j < frequencyOfTexture[i]; j++)
            {
                n++;
                GameObject newColor = Instantiate(image, colorBar.transform);
                newColor.GetComponent <Image>().color = colorOfTexture[i];
            }

            colorBar.GetComponent <GridLayoutGroup>().cellSize = new Vector2(408 / n, 100);
        }
    }