public class ClusteringHelper
extends java.lang.Object
| Modifier and Type | Method and Description |
|---|---|
static ColorCluster[] |
addColorsToClusters(ColorCluster[] clusters,
RColor[] colors)
Assigns each color from given set of colors to one of the cluster
of the given set clusters.
|
static ColorCluster[] |
colorsToClusters(RColor[] means,
ColorDifferenceMeasure m)
Builds new ColorClusters from a given set of colors.
|
static java.lang.Float |
computeLoss(Cluster[] clusters)
Computed the mean loss of the given clusters.
|
static float[] |
getLosses(Clustering[] clustering)
Calculates the loss for all the clusterings in the given set.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize,
ColorDifferenceMeasure m)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize,
ColorDifferenceMeasure m,
java.lang.Integer cellSize)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize,
ColorSpace space)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize,
ColorSpace space,
int cellSize)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(processing.core.PImage img,
java.lang.Integer trainingsSize,
java.lang.Integer cellSize)
Picks trainingsSize semi-random colors from the input image.
|
static RColor[] |
getTrainingColors(RColor[] colors,
java.lang.Integer trainingsSize)
Creates a randomly sampled subset of the give set of colors.
|
static RColor[] |
getTrainingColors(RColor[] colors,
java.lang.Integer trainingSize,
ColorDifferenceMeasure m)
Creates a randomly sampled subset of the give set of colors and
converts the returned colors to a color space defined by the given
ColorDifferenceMeasure (e.g. m=RGBEuclidean -> returned colors are
RGBColors).
|
static RColor[] |
getTrainingColors(RColor[] colors,
java.lang.Integer trainingsSize,
ColorSpace space)
Creates a randomly sampled subset of the give set of colors and
converts the returned colors to the given color space.
|
static java.lang.Object[] |
getTrainingData(java.lang.Object[] raw,
java.lang.Integer trainingSize)
Creates a randomly sampled subset of the give set raw.
|
static ColorClustering |
kmeans(RColor[] colors,
java.lang.Integer k,
ColorDifferenceMeasure m)
Applies the k-means algorithm to colors for a given k.
|
static ColorClustering |
kmeans(RColor[] colors,
java.lang.Integer k,
ColorDifferenceMeasure m,
ColorCluster[] existingClusters)
Applies the k-means algorithm to colors for a given k.
|
static ColorClustering[] |
kmeansClusterings(RColor[] colors,
java.lang.Integer minK,
java.lang.Integer maxK,
ColorDifferenceMeasure m)
Applies the k-means algorithm to colors for a range of k.
|
public static java.lang.Float computeLoss(Cluster[] clusters)
clusters - A set of clusters.public static float[] getLosses(Clustering[] clustering)
clustering - A set of clusterings.public static java.lang.Object[] getTrainingData(java.lang.Object[] raw,
java.lang.Integer trainingSize)
raw - The original data.trainingSize - The number of elements the training data should consist of. If
the given set raw is smaller than trainingSize, the
returned set is not a subset, but a randomly sorted version of
the original set.public static ColorCluster[] colorsToClusters(RColor[] means, ColorDifferenceMeasure m)
means - The colors that should be the initial means of the new
clusters.m - A colorDifferenceMeasure.public static ColorCluster[] addColorsToClusters(ColorCluster[] clusters, RColor[] colors)
clusters - A set of clusters with already assigned means and
ColorDifferenceMeasure. The ColorDifferenceMeasure for all
clusters should be equal.colors - A set of colors. For better performance make sure that the
color space of all colors are equal and equal to the cluster
means color spaces as well as that the color space correspond
to the ColorDifferenceMeasure of the clusters.public static ColorClustering kmeans(RColor[] colors, java.lang.Integer k, ColorDifferenceMeasure m)
colors - The set of colors which will be clustered. To prevent
unnecessary color space transformations please make sure that
these colors are all members of the same color space and that
this color space correlates to the give
ColorDifferenceMeasure. You can convert the colors using the
ColorHelper.convert(ColorDifferenceMeasure) method.k - The number of clusters (>= 2).m - The ColorDifferencemeasure.public static ColorClustering kmeans(RColor[] colors, java.lang.Integer k, ColorDifferenceMeasure m, ColorCluster[] existingClusters)
colors - The set of colors which will be clustered. To prevent
unnecessary color space transformations please make sure that
these colors are all members of the same color space and that
this color space correlates to the give
ColorDifferenceMeasure. You can convert the colors using the
ColorHelper.convert(ColorDifferenceMeasure) method.k - The number of clusters (>= 2).m - The ColorDifferencemeasure.existingClusters - null or previously calculated clusters. The means of them will
serve as initial cluster centers for the new clustering.public static ColorClustering[] kmeansClusterings(RColor[] colors, java.lang.Integer minK, java.lang.Integer maxK, ColorDifferenceMeasure m)
colors - The set of colors which will be clustered. To prevent
unnecessary color space transformations please make sure that
these colors are all members of the same color space and that
this color space correlates to the give
ColorDifferenceMeasure. You can convert the colors using the
ColorHelper.convert(ColorDifferenceMeasure) method.minK - The number of clusters for the first clustering (minK >= 2,
minK < maxK).maxK - The number of clusters for the last clustering (maxK <
colors.length, minK < maxK).m - The ColorDifferencemeasure.public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize)
img - A image (Number of pixels should be higher then
trainingsSize).trainingsSize - The number of colors that should be sampled from the image.public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize, java.lang.Integer cellSize)
img - A image (Number of pixels should be higher then
trainingsSize).trainingsSize - The number of colors that should be sampled from the image.cellSize - Sets the number of random chosen color samples per cell. If
cellSize=1, there are a lot of small cells and in each sell
one color is picked. If cellSize=2, there are bigger cells and
in each cell two colors are picked. In most cases cellSize=1
is the most convenient value.public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize, ColorDifferenceMeasure m)
img - A image (Number of pixels should be higher then
trainingsSize).trainingsSize - The number of colors that should be sampled from the image.m - A ColorDifferenceMeasure (defines in what color space the
colors are returned).public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize, ColorSpace space)
img - A image (Number of pixels should be higher then
trainingsSize).space - A color space (defines in what color space the colors are
returned).cellSize - Sets the number of random chosen color samples per cell. If
cellSize=1, there are a lot of small cells and in each sell
one color is picked. If cellSize=2, there are bigger cells and
in each cell two colors are picked. In most cases cellSize=1
is the most convenient value.public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize, ColorSpace space, int cellSize)
img - A image (Number of pixels should be higher then
trainingsSize).trainingsSize - The number of colors that should be sampled from the image.space - A color space (defines in what color space the colors are
returned).cellSize - Sets the number of random chosen color samples per cell. If
cellSize=1, there are a lot of small cells and in each sell
one color is picked. If cellSize=2, there are bigger cells and
in each cell two colors are picked. In most cases cellSize=1
is the most convenient value.public static RColor[] getTrainingColors(processing.core.PImage img, java.lang.Integer trainingsSize, ColorDifferenceMeasure m, java.lang.Integer cellSize)
img - A image (Number of pixels should be higher then
trainingsSize).trainingsSize - The number of colors that should be sampled from the image.m - A ColorDifferenceMeasure (defines in what color space the
colors are returned).cellSize - Sets the number of random chosen color samples per cell. If
cellSize=1, there are a lot of small cells and in each sell
one color is picked. If cellSize=2, there are bigger cells and
in each cell two colors are picked. In most cases cellSize=1
is the most convenient value.public static RColor[] getTrainingColors(RColor[] colors, java.lang.Integer trainingsSize)
colors - The original data.trainingsSize - The number of elements the training data should consist of. If
the given set colors is smaller than trainingSize, the
returned set is not a subset, but a randomly sorted version of
the original set.public static RColor[] getTrainingColors(RColor[] colors, java.lang.Integer trainingsSize, ColorSpace space)
colors - The original data.trainingsSize - The number of elements the training data should consist of. If
the given set colors is smaller than trainingSize, the
returned set is not a subset, but a randomly sorted version of
the original set.space - A color space or null. A ColorDifferenceMeasure or null.public static RColor[] getTrainingColors(RColor[] colors, java.lang.Integer trainingSize, ColorDifferenceMeasure m)
colors - The original data.trainingsSize - The number of elements the training data should consist of. If
the given set colors is smaller than trainingSize, the
returned set is not a subset, but a randomly sorted version of
the original set.m - A ColorDifferenceMeasure or null.