Last active
March 30, 2017 12:04
color distance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
n <- 1000000 | |
data <- data.frame(id = 1:n, | |
red = sample(0:255, size = n, replace = TRUE), | |
green = sample(0:255, size = n, replace = TRUE), | |
blue = sample(255, size = n, replace = TRUE)) | |
query <- list(red = 80, green = 90, blue = 255) | |
results <- data %>% | |
mutate(eu_dist = sqrt((red - query$red)^2 + | |
(blue - query$blue)^2 + | |
(green - query$green)^2)) %>% | |
arrange(eu_dist) | |
print(head(results)) | |
# output | |
# > print(head(results)) | |
# id red green blue eu_dist | |
# 1 850076 81 91 255 1.414214 | |
# 2 245256 81 88 255 2.236068 | |
# 3 255701 79 89 253 2.449490 | |
# 4 864183 78 89 254 2.449490 | |
# 5 126499 78 90 253 2.828427 | |
# 6 904071 79 90 252 3.162278 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment