[postgis-users] Better way of removing pixelation with postgis raster

Tom van Tilburg tom.van.tilburg at gmail.com
Thu Jul 19 01:43:58 PDT 2012


Pierre,

Thanks for putting your brain on this!
This last option I thought about as well, but since I need to remove 
pixelation on *all* classes, I would have to do the process of 
vectorizing on all of them as well. In the end, wouldn't  the total 
processing time be about the same?

In my idea staying with the algebra functions should be doable, even 
with complex speckles.
As long as the mask is big enough (finding speckles of max N pixels 
takes a 2N x 2N matrix) one should be able to run a neighbourhood scan 
outwards from the centre pixel. With some smart iterations that might 
work, I just need to start learning plpsql or something...
Would you agree that that kind of method would be faster than vectorizing?

Cheers,
  Tom

On 18-7-2012 23:14, Pierre Racine wrote:
> What if you use ST_Mapalgebra to isolate the value you want to work on before vectorizing so that you reduce a lot the number of pixel to vectorize?
>
> In your case you would produce two intermediate rasters (one for class 1, one for class 2), vectorize/buffer/union/rasterize them and then merge them using ST_Union(rast)?
>
> Pierre
>
>> -----Original Message-----
>> From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-
>> bounces at postgis.refractions.net] On Behalf Of Tom van Tilburg
>> Sent: Friday, July 06, 2012 9:37 AM
>> To: PostGIS Users Discussion
>> Subject: [postgis-users] Better way of removing pixelation with postgis raster
>>
>> Hi list,
>>
>> 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.
>>
>> thanks, Tom
>>
>> ------------------------------------------
>> WITH
>> --Dump to polygons
>> polygons As
>> (
>>           SELECT (ST_DumpAsPolygons(rast)).geom geom,
>> (ST_DumpAsPolygons(rast)).val val
>>           FROM out_landuse_rast_30
>> )
>> --Merge polygons
>> ,polygons_dissolved As
>> (
>>           SELECT
>> ST_Buffer((ST_Dump(ST_Union(ST_Buffer(geom,1)))).geom,-1) geom, val
>>           FROM polygons
>>           GROUP BY val
>> )
>>
>> --Select polygons that should go out
>> ,polygons_out As
>> (
>>           SELECT St_Collect(geom) geom FROM polygons_dissolved
>>           WHERE
>>                   (ST_Area(geom) >= ((30*30) * 4) --4 pixels
>>                   AND val IN (1)
>>                   )
>>           OR
>>                   (ST_Area(geom) >= ((30*30) * 50) --50 pixels
>>                   AND val IN (2)
>>                   )
>> )
>>
>> --Create raster (mask) that should go out
>> SELECT 1 As rid, ST_AsRaster(a.geom, b.rast, '8BUI',1,0,false) rast
>> FROM polygons_out a, emptycanvas30 b;
>> ------------------------------------
>>
>> _______________________________________________
>> postgis-users mailing list
>> postgis-users at postgis.refractions.net
>> http://postgis.refractions.net/mailman/listinfo/postgis-users
> _______________________________________________
> postgis-users mailing list
> postgis-users at postgis.refractions.net
> http://postgis.refractions.net/mailman/listinfo/postgis-users




More information about the postgis-users mailing list