machinevisiontoolbox.Image.sum

Image.sum(*args, **kwargs)[source]

Sum of all pixels

Parameters:
  • args – additional positional arguments to numpy.sum

  • kwargs – additional keyword arguments to numpy.sum

Returns:

sum

Computes the sum of pixels in the image:

\[\sum_{uvc} I_{uvc}\]

Example:

>>> from machinevisiontoolbox import Image
>>> img = Image.Read('flowers1.png')
>>> img.sum()  # R+G+B
86260474
>>> img.sum(axis=(0,1)) # sum(R), sum(G), sum(B)
array([28267315, 30542247, 27450912], dtype=uint64)
>>> img = Image.Read('flowers1.png', dtype='float32')
>>> img.sum(axis=2)
array([[0.6275, 0.6196, 0.851 , ..., 2.5412, 2.5569, 2.8471],
       [0.6078, 0.6275, 0.8588, ..., 2.6431, 2.7451, 2.9961],
       [0.6118, 0.6196, 0.8157, ..., 2.3608, 2.9098, 2.9843],
       ...,
       [1.0784, 0.8784, 0.8353, ..., 1.098 , 1.1216, 1.1725],
       [1.0314, 0.851 , 0.7412, ..., 1.0706, 1.0902, 1.1412],
       [0.9647, 0.8039, 0.7059, ..., 1.0157, 1.0588, 1.1059]],
      dtype=float32)
Note:
  • The return value type is the same as the image type.

  • By default the result is a scalar computed over all pixels, if the axis option is given the results is a 1D or 2D NumPy array.

Seealso:

numpy.sum mpq npq upq