[postgis-users] Better way of removing pixelation with postgis raster
Pierre Racine
Pierre.Racine at sbf.ulaval.ca
Wed Jul 18 13:04:44 PDT 2012
Hi Tom,
> Im trying to create a landuse map for a customer that requires the
> removal of pixelation (isolated islands of pixels, possible larger than
> 1 pixel).
> To make things complicated, different pixelclasses have different
> tresholds for removal.
> For instance, class 1 is removed when the combined pixels are less than
> 4, whereas class2 is removed when the combined pixels are less than 50.
> Furthermore, some classes count diagonal neighbours as 'touching'
> whereas other classes discard them.
>
> My solution is given below.
> As you can see there is an expensive buffer-union-buffer trio to make
> sure I connect the correct polygons before I can calculate their area.
> This calculation is part of a big raster calculation. All of the
> calculations are going very fast, except this one.
> Anyone with an idea to make it faster? In the end all I need is removal
> of isolated islands of pixels so any matrix calculation would be fine as
> well.
I think you could easily implement a filter function to remove the 1 pixel type of island as a custom function of ST_MapAlgebraFctNgb(). See http://www.postgis.org/documentation/manual-svn/RT_ST_MapAlgebraFctNgb.html The size of the window should be 3x3 in this case. Return the pixel value if at least one neighbour has a value, null otherwise.
I am 99% sure ST_MapAlgebraFctNgb would be faster on big rasters than vectorizing/union/rasterizing...
However I have no idea how to implement such a filter to remove bigger islands (or speckles?) spanning on many pixels. Maybe with a little of research...
Pierre
More information about the postgis-users
mailing list