Here a simple answer to this:this but not an exact one:
- first of all you should extract sharp edges. Like if you use Canny for edge detection set the thresholds somehow to that is responsive to sharp edges.
- Then you could simply use a smoothing filter(e.g Gaussian) where a sharp edges where detected.