[GRASS5] Gaussian filter for GRASS

Glynn Clements glynn at gclements.plus.com
Thu Apr 21 14:06:39 EDT 2005


Jachym Cepicky wrote:

> I have tryed to program the Gaussian filter for raster maps. It
> works only with CELL maps for now, but I hope to extend it for DCELL
> and FCELL maps too.

The simplest solution is to use DCELL throughout. All CELL and FCELL
values can be represented as DCELL without loss of range or precision.

> Because this is my first raster module for GRASS and also my first bigger
> C-program, I would be very thankfull, if someone could have a look at the 
> code at to tell me, what I could do better/safer.

Use a scrolling window; don't read each row three times.

At the moment, you're reading rows 0/1/2, then 1/2/3, then 2/3/4 and
so on. Note that you're reading each row (except the first and last
two) three times. Also note that you already have two out of the three
rows in memory from the previous pass (again, except for the first and
last two passes).

See r.neighbors or r.grow2.

Actually, is there any reason why this filter can't be added to
r.neighbors as another method?

> I would like to write some other filters for raster maps too, the next stage
> should be Mean of least variance filter. But before I start, I would like to be
> shure, that I don't do something really stupid in the program.
> 
> I could not to solve, how to work on the boundaries of the raster. I had to
> skip these cells, like e.g. r.mapcalc does -- so NULL values appear there. 
> How to do it some better way?

In general, you can't. Convolution-style filters always result in the
map being "shrunk".

> I'm also not shure, if I do the allocation of neigborhood rows the right way.
> 
> I hope, I did not forget to free all the buffers at the end.

It doesn't matter about freeing buffers; all memory will be reclaimed
by the OS when the program terminates.

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




More information about the grass-dev mailing list