[GRASS-dev] r.neighbors modification

Hello,

I am looking for a way to compute r.neighbors for a ring only and not for the
whole 5x5, 7x7 etc. moving window.
It is something like a 7x7 windows but minus the values in the 5x5 windows.

traditional way:

a a a a a
a b b b a
a b x b a
a b b b a
a a a a a

ring analysis:

a a a a a
a a
a x a
a a
a a a a a

I think there is no post-r.neighbors way to compute statistics in such
a "ring", hence I or somebody else has to modify the source code. I am
willing to learn some more C programming, but definitely need some help to
get started.

BTW I posted such a wish quite a while ago but for the inactive r.le module
http://www.intevation.de/rt/webrt?serial_num=2104&display=History

regards, Martin

Martin Wegmann wrote:

I am looking for a way to compute r.neighbors for a ring only and not for the
whole 5x5, 7x7 etc. moving window.
It is something like a 7x7 windows but minus the values in the 5x5 windows.

traditional way:

a a a a a
a b b b a
a b x b a
a b b b a
a a a a a

ring analysis:

a a a a a
a a
a x a
a a
a a a a a

r.mfilter ?

Maciek

Martin Wegmann wrote:

BTW I posted such a wish quite a while ago but for the inactive r.le
module
http://www.intevation.de/rt/webrt?serial_num=2104

r.le is not totally "inactive", it has been updated recently to (at least)
be fully functional.

new filters should probably be added to the newly commited r.li however.

Hamish

Martin Wegmann wrote:

I am looking for a way to compute r.neighbors for a ring only and not for the
whole 5x5, 7x7 etc. moving window.
It is something like a 7x7 windows but minus the values in the 5x5 windows.

traditional way:

a a a a a
a b b b a
a b x b a
a b b b a
a a a a a

ring analysis:

a a a a a
a a
a x a
a a
a a a a a

I'm guessing that should be:

a a a a a
a a
a x a
a a
a a a a a

I think there is no post-r.neighbors way to compute statistics in such
a "ring",

It depends upon the aggregate. Some of them could be computed with a
combination of r.neighbors and r.mapcalc commands.

They could all be done using r.mapcalc, but some of them might require
excessively complex expressions (at a minimum, they would all involve
16 map[r,c] terms). r.mapcalc has n-ary min, max, median and mode; sum
and mean are fairly easy to write (you would probably want to process
the nulls separately to simplify the expressions), variance and stddev
aren't hard but would be somewhat more verbose.

Of course, the expressions get longer as the window size increases,
and you would need a separate expression for each size (although you
could probably generate it from a script).

hence I or somebody else has to modify the source code. I am
willing to learn some more C programming, but definitely need some help to
get started.

I'm not sure it's worth modifying r.neighbors for this specific case
(it might be worth you modifying your version, but not us shipping a
modified version). More generally useful would be to allow the
neighbourhood set to be read from a file, similar to r.mfilter (or
even just have a list of offsets as an optional argument).

--
Glynn Clements <glynn@gclements.plus.com>

On Tuesday 14 November 2006 17:42, Maciej Sieczka wrote:

Martin Wegmann wrote:
> I am looking for a way to compute r.neighbors for a ring only and not
> for the whole 5x5, 7x7 etc. moving window.
> It is something like a 7x7 windows but minus the values in the 5x5
> windows.
>
> traditional way:
>
> a a a a a
> a b b b a
> a b x b a
> a b b b a
> a a a a a
>
> ring analysis:
>
> a a a a a
> a a
> a x a
> a a
> a a a a a

r.mfilter ?

that looks good, but as far as I understood it, it is not possible to conduct
statistics on this filter (beside divisor), is it?

Martin

Maciek

_______________________________________________
grass-dev mailing list
grass-dev@grass.itc.it
http://grass.itc.it/mailman/listinfo/grass-dev

Martin Wegmann wrote:

> > I am looking for a way to compute r.neighbors for a ring only and not
> > for the whole 5x5, 7x7 etc. moving window.
> > It is something like a 7x7 windows but minus the values in the 5x5
> > windows.
> >
> > traditional way:
> >
> > a a a a a
> > a b b b a
> > a b x b a
> > a b b b a
> > a a a a a
> >
> > ring analysis:
> >
> > a a a a a
> > a a
> > a x a
> > a a
> > a a a a a
>
> r.mfilter ?

that looks good, but as far as I understood it, it is not possible to conduct
statistics on this filter (beside divisor), is it?

I don't think that you can compute anything except for sum and mean
using r.mfilter.

--
Glynn Clements <glynn@gclements.plus.com>

Glynn Clements wrote:

> > r.mfilter ?
>
> that looks good, but as far as I understood it, it is not possible
> to conduct statistics on this filter (beside divisor), is it?

I don't think that you can compute anything except for sum and mean
using r.mfilter.

is this an inherent limitation of the method, or has it just not been
coded yet?

it would be nice to have a powerful r.mfilter (not as grand as
r.mapcalc, but more customizable than just sum+mean.

Hamish

Hamish wrote:

> > > r.mfilter ?
> >
> > that looks good, but as far as I understood it, it is not possible
> > to conduct statistics on this filter (beside divisor), is it?
>
> I don't think that you can compute anything except for sum and mean
> using r.mfilter.

By "anything", I mean that these are the only "standard" aggregates
(those offered by r.neighbors) which can be computed.

is this an inherent limitation of the method, or has it just not been
coded yet?

The former. The result is just a weighted sum of the cells in the
window, so you are limited to linear functions.

An all-ones matrix with a divisor of one gives the sum, while an
all-ones matrix with a divisor equal to the number of ones gives the
mean.

All of the other standard aggregates have some kind of non-linearity.

Variance and standard deviation can be implemented using two passes of
each of r.mfilter and r.mapcalc, e.g.:

  r.mfilter input=foo output=foo.sum filter=sum.txt
  r.mapcalc "foo.sq = foo^2"
  r.mfilter input=foo.sq output=foo.sumsq filter=sum.txt
  r.mapcalc "foo.var = (foo.sumsq - foo.sum^2/$N)/$N ; foo.sdev = sqrt(foo.var)"

it would be nice to have a powerful r.mfilter (not as grand as
r.mapcalc, but more customizable than just sum+mean.

There isn't really any "obvious" intermediate level between the linear
filters which are already available in r.mfilter and the arbitrary
expressions offered by r.mapcalc.

E.g. I can't think of any enhancement which would allow you to
implement median/minimum/maximum filters.

--
Glynn Clements <glynn@gclements.plus.com>