[GRASS-user] circular neighborhoods?

Tom Russo russo at bogodyn.org
Thu Feb 21 13:52:16 EST 2008


On Thu, Feb 21, 2008 at 03:11:43PM -0300, we recorded a bogon-computron collision of the <carlos.grohmann at gmail.com> flavor, containing:
> Yes, Eric, that is what it does for a _square_ neighborhood. I am a
> little confuse about the actual shape of the _circular_ neighborhood.
> 
> using your examples:
> 
> will a 3x3 circular neighborhood look like this:?
> 
> ---o---
> o-X-o
> ---o---
> 
> and a 5x5?
> 
> ---o-o-o---
> o-o-o-o-o
> o-o-X-o-o
> o-o-o-o-o
> ---o-o-o---
> 
> 
> maybe now my question is more clear...

Piping in here after a quick glance at the source code...

When the "-c" option to r.neighbors is selected, a neighborhood mask of booleans
is created by this loop (in pseudocode):

  neighborhoodDistance=neighborhoodSize/2 (in integer math)
  for (i=0; i<neigborhoodSize; i++)
    for (j=0; j<neighborhoodSize; j++)
       mask[i][k]= ( (i-neighborhoodDistance)^2 + (j-neighborhoodDistance)^2 <= (neighborhoodDistance)^2

So in a 3x3 example, neighborhoodSize=3, neighborhoodDistance=1, and your
first diagram has "o"s where the mask is true.  The corners of the square
wouldn't be in the mask (as in Eric's 3x3), because those points would have 
the left hand side of the inequality equal to 2, making the mask false.

I haven't actually *tried* the code, but that is what the block of code in
gather.c for circular neighborhoods says it should be doing.

> > >I was thinking about the circular neighborhoods that r.neighbors use.
> >  >How exactly are they shaped? I mean, in a 3x3 window, does the
> >  >circular one looks like a cross? and then it start to look more like a
> >  >circle as the size increases?
> >
> >  As far as I understand it,
> >
> >  A 3x3 window would look like this:
> >
> >  o-o-o
> >  o-X-o
> >  o-o-o
> >
> >  Where the 'X' is the current cell being processed. Similarly, a 5X5 window
> >  would look like this:
> >
> >  o-o-o-o-o
> >  o-o-o-o-o
> >  o-o-X-o-o
> >  o-o-o-o-o
> >  o-o-o-o-o
> >
> >  r.neighbors will perform calculations on all the cells I've marked 'o' and and
> >  assign the output value to 'X', according to whatever method has been chosen
> >  (i.e., average, median, min, max, etc.).
> >
> >  ~ Eric.
> >
> 
> 
> 
> -- 
> +-----------------------------------------------------------+
>  Carlos Henrique Grohmann - Guano
>  Geologist M.Sc - Doctorate Student at IGc-USP - Brazil
> Linux User #89721 - carlos dot grohmann at gmail dot com
> +-----------------------------------------------------------+
> _________________
> "Good morning, doctors. I have taken the liberty of removing Windows
> 95 from my hard drive."
> --The winning entry in a "What were HAL's first words" contest judged
> by 2001: A SPACE ODYSSEY creator Arthur C. Clarke
> 
> Can't stop the signal.
> _______________________________________________
> grass-user mailing list
> grass-user at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/grass-user

-- 
Tom Russo    KM5VY   SAR502   DM64ux          http://www.swcp.com/~russo/
Tijeras, NM  QRPL#1592 K2#398  SOC#236 AHTB#1 http://kevan.org/brain.cgi?DDTNM
"And, isn't sanity really just a one-trick pony anyway? I mean all you get is
 one trick, rational thinking, but when you're good and crazy, oooh, oooh,
 oooh, the sky is the limit!"  --- The Tick


More information about the grass-user mailing list