Search in sources :

Example 1 with CentroidCluster

use of org.apache.commons.math3.ml.clustering.CentroidCluster in project imagingbook-common by imagingbook.

the class KMeansClusteringQuantizerApache method makeColorMap.

private int[][] makeColorMap() {
    List<int[]> colList = new LinkedList<>();
    for (CentroidCluster<DoublePoint> ctr : centers) {
        double[] c = ctr.getCenter().getPoint();
        int red = (int) Math.round(c[0]);
        int grn = (int) Math.round(c[1]);
        int blu = (int) Math.round(c[2]);
        colList.add(new int[] { red, grn, blu });
    }
    return colList.toArray(new int[0][]);
}
Also used : DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) LinkedList(java.util.LinkedList) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint)

Example 2 with CentroidCluster

use of org.apache.commons.math3.ml.clustering.CentroidCluster in project imagingbook-common by imagingbook.

the class KMeansClusteringQuantizerApache method cluster.

// --------------------------------------------------------------
private List<CentroidCluster<DoublePoint>> cluster(int[] pixels) {
    KMeansPlusPlusClusterer<DoublePoint> clusterer = new KMeansPlusPlusClusterer<>(params.maxColors, params.maxIterations);
    List<DoublePoint> points = new ArrayList<>();
    for (int i = 0; i < pixels.length; i++) {
        points.add(new DoublePoint(intToRgbDouble(pixels[i])));
    }
    return clusterer.cluster(points);
}
Also used : DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint) ArrayList(java.util.ArrayList) KMeansPlusPlusClusterer(org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer) DoublePoint(org.apache.commons.math3.ml.clustering.DoublePoint)

Aggregations

DoublePoint (org.apache.commons.math3.ml.clustering.DoublePoint)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 KMeansPlusPlusClusterer (org.apache.commons.math3.ml.clustering.KMeansPlusPlusClusterer)1