Skip to contents

Often for batch processing purposes, it is important to ensure that color centers fit using different methods are in the same order. This function reorders a provided color palette (match_palette) according a provided reference palette (reference_palette) by minimizing their overall distance using the Hungarian algorithm as implemented by clue::solve_LSAP.

Usage

match_colors(reference_palette, match_palette, plotting = FALSE)

Arguments

reference_palette

The palette whose order to match. Either a character vector of colors (hex codes or color names) or an nx3 matrix in sRGB color space.

match_palette

The palette to reorder, same formats as reference_palette

plotting

Logical. Plot the ordered palettes?

Value

A vector of color orders for match_palette.

Details

If the color palettes are wildly different, the returned order may not be especially meaningful.

See also

Examples

ref_palette <- c("mediumblue", "olivedrab", "tomato2", "beige", "chocolate4")
match_palette <- c("#362C34", "#E4D3A9", "#AA4E47", "#809C35", "#49468E")
match_colors(ref_palette, match_palette, plotting = TRUE)
#> Registered S3 method overwritten by 'spatstat.geom':
#>   method      from  
#>   plot.imlist imager

#> Optimal assignment:
#> 1 => 5, 2 => 4, 3 => 3, 4 => 2, 5 => 1