Clustering-driven residue filter for profile measurement system