#2d #table #integral #sum #2d-array #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

#1655 in Math

Download history 74/week @ 2024-10-27 98/week @ 2024-11-03 104/week @ 2024-11-10 105/week @ 2024-11-17 191/week @ 2024-11-24 41/week @ 2024-12-01 169/week @ 2024-12-08 59/week @ 2024-12-15 1/week @ 2024-12-22 40/week @ 2024-12-29 74/week @ 2025-01-05 241/week @ 2025-01-12 116/week @ 2025-01-19 122/week @ 2025-01-26 182/week @ 2025-02-02 131/week @ 2025-02-09

551 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