Example #1
0
        public int matchColor(Color color, List <IBlock> blocks)
        {
            int    length = blocks.Count;
            double min    = double.PositiveInfinity;

            IPointMath3D colorPrecise = new PointMath3D(color);

            // TODO: parallel, separate work to multiple threads, then collect minimum and compare
            // with final thread

            int save = 0;

            for (int i = 0; i < length; i++)
            {
                float local = colorPrecise.distanceSquared(blocks[i].Stats.getMean());

                if (min > local)
                {
                    min  = local;
                    save = i;
                }

                //Console.Out.WriteLine(blocks[i].Name + " at distance of " + local);
            }

            return(save);
        }
Example #2
0
        public float getVariance()
        {
            uint   count           = 0;
            double distanceSquared = 0;

            // TODO: bool variable that checks if mean computed

            getMean();

            // TODO: parallel with atomic add

            Color[][] mat = cache;

            foreach (Color[] row in mat)
            {
                foreach (Color pixel in row)
                {
                    distanceSquared += new PointMath3D(pixel).distanceSquared(cachedMean);
                    ++count;
                }
            }

            return(cachedVariance = (float)(distanceSquared / count));
        }