[GRASS-user] Fwd: How to obtain selected adjacent pixel values?

Markus Metz markus.metz.giswork at gmail.com
Sun Jun 30 12:10:11 PDT 2013


On Sun, Jun 30, 2013 at 3:31 PM, Nikos Alexandris
<nik at nikosalexandris.net> wrote:
> (cc-ing @MarkusMetz)
>
> Yasser Said Lopez de Olmos Reyes wrote:
>
>> > 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))
>
> Nikos Alexandris wrote:
>> This boils down to calculating
>> (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)
>>
>> Please check the manual of r.mapcalc.  There is
>>
>> --%<---
>> THE NEIGHBORHOOD MODIFIER
> ..
>> --->%--
>
>> which I think can be used to obtain what is asked.
>> So, for each of the off-current pixel, the modifiers would be like
>
>> RASTER_IN_PUSHED_ONE_ROW_UP:  map[-1,0]
>> RASTER_IN_PUSHED_ONE_ROW_DOWN:  map[1,0]
>> RASTER_IN_PUSHED_ONE_COLUMN_LEFT:  map[0,-1]
>> RASTER_IN_PUSHED_ONE_COLUMN_RIGHT:  map[0,1]
>>
>> I am not exactly sure about the implementation though.

r.mapcalc "RASTER_OUT=round(abs((RASTER_IN - RASTER_IN[0,-1]) + \
                                                       (RASTER_IN -
RASTER_IN[0,1]) + \
                                                       (RASTER_IN -
RASTER_IN[-1,0]) + \
                                                       (RASTER_IN -
RASTER_IN[1,0])))"

Note that this is the same like round(abs(4 * RASTER_IN -
(RASTER_IN[0,-1] + RASTER_IN[0,1] + RASTER_IN[-1,0] +
RASTER_IN[1,0])))

If you are interested in the sum of the absolute differences, you will
need to use abs() for each difference.

>
> @Yasser, if you implement this and think it is something that can be justified
> as generically useful, why not ask @MarkusMetz if it is easy to include in
> "r.neighbors" as yet another method?

# prepare a weights file with the contents
0 1 0
1 0 1
0 1 0

r.neighbors in=raster_in out=raster_cardinalsum weight=weights method=sum

r.mapcalc "RASTER_OUT = round(abs(4 * RASTER_IN - raster_cardinalsum))"

HTH,

Markus M


More information about the grass-user mailing list