Accord.Imaging.Tools.Sum C# (CSharp) Method

Sum() public static method

Computes the sum of the pixels in a given image.
public static Sum ( this image ) : int
image this
return int
        public static int Sum(this Bitmap image)
        {
            BitmapData data = image.LockBits(new Rectangle(0, 0, image.Width, image.Height),
                ImageLockMode.ReadOnly, image.PixelFormat);

            int sum = Sum(data);

            image.UnlockBits(data);

            return sum;
        }

Same methods

Tools::Sum ( this image, Rectangle rectangle ) : int
Tools::Sum ( this image, Rectangle rectangle ) : long

Usage 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);
        }
All Usage Examples Of Accord.Imaging.Tools::Sum