Integral images#

Functions#

kornia.enhance.integral_image(image)[source]#

Sum an image cumulatively along its rows and columns.

out = integral_image(image) returns the integral image of image: out[..., i, j] is the sum of image[..., :i + 1, :j + 1].

Convention:

There is no zero row or column in front, unlike cv2.integral, whose result is larger by one row and column.

Parameters:

image (Tensor) – image with shape (*, H, W).

Return type:

Tensor

Returns:

Integral image with shape (*, H, W).

See also

Examples

>>> input = torch.ones(1, 5, 5)
>>> output = integral_image(input)
>>> output
tensor([[[ 1.,  2.,  3.,  4.,  5.],
         [ 2.,  4.,  6.,  8., 10.],
         [ 3.,  6.,  9., 12., 15.],
         [ 4.,  8., 12., 16., 20.],
         [ 5., 10., 15., 20., 25.]]])
kornia.enhance.integral_tensor(input, dim=None)[source]#

Sum a tensor cumulatively along chosen axes.

out = integral_tensor(input, dim) takes the inclusive cumulative sum of input along each axis in dim. For dim=(-2, -1), out[..., i, j] is the sum of input[..., :i + 1, :j + 1].

Convention:
  • dim is a non-empty tuple of unique axes; an int raises TypeError.

  • There is no zero row or column in front, so cv2.integral(x)[1:, 1:] equals the result for the two spatial axes.

Parameters:
  • input (Tensor) – tensor with shape (*, D), one axis or more.

  • dim (Optional[Tuple[int, ...]], optional) – axes to sum along. The default is the last axis. Default: None

Return type:

Tensor

Returns:

Cumulative sums with the shape of input.

See also

Examples

>>> input = torch.ones(3, 5)
>>> output = integral_tensor(input, (-2, -1))
>>> output
tensor([[ 1.,  2.,  3.,  4.,  5.],
        [ 2.,  4.,  6.,  8., 10.],
        [ 3.,  6.,  9., 12., 15.]])

Modules#

class kornia.enhance.IntegralImage(*args, **kwargs)[source]#

Sum an image cumulatively along its rows and columns (module form).

out = IntegralImage()(image) is integral_image().

Convention:
Shape:
  • Input: (*, H, W)

  • Output: same shape as the input.

See also

Examples

>>> input = torch.ones(1, 5, 5)
>>> output = IntegralImage()(input)
>>> output
tensor([[[ 1.,  2.,  3.,  4.,  5.],
         [ 2.,  4.,  6.,  8., 10.],
         [ 3.,  6.,  9., 12., 15.],
         [ 4.,  8., 12., 16., 20.],
         [ 5., 10., 15., 20., 25.]]])
class kornia.enhance.IntegralTensor(dim=None)[source]#

Sum a tensor cumulatively along chosen axes (module form).

op = IntegralTensor(dim) stores dim and out = op(input) is integral_tensor() with it.

Convention:
Parameters:

dim (Optional[Tuple[int, ...]], optional) – axes to sum along. The default is the last axis. Default: None

Shape:
  • Input: (*, D)

  • Output: same shape as the input.

See also

Examples

>>> input = torch.ones(3, 5)
>>> dim = (-2, -1)
>>> output = IntegralTensor(dim)(input)
>>> output
tensor([[ 1.,  2.,  3.,  4.,  5.],
        [ 2.,  4.,  6.,  8., 10.],
        [ 3.,  6.,  9., 12., 15.]])