orderClusters {colordistance} | R Documentation |
Order color clusters to minimize overall color distance between pairs
Description
Reorders clusters to minimize color distance using the
Hungarian algorithm
as implemented by solve_LSAP
.
Usage
orderClusters(extractClustersObject)
Arguments
extractClustersObject |
A list of color clusters such as those returned
by |
Details
Briefly: Euclidean distances between every possible pair of clusters across two dataframes are calculated, and pairs of clusters are chosen in order to minimize the total sum of color distances between the cluster pairs (i.e. A1-B1, A2-B2, etc).
For example, if dataframe A has a black cluster, a white cluster, and a blue cluster, in that order, and dataframe B has a white cluster, a blue cluster, and a grey cluster, in that order, the final pairs might be A1-B3 (black and grey), A2-B2 (blue and blue), and A3-B1 (white and white).
Rows are reordered so that paired rows are in the same row index (in the example, dataframe B would be reshuffled to go grey, blue, white instead of white, grey, blue).
Value
A list with identical data to the input list, but with rows in each dataframe reordered to minimize color distances per cluster pair.
Examples
cluster.list <- colordistance::getKMeansList(c(system.file("extdata",
"Heliconius/Heliconius_A", package="colordistance"), lower=rep(0.8, 3),
upper=rep(1, 3)))
cluster.list <- colordistance::extractClusters(cluster.list)
colordistance:::orderClusters(cluster.list)