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

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

#1289 in Math

Download history 31/week @ 2024-03-26 80/week @ 2024-04-02 81/week @ 2024-04-09 28/week @ 2024-04-16 23/week @ 2024-04-23 30/week @ 2024-04-30 104/week @ 2024-05-07 148/week @ 2024-05-14 128/week @ 2024-05-21 85/week @ 2024-05-28 55/week @ 2024-06-04 48/week @ 2024-06-11 65/week @ 2024-06-18 67/week @ 2024-06-25 63/week @ 2024-07-02 67/week @ 2024-07-09

266 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

~62KB