public double Calculate(Region region)
        {
            Point center = centerOfMass.Calculate(region);

            return(region.Infos.Select(pixel =>
                                       Math.Pow(pixel.Coords.X - center.X, i) * Math.Pow(pixel.Coords.Y - center.Y, j))
                   .Sum());
        }
Exemple #2
0
        public Point Calculate(Region region)
        {
            int square = region.Infos.Count;

            int coordsSumByX = region.Infos.Sum(e => e.Coords.X);
            int coordsSumByY = region.Infos.Sum(e => e.Coords.Y);

            int centerX = coordsSumByX / square;
            int centerY = coordsSumByY / square;

            return(new Point(centerX, centerY));
        }
Exemple #3
0
        public double Calculate(Region region)
        {
            IEnumerable <int> averageColor = region.Infos.Select(e => new
            {
                source.GetPixel(e.Coords.X, e.Coords.Y).R,
                source.GetPixel(e.Coords.X, e.Coords.Y).G,
                source.GetPixel(e.Coords.X, e.Coords.Y).B
            }).Aggregate(new[] { 0, 0, 0 }, (tuple, element) =>
            {
                tuple[0] += element.R;
                tuple[1] += element.G;
                tuple[2] += element.B;
                return(tuple);
            }).Select(e => e / region.Infos.Count);

            return(averageColor.Average());
        }