MathGroup Archive 2001

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

Search the Archive

Re: Re: ListCorrelate[] ??

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30208] Re: [mg30182] Re: ListCorrelate[] ??
  • From: Brent Pedersen <bpederse at nature.berkeley.edu>
  • Date: Thu, 2 Aug 2001 03:16:02 -0400 (EDT)
  • References: <9jtkeq$894$1@smc.vnet.net> <200108010619.CAA03979@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Mariusz Jankowski wrote:

> Brent,
> "Brent Pedersen" <bpederse at nature.berkeley.edu> wrote in message
> news:9jtkeq$894$1 at smc.vnet.net...
> > with a real square matrix H, I calculate the sum of each cell and its 8
> > neighbors as:
> > Htot=ListCorrelate[kern, H ,{2,-2}];     (thanks to the help of some of
> > you)
> > where:
> > kern = Table[1, {3}, {3}];
> >
>
> You probably should use Htot=ListCorrelate[kern, H ,{2, 2}]. For a 3x3
> kernel
> ListCorrelate[kern,H,{2,-2}] == ListCorrelate[kern,H,{2,2}], but this is not
> true for larger kernels.
>
> > now, for each 9 cell neighborhood around (and including cell H[[i,j]], I
> > wish to calculate:
> > Sum[(H[[m,n]]/Htot[[i,j]])^c,{m,i-1,i+1},{n,j-1,j+1}];
> > (when c=1, this will be 1.)
> > of course, this code won't work as is but the idea is there.I can write
> > loops containing a Sum[] similar to that above,but i am sure that
> > ListCorrelate[] operates much faster (which is important since H is
> > 256*256).in short, i need to output a 256*256 matrix where each cell
> > contains the result of the Sum[] function above.
> >
> > ListCorrelate[kern, H/Htot,{2,-2}]; does not work because it contains
> > H[[i,j]]/Htot[[i,j]]  not H[[i,j]]/Htot[[m,n]];
> >
>
> Right, correlation will not return the same result, but here is a reasonable
> solution:
>
> Table[(Tr[Flatten[(#1/Tr[Flatten[#1]] )^c]] & )[ H[[{i - 1, i, i + 1},{j -
> 1, j, j + 1}]] ],
>   {i, 2, 255}, {j, 2, 255}]
>
> or
>
> Htot=ListCorrelate[kern,H,{2,2}];
>
> Table[(Tr[Flatten[(#1/Htot[[i,j]])^c]] & )[ H[[{i - 1, i, i + 1},{j - 1, j,
> j + 1}]] ],
>   {i, 2, 255}, {j, 2, 255}]
>
> where Tr[Flatten[...]] is just a fast way to calculate Sum. The second
> solution may be faster since you are precomputing the averages. If you
> REALLY need to have a 256x256 result, then you should pad the original data
> prior to the calculations shown above and change the iterators in Table to
> 1,256
>
> A question. The calculation you desire is a form of edge
> enhancement/detection. The calculation using two subsequent ListCorrelates
> which you rejected also enhances edges. Why is one better than the other?
>
> Mariusz
>

thanks,
i had not tried Tr[Flatten[...]] for quick summation.
but, now i am confused about the 3rd argument in ListCorrelate[]...
first to answer your question. yes, this is similar to edge enhancement
for DIP but, i am using it to simulate dispersal of populations where
each entry of the matrix is a population density and ListCorrelate[] simulates
dispersal.
  i assume (to avoid a loss of individuals at the edge of the lattice)
periodic boundaries such that the surface essentially becomes a torus
(or a donut as noted by Daniel Licthblau).
so, i have been using   ListCorrelate[kern,matrix, {n,-n}]
where n is the maximum dispersal radius +1
because this allows the kernel to "hang" over the edge of the population
lattice by n on all sides. then, for the case where i wish
to have "absorbing boundaries" where individuals can move off
the matrix i use:
ListCorrelate[kern,matrix, {n,-n},0]
assuming that the automatic  padding is at least n zeros on all sides.
is this correct for my purposes?
and another question, how would one create "reflecting boundaries" where
individuals that would normally leave the edge of the matrix, instead
remain on the edge?



  • Prev by Date: Re: Re: ListCorrelate[] ??
  • Next by Date: Re: latex and Mathematica, problems
  • Previous by thread: Re: Re: ListCorrelate[] ??
  • Next by thread: Re: Any quantum chemists / physicists?