ValueError While clustering in Sklearn

I have an RGB image of the following form ((3L, 5L, 5L). This means that a 5 by 5 pixel image has 3 layers (R, G and B.). I want to group it using the DBSCAN algorithm as follows. But I got the error message ValueError: Found array with dim 3. Expected <= 2 Can't I use it for my 3D image?

 import numpy as np from sklearn.cluster import DBSCAN from collections import Counter data = np.random.rand(3,5,5) print np.shape(data) print data db = DBSCAN(eps=0.12, min_samples=3).fit(data) print db DBSCAN(algorithm='auto', eps=0.12, leaf_size=30, metric='euclidean', min_samples=1, p=None, random_state=None) labels = db.labels_ print Counter(labels) 
+4
source share
1 answer

To group, you need to say what is the distance between two points. DBSCAN is not a graph clustering algorithm; it works with functions. You must represent each pixel as a function so that the distances are suitable.

Functions can only be RGB, in which case the same colors are grouped together. In addition, functions may also include x, y coordinates, which will indicate spatial distances.

If you want to consider spatial distances, I would suggest you take a look at the scikit-image segmentation module, which contains several popular image segmentation methods.

+2
source

All Articles