Skip to content

Commit

Permalink
small optimization on final rgb drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreaCirilloAC committed Nov 16, 2017
1 parent dee9f19 commit 14f1846
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions R/create_palette.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
}

0 comments on commit 14f1846

Please sign in to comment.