Skip to content

Instantly share code, notes, and snippets.

@myazdani
Created April 10, 2014 19:01
Show Gist options
  • Save myazdani/10412314 to your computer and use it in GitHub Desktop.
Save myazdani/10412314 to your computer and use it in GitHub Desktop.
Adds an HSV proxy to QTIP CSV
#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