[GRASS-dev] r.shrink??

Glynn Clements glynn at gclements.plus.com
Tue Aug 22 20:23:37 EDT 2006


Michael Barton wrote:

> Can r.grow use negative numbers?

No.

> Could it be made to do so

Sort of.

You could implement shrinking by inverting the sense of the
!G_is_d_null_value(...) tests (and making a couple of other changes).

The end result would be equivalent to "inverting" the map (swap
null<->non-null), running r.grow, then swapping back, e.g.:

	r.mapcalc 'tmp1 = if(isnull(inmap),1,null())'
	r.grow in=tmp1 out=tmp2 new=1
	r.mapcalc outmap = if(isnull(tmp2),inmap,null())'

> or can we make an r.shrink?

That's also an option. A separate r.shrink would be slightly simpler
than r.grow, as you don't need to deal with ordering (r.grow needs to
determine the nearest non-null cell, while an r.shrink would just need
to test whether any of the neighbours are null).

> A standard set of image processing routines, for binary images, includes
> dilate, erode,  outline, and skeletonize. Two other compound routines are
> open (dilate followed by erode) and close (erode followed by dilate). GRASS
> can accomplish some of these processes:
> 
> dilate = r.grow
> outline (sort of) = r.to.vect followed by v.to rast, but a better raster
> version would be nice
> skeletonize = r.thin (iterated)
> 
> But there is nothing to shrink areas (erode in image processing parlance).
> 
> Since GRASS already has such good image processing capabilities already, it
> would be nice to round them out with these standard routines.
> 
> If people think this is a good idea, I can turn this into a wish.

Rather than writing lots of separate modules, it might be worth
extending r.mapcalc to support operations on a neighbourhood window
(i.e. so that things that you can theoretically do in r.mapcalc using
expressions with O(W x H) terms would actually become practical).

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




More information about the grass-dev mailing list