From 14f1846a8eb46581f147823fbf555d4229fe56b1 Mon Sep 17 00:00:00 2001 From: AndreaCirilloAC Date: Thu, 16 Nov 2017 22:16:25 +0100 Subject: [PATCH] small optimization on final rgb drawing --- R/create_palette.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/create_palette.R b/R/create_palette.R index 2dbcdc9..b126131 100644 --- a/R/create_palette.R +++ b/R/create_palette.R @@ -10,7 +10,8 @@ #' create_palette("data/nascita_venere.jpg",number_of_colors = 20) #' @export create_palette <- function(image_path = NA, number_of_colors = 20){ - if (is.na(image_path)){stop("you must provide a jpg image to build your palette from")} + + if (is.na(image_path)){stop("you must provide a jpg image to create your palette from")} painting <- readJPEG(image_path) dimension <- dim(painting) painting_rgb <- data.frame( @@ -21,8 +22,7 @@ create_palette <- function(image_path = NA, number_of_colors = 20){ B = as.vector(painting[,,3]) ) k_means <- kmeans(painting_rgb[,c("R","G","B")], centers = number_of_colors, iter.max = 30) - colours_k <- rgb(k_means$centers[k_means$cluster,]) - colours_vector <- unique(colours_k) + colours_vector <- rgb(k_means$centers) show_col(colours_vector) return(colours_vector) } \ No newline at end of file