Added erosion filter and threshold