Created
April 10, 2014 19:01
-
-
Save myazdani/10412314 to your computer and use it in GitHub Desktop.
Adds an HSV proxy to QTIP CSV
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
#addHSVtoQTIP.R | |
# | |
#adds HSV (as defined on wikipedia) to mean RGB as computed by QTIP | |
#Mehrdad Yazdani, Feb 2014 | |
in_file = "~/Desktop/kiev_merged.csv" | |
out_file = "~/Desktop/kiev_HSV_added.csv" | |
qtip.features = read.csv(in_file, header = TRUE, stringsAsFactors = FALSE) | |
M = apply(qtip.features[,c("meanR", "meanG", "meanB")], 1, max) | |
m = apply(qtip.features[,c("meanR", "meanG", "meanB")], 1, min) | |
C = M - m | |
alpha = .5*(2*qtip.features$meanR - qtip.features$meanG - qtip.features$meanB) | |
beta = (sqrt(3)/2)*(qtip.features$meanG - qtip.features$meanB) | |
qtip.features$Hue = atan2(beta, alpha) | |
qtip.features$Chroma = sqrt(alpha**2 + beta**2) | |
qtip.features$Value = M | |
qtip.features$Saturaion = qtip.features$Chroma/qtip.features$Value | |
write.csv(qtip.features, file = out_file, row.names = FALSE, quote = FALSE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment