#integral #2d #sum #2d-array #table #image

summed-area

Implementation of a summed-area table for fast sums or averages of subsections of a 2d array or an image

1 stable release

1.0.0 Sep 19, 2022

#1491 in Math

Download history 175/week @ 2024-07-25 195/week @ 2024-08-01 150/week @ 2024-08-08 88/week @ 2024-08-15 52/week @ 2024-08-22 171/week @ 2024-08-29 139/week @ 2024-09-05 189/week @ 2024-09-12 53/week @ 2024-09-19 144/week @ 2024-09-26 140/week @ 2024-10-03 69/week @ 2024-10-10 115/week @ 2024-10-17 136/week @ 2024-10-24 81/week @ 2024-10-31 113/week @ 2024-11-07

459 downloads per month
Used in mss_saliency

MIT/Apache

12KB
198 lines

Summed Area Table AKA Integral Image

It precomputes sums of all rows and columns in a 2d array for fast O(1) querying of sums of areas within it.

It does this:

let mut sum = 0;
for row in y1..y2 {
    for col in x1..x2 {
        sum += input[col + row * width];
    }
}

but faster:

// precompute
let s = SummedArea::new(input, width);

// now it's fast:
let sum = s.sum_range(x1..x2, y1..y2);

Dependencies

~66KB