# [OSGeo-Discuss] How to obtain selected adjacent pixel values?

Yasser Said Lopez de Olmos Reyes biolyasser at gmail.com
Wed Jun 26 17:25:22 PDT 2013

```Hello all, this is my first time using a subscriber list and I have some

I have an AML script (old arcinfo srcipt) that uses focal operations that
I've sorted out well using r.neighbors but I have a problem in certain part
of the script to follow in grass GIS. In some part of the script the author
declares a variable as a grid called "cbd" and codes as follows:

*%cb%d = int(abs((%cb% - %cb%(1,0)) + (%cb% - %cb%(0,1)) + (%cb% -
%cb%(0,-1)) + (%cb% - %cb%(-1,0))))*

>From where he obtains a grid filled with integer positive values from 0 to
4. All these values come from a binary grid (0 or 1 values) declared as
"cb" where I believe* (%cb% - %cb%(1,0)) *means something like "central
pixel value minus pixel value at west from central pixel value" and *(%cb%
- %cb%(0,1)) *means something like "central pixel value minus pixel value
at north from central pixel value", and so on...

How could I obtain the differences between central pixel values and
cardinal directions pixel values related with a central pixel?

Or in a different manner, how to do this in grass gis?

RASTER_OUT= round(abs((RASTER_IN - RASTER_IN_PUSHED_ONE_ROW_UP) +
(RASTER_IN - RASTER_IN_PUSHED_ONE_ROW_DOWN) + (RASTER_IN -
RASTER_IN_PUSHED_ONE_COLUMN_LEFT) + (RASTER_IN -
RASTER_IN_PUSHED_ONE_COLUMN_RIGHT))