Clustering cartesian coordinates associated with 1 categorical feature
This isn't a clustering problem. Within each set (like W=3), you simply sort them by x coordinate and then y coordinate too. Find the points +/- 2 pixels in the x dimension, then in the y dimension, and take the points that are in both. This ought to be linear within a sorted list.