PostGIS's ST_MapAlgebra_expr (focal operations) seems a good canditate to implement Erosion and Dilation operations, that are like the vectorial counterpart ST_Buffer (positive and negative).
It is not obvious and the Guide not show examples. Can you show an example?