# make a 100x100 'image' of random colors
img <- array(runif(30000), dim = c(100, 100, 3))
plotImageArray(img)
# make a background index object:
bg_indexed <- backgroundIndex(img, backgroundCondition())
# histogram clustering
hist_clusters <- colorClusters(bg_indexed, method = "hist", bins = 2)
plotColorPalette(hist_clusters$centers)
# we can use a different number of bins for each channel
uneven_clusters <- colorClusters(bg_indexed, method = "hist",
bins = c(3, 2, 1))
plotColorPalette(uneven_clusters$centers)
# using kmeans
kmeans_clusters <- colorClusters(bg_indexed, method = "kmeans",
n = 5)
plotColorPalette(kmeans_clusters$centers)
Run the code above in your browser using DataLab