Detecting bad surfaces with API

How would I detect something like this and remove it ? Anyone know of a method or function that can at least detect it so I can deal with it.