Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Summed Area Table / Integral Image

  • To: mathgroup at smc.vnet.net
  • Subject: [mg115408] Re: Summed Area Table / Integral Image
  • From: DrMajorBob <btreat1 at austin.rr.com>
  • Date: Mon, 10 Jan 2011 02:38:47 -0500 (EST)

This creates the table of sums for a simple example:

{d1, d2} = {5, 6};
i = RandomInteger[{1, 10}, {d1, d2}]

{{5, 6, 8, 6, 2, 8}, {7, 8, 10, 8, 1, 3}, {10, 3, 8, 6, 3, 3}, {7, 1,
   5, 10, 5, 1}, {5, 9, 10, 5, 2, 4}}

Clear[sum]
sum[0, _] = 0;
sum[_, 0] = 0;
sum[x_, y_] :=
  sum[x, y] =
   i[[x, y]] + sum[x - 1, y] + sum[x, y - 1] - sum[x - 1, y - 1]
Table[sum[x, y], {x, d1}, {y, d2}]

{{5, 11, 19, 25, 27, 35}, {12, 26, 44, 58, 61, 72}, {22, 39, 65, 85,
   91, 105}, {29, 47, 78, 108, 119, 134}, {34, 61, 102, 137, 150, 169}}

To create the table without displaying it, replace Table with Do:

{d1, d2} = {2, 4};
i = RandomInteger[{1, 10}, {d1, d2}]

{{2, 7, 9, 9}, {1, 2, 10, 9}}

Clear[sum]
sum[0, _] = 0;
sum[_, 0] = 0;
sum[x_, y_] :=
  sum[x, y] =
   i[[x, y]] + sum[x - 1, y] + sum[x, y - 1] - sum[x - 1, y - 1]
Do[sum[x, y], {x, d1}, {y, d2}]

?? sum

Global`sum

sum[1,1]=2

sum[1,2]=9

sum[1,3]=18

sum[1,4]=27

sum[2,1]=3

sum[2,2]=12

sum[2,3]=31

sum[2,4]=49

sum[0,_]=0

sum[_,0]=0

sum[x_,y_]:=sum[x,y]=i[[x,y]]+sum[x-1,y]+sum[x,y-1]-sum[x-1,y-1]

Bobby

On Sun, 09 Jan 2011 01:18:31 -0600, Gareth Edwards  
<gareth.edwards at cubicmotion.com> wrote:

> Next newbie question....
>
> Suppose I have a 2D matrix, what would be a neat syntax for computed the
> 'Integral Image' or summed area table? (
> http://en.wikipedia.org/wiki/Summed_area_table )
>
> Many thanks in advance for any neat suggestions.
>
> Best,
>
> Gareth
>


-- 
DrMajorBob at yahoo.com


  • Prev by Date: Re: Solve can solve it with some help
  • Next by Date: Re: how to remove $RecursionLimit::reclim: and $IterationLimit::itlim:
  • Previous by thread: Re: Summed Area Table / Integral Image
  • Next by thread: Mathematica how to call and run hspice program which is a EDA software