/** * Construct using the given colour space, number of segments, and distance * measure. The elements of each colour band are by the corresponding * elements in the given scaling vector, and the k-means algorithm will * iterate at most <code>maxIters</code> times. * * @param colourSpace * the colour space * @param scaling * the scaling vector * @param K * the number of segments * @param distance * the distance measure * @param maxIters * the maximum number of iterations to perform */ public KMColourSegmenter(ColourSpace colourSpace, float[] scaling, int K, FloatFVComparator distance, int maxIters) { if (scaling != null && scaling.length < colourSpace.getNumBands()) throw new IllegalArgumentException( "Scaling vector must have the same length as the number of dimensions of the target colourspace (or more)"); this.colourSpace = colourSpace; this.scaling = scaling; final KMeansConfiguration<FloatNearestNeighbours, float[]> conf = new KMeansConfiguration<FloatNearestNeighbours, float[]>( K, new FloatNearestNeighboursExact.Factory(distance), maxIters); this.kmeans = new FloatKMeans(conf); }
/** * Construct using the given colour space, number of segments, and distance * measure. The elements of each colour band are by the corresponding * elements in the given scaling vector, and the k-means algorithm will * iterate at most <code>maxIters</code> times. * * @param colourSpace * the colour space * @param scaling * the scaling vector * @param K * the number of segments * @param distance * the distance measure * @param maxIters * the maximum number of iterations to perform */ public KMColourSegmenter(ColourSpace colourSpace, float[] scaling, int K, FloatFVComparator distance, int maxIters) { if (scaling != null && scaling.length < colourSpace.getNumBands()) throw new IllegalArgumentException( "Scaling vector must have the same length as the number of dimensions of the target colourspace (or more)"); this.colourSpace = colourSpace; this.scaling = scaling; final KMeansConfiguration<FloatNearestNeighbours, float[]> conf = new KMeansConfiguration<FloatNearestNeighbours, float[]>( K, new FloatNearestNeighboursExact.Factory(distance), maxIters); this.kmeans = new FloatKMeans(conf); }
/** * Convenience method to quickly create an exact {@link FloatKMeans}. All * parameters other than the number of clusters and number * of iterations are set at their defaults, but can be manipulated through * the configuration returned by {@link #getConfiguration()}. * <p> * Euclidean distance is used to measure the distance between points. * * @param K * the number of clusters * @param niters * maximum number of iterations * @return a {@link FloatKMeans} instance configured for exact k-means */ public static FloatKMeans createExact(int K, int niters) { final KMeansConfiguration<FloatNearestNeighbours, float[]> conf = new KMeansConfiguration<FloatNearestNeighbours, float[]>(K, new FloatNearestNeighboursExact.Factory(), niters); return new FloatKMeans(conf); }
/** * Convenience method to quickly create an exact {@link FloatKMeans}. All * parameters other than the number of clusters are set * at their defaults, but can be manipulated through the configuration * returned by {@link #getConfiguration()}. * <p> * Euclidean distance is used to measure the distance between points. * * @param K * the number of clusters * @return a {@link FloatKMeans} instance configured for exact k-means */ public static FloatKMeans createExact(int K) { final KMeansConfiguration<FloatNearestNeighbours, float[]> conf = new KMeansConfiguration<FloatNearestNeighbours, float[]>(K, new FloatNearestNeighboursExact.Factory()); return new FloatKMeans(conf); }