[GRASS-user] identifying diagonal clumps

Dear all,

I am using r.cluster to identify the clumps of pixels of my binary map (0=matrix and 1=habitat).
But when I run r.cluster, I get and output cluster map as (B) (see below) and in fact
I would like the those diaagonal patches were clumped as the same clump.
Almost to those that work with landscape ecology, the patches are formed
using rules with 8 neighbors intead of 4 neighbors.

I know that I can do it on other programs, but I need to implement a sequence of
codes on GRASS, and I really need a rule-8 to build my patches map. Any idea?

Best wishes,

miltinho astronauta
brazil

(A)

00000000
01000000
00110000
00110000
00001100
00001100
00001100
00000000
(B)
00000000
01000000
00220000
00220000
00003300
00003300
00001100
00000000

I used to implement an r.mapcalc script by evaluating values in the
cardinal directions

sample below:
## pixels with both forest from the cardinal directions
# 0--x--0
# | | |
# x--x--x
# | | |
# 0--x--0

r.mapcalc "F4 = (A * A [1,0]) * (A * A [-1,0]) * (A * A [0,-1]) * (A * A [0,1])"

where [r,c] refers to the current cell offset

for an 8-rule you can use

[-1,-1],[-1,0],[1,-1],[0,-1],[0,1],[-1,1],[1,-1],-1,1]

hope that helps.

cheers,
maning

On 9/15/08, Milton Cezar Ribeiro <miltinho.astronauta@gmail.com> wrote:

Dear all,
I am using r.cluster to identify the clumps of pixels of my binary map
(0=matrix and 1=habitat).
But when I run r.cluster, I get and output cluster map as (B) (see below)
and in fact
I would like the those diaagonal patches were clumped as the same clump.
Almost to those that work with landscape ecology, the patches are formed
using rules with 8 neighbors intead of 4 neighbors.

I know that I can do it on other programs, but I need to implement a
sequence of
codes on GRASS, and I really need a rule-8 to build my patches map. Any
idea?

Best wishes,

miltinho astronauta
brazil

(A)
00000000
01000000
00110000
00110000
00001100
00001100
00001100
00000000
(B)
00000000
01000000
00220000
00220000
00003300
00003300
00001100
00000000

--
|---------|----------------------------------------------------------|
| __.-._ |"Ohhh. Great warrior. Wars not make one great." -Yoda |
| '-._"7' |"Freedom is still the most radical idea of all" -N.Branden|
| /'.-c |Linux registered user #402901, http://counter.li.org/ |
| | /T |http://esambale.wikispaces.com|
| _)_/LI
|---------|----------------------------------------------------------|

Dear Maning,

Many thanks for your kindly attention.

I tryed your suggestion and notice that the F8 solution
simulate a dilatation of 1pixels on everyside of patches.
But, if I am not wrong, when I have a patch separated by
2 pixels, the F8 solution will join these patches on only one.

But I can preserve the patches separated, and only
consider as one patches those pixels that can be joined
on the rule 8. I don´t know if I am so clear, but I would
like to request a little more time of you on this regard.

I run the folowwing commands:

r.mapcalc “F8 = (AA[-1,-1]) * (AA[-1,0]) * (AA[1,-1]) * (AA[0,-1]) * (AA[0,1]) * (AA[-1,1]) * (A*A[1,1])”
r.clump input=F8 output=F8_clump

Best wishes,

miltinho

2008/9/14 maning sambale <emmanuel.sambale@gmail.com>

I used to implement an r.mapcalc script by evaluating values in the
cardinal directions

sample below:

pixels with both forest from the cardinal directions

0–x–0

| | |

x–x–x

| | |

0–x–0

r.mapcalc “F4 = (A * A [1,0]) * (A * A [-1,0]) * (A * A [0,-1]) * (A * A [0,1])”

where [r,c] refers to the current cell offset

for an 8-rule you can use

[-1,-1],[-1,0],[1,-1],[0,-1],[0,1],[-1,1],[1,-1],-1,1]

hope that helps.

cheers,
maning

On 9/15/08, Milton Cezar Ribeiro <miltinho.astronauta@gmail.com> wrote:

Dear all,
I am using r.cluster to identify the clumps of pixels of my binary map
(0=matrix and 1=habitat).
But when I run r.cluster, I get and output cluster map as (B) (see below)
and in fact
I would like the those diaagonal patches were clumped as the same clump.
Almost to those that work with landscape ecology, the patches are formed
using rules with 8 neighbors intead of 4 neighbors.

I know that I can do it on other programs, but I need to implement a
sequence of
codes on GRASS, and I really need a rule-8 to build my patches map. Any
idea?

Best wishes,

miltinho astronauta
brazil

(A)
00000000
01000000
00110000
00110000
00001100
00001100
00001100
00000000
(B)
00000000
01000000
00220000
00220000
00003300
00003300
00001100
00000000


|---------|----------------------------------------------------------|
| _.-. |“Ohhh. Great warrior. Wars not make one great.” -Yoda |
| ‘-._"7’ |“Freedom is still the most radical idea of all” -N.Branden|
| /'.-c |Linux registered user #402901, http://counter.li.org/ |
| | /T |http://esambale.wikispaces.com|
| )/LI
|---------|----------------------------------------------------------|

Milton Cezar Ribeiro wrote:

I tryed your suggestion and notice that the F8 solution
simulate a dilatation of 1pixels on everyside of patches.
But, if I am not wrong, when I have a patch separated by
2 pixels, the F8 solution will join these patches on only one.

But I can preserve the patches separated, and only
consider as one patches those pixels that can be joined
on the rule 8. I don´t know if I am so clear, but I would
like to request a little more time of you on this regard.

I run the folowwing commands:

r.mapcalc "F8 = (A*A[-1,-1]) * (A*A[-1,0]) * (A*A[1,-1]) * (A*A[0,-1]) * (A*A[0,1]) * (A*A[-1,1]) * (A*A[1,1])"
r.clump input=F8 output=F8_clump

The r.mapcalc command will perform "thinning". The result will be one
if all nine cells (the centre and all eight surrounding cells) are
one, and zero if any of the nine cells are zero).

[Actually, you're missing A[1,0].]

For "fattening", you should use e.g.:

r.mapcalc "F8 = A[-1,-1] || A[-1,0] || A[-1,1] || A[0,-1] || A || A[0,1] || A[1,-1] || A[1,0] || A[1,1]"

[For 0/1, multiplication is equivalent to the "&&" operator (logical
conjunction).]

Another option, which should only fill in the cells necessary to make
r.clump recognise diagonal adjacency, is:

r.mapcalc "AF = A || A[0,1] && A[1,0] || A[0,-1] && A[1,0] || A[0,1] && A[-1,0] || A[0,-1] && A[-1,0]"

This will only set the centre cell if two diagonally-adjacent
neighbours are both set.

It may even suffice to use:

r.mapcalc "AF = A || A[0,1] && A[1,0] || A[0,-1] && A[1,0]"

This will only fill the cell on one side of a pair of diagonally
adjacent cells.

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

Dear Glynn and Manning

Your tips solved my problem.

Many thanks for both.

Best wishes

miltinho

2008/9/15 Glynn Clements <glynn@gclements.plus.com>

Milton Cezar Ribeiro wrote:

I tryed your suggestion and notice that the F8 solution
simulate a dilatation of 1pixels on everyside of patches.
But, if I am not wrong, when I have a patch separated by
2 pixels, the F8 solution will join these patches on only one.

But I can preserve the patches separated, and only
consider as one patches those pixels that can be joined
on the rule 8. I don´t know if I am so clear, but I would
like to request a little more time of you on this regard.

I run the folowwing commands:

r.mapcalc “F8 = (AA[-1,-1]) * (AA[-1,0]) * (AA[1,-1]) * (AA[0,-1]) * (AA[0,1]) * (AA[-1,1]) * (A*A[1,1])”
r.clump input=F8 output=F8_clump

The r.mapcalc command will perform “thinning”. The result will be one
if all nine cells (the centre and all eight surrounding cells) are
one, and zero if any of the nine cells are zero).

[Actually, you’re missing A[1,0].]

For “fattening”, you should use e.g.:

r.mapcalc “F8 = A[-1,-1] || A[-1,0] || A[-1,1] || A[0,-1] || A || A[0,1] || A[1,-1] || A[1,0] || A[1,1]”

[For 0/1, multiplication is equivalent to the “&&” operator (logical
conjunction).]

Another option, which should only fill in the cells necessary to make
r.clump recognise diagonal adjacency, is:

r.mapcalc “AF = A || A[0,1] && A[1,0] || A[0,-1] && A[1,0] || A[0,1] && A[-1,0] || A[0,-1] && A[-1,0]”

This will only set the centre cell if two diagonally-adjacent
neighbours are both set.

It may even suffice to use:

r.mapcalc “AF = A || A[0,1] && A[1,0] || A[0,-1] && A[1,0]”

This will only fill the cell on one side of a pair of diagonally
adjacent cells.


Glynn Clements <glynn@gclements.plus.com>