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 ofimage:out[..., i, j]is the sum ofimage[..., :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:
- Returns:
Integral image with shape
(*, H, W).
See also
integral_tensor(): sums along any axes.IntegralImage: the module form.
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 ofinputalong each axis indim. Fordim=(-2, -1),out[..., i, j]is the sum ofinput[..., :i + 1, :j + 1].- Convention:
dimis a non-empty tuple of unique axes; anintraisesTypeError.There is no zero row or column in front, so
cv2.integral(x)[1:, 1:]equals the result for the two spatial axes.
- Parameters:
- Return type:
- Returns:
Cumulative sums with the shape of
input.
See also
integral_image(): sums the two spatial axes.IntegralTensor: the module form.
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)isintegral_image().- Convention:
See the convention block of
integral_image().
- Shape:
Input:
(*, H, W)Output: same shape as the input.
See also
integral_image(): the one-call form.IntegralTensor: sums along any axes.
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)storesdimandout = op(input)isintegral_tensor()with it.- Convention:
See the convention block of
integral_tensor().
- 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
integral_tensor(): the one-call form.IntegralImage: sums the two spatial axes.
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.]])