Skip to content

Commit

Permalink
Summed Area Table barryclark#6
Browse files Browse the repository at this point in the history
  • Loading branch information
kilinco authored Sep 11, 2021
1 parent af59c54 commit 5acf272
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions _posts/2021-09-13-summed-area-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ class SummedAreaTable {
}

int get_submatrix_sum(int x_low, int y_low, int x_high, int y_high) const;
int get_submatrix_mean(int x_low, int y_low, int x_high, int y_high) const;
private:
int get_num_elements(int x_low, int y_low, int x_high, int y_high) const;
double get_submatrix_mean(int x_low, int y_low, int x_high, int y_high) const;
private:
std::vector<std::vector<int>> dp;
}

int SummedAreaTable::get_submatrix_sum(int x_low, int y_low, int x_high, int y_high) const {
return dp[x_high+1][y_high+1] - dp[x_high+1][y_low] - dp[x_low][y_high+1] + dp[x_low][y_low];
}

int SummedAreaTable::get_submatrix_mean(int x_low, int y_low, int x_high, int y_high) const {
return (double) get_submatrix_sum(x_low, y_low, x_high, y_high) / get_num_elements(x_low, y_low, x_high, y_high);
}

int SummedAreaTable::get_num_elements(int x_low, int y_low, int x_high, int y_high) const {
return (x_high - x_low + 1) * (y_high - y_low + 1);
}

double SummedAreaTable::get_submatrix_mean(int x_low, int y_low, int x_high, int y_high) const {
return std::static_cast<double>(get_submatrix_sum(x_low, y_low, x_high, y_high)) / get_num_elements(x_low, y_low, x_high, y_high);
}
{% endhighlight %}

Lastly, you can find the much better illustrated solution [here](https://nayan.co/blog/AI/Integral-Image/).
Expand Down

0 comments on commit 5acf272

Please sign in to comment.