Sum() public static method

Computes the sum of the pixels in a given image.
public static Sum ( this image ) : int
image this
return int
Example #1
0
        public void SumTest2()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Resources.image2);

            int expected = 0;

            for (int i = 3; i < 9; i++)
            {
                for (int j = 2; j < 10; j++)
                {
                    expected += image.GetPixel(i, j).R;
                }
            }

            int actual = (int)Tools.Sum(image, new Rectangle(3, 2, 9 - 3, 10 - 2));

            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void SumTest()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Resources.image1);

            int expected = 0;

            for (int i = 0; i < 16; i++)
            {
                for (int j = 0; j < 16; j++)
                {
                    expected += image.GetPixel(i, j).R;
                }
            }

            int actual = (int)Tools.Sum(image);

            Assert.AreEqual(expected, actual);
        }
Example #3
0
        public void SumTest1()
        {
            Bitmap image = Accord.Imaging.Image.Clone(Resources.image2);

            int expected = 0;

            for (int i = 3; i < 9; i++)
            {
                for (int j = 2; j < 10; j++)
                {
                    expected += image.GetPixel(i, j).R;
                }
            }


            BitmapData data = image.LockBits(new Rectangle(System.Drawing.Point.Empty, image.Size),
                                             ImageLockMode.ReadOnly, image.PixelFormat);

            int actual = Tools.Sum(data, new Rectangle(3, 2, 9 - 3, 10 - 2));

            Assert.AreEqual(expected, actual);

            image.UnlockBits(data);
        }