# Weighted Minkowski distance for DBSCAN

I'm trying to make clustering of image's pixels with DBSCAN, using RGB values and pixel's coordinates as features. It works well with just RGB values as features, but I want pixels with the same color, but from different regions, to be considered as pixels from different clusters (Imagine 2 red circles on image - even though their pixels share the same color, they belong to different circles, so intuitively, there are 2 different clusters). But, adding coordinates to feautres worsens result.

I've decided, that using a weighted distance metric, where RGB color have higher weights and coordinates have lower, could be useful.But I can't figure out how to pass weights for selected metric (e.g., Minkowski) to scikit-learn implementation of DBSCAN, or, how to precompute distance matrix fast enough (e.g., with scipy.spatial.distance.minkowski, it takes too long for feature's matrix with size of (14000,5)).

Any ideas how to implement it?

clstr = DBSCAN(eps=7,min_samples=14,metric='wminkowski',p=2,metric_params={"w":np.ones(len(X))})