-
Notifications
You must be signed in to change notification settings - Fork 1
/
Munsellchip.R
92 lines (62 loc) · 2.37 KB
/
Munsellchip.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#setwd("C:/Users/mnel6409/Seb Dropbox/Dropbox/BIOM Extra Tutorial")
#setwd("C:/Users/bmal4866/Desktop/TXTBIN")
setwd("C:/Users/phug7649/Desktop/TXTBIN")
## This is where the munsell colours are.
##install.packages("munsell")
ctrial <- read.table("LAB_Carbon32.txt", header=TRUE, sep=",")
ctrial<-colours
#ctrial<-na.exclude(ctrial)
Reference <- read.csv("reference.csv", header=TRUE, sep=",")
#ctrial <- read.table("Ctrial.txt", header=TRUE, sep=",")
library(munsell)
###Warning!! this is a test script. It will damage the file if left in####################
#generate all munsell hues
munsell_cols <- with(hue_slice()$data, paste(hue, " ", value, "/", chroma, sep=""))
#Pick random colours
random_colours <- sample(munsell_cols, nrow(ctrial), replace=TRUE)
#Make munsell column of random colours
ctrial$class <- random_colours
##########################################################################################
#mnsl_US[mnsl_US=="*"] <- NA
#mnsl_US[mnsl_US=="N"] <- NA
#mnsl_US[mnsl_US==""] <- NA
#mnsl_US <- droplevels(mnsl_US)
## much of this data was in the factor column. Even though
## deleted, quotes and NA's can be rememberedby the program
## as levels. Droplevels removes these unnecesary quotes
## and NA's.
##unsure as to why we need ggplot. Its cool though.
install.packages("ggplot2")
library(ggplot2)
##time to diverge from the munsell colour converting software.
#LAB<-read.table("Ctrial.txt", sep=",", header=T)
LAB<-read.table("LAB_Carbon32.txt", sep=",", header=T)
##This x needs to have each row matched with a munsell tile that is closest in colour.
##Euclidean distances would be the best method.
euc <- function(dat, x1, y1, z1){
if(any(length(x1)!=1,length(y1)!=1,length(z1)!=1)) stop("x1, y1, or z1 should be length 1")
x<-dat$L.
y<-dat$a.
z<-dat$b.
answer <- sqrt((x-x1)^2+(y-y1)^2+(z-z1)^2)
return(answer)
}
#y <- matrix(NA, )
##refLAB <- munslab.df
Munsell <- rep(NA,nrow(ctrial))
for(i in 1:nrow(ctrial)){
L <- ctrial$L[i]
A <- ctrial$A[i]
B <- ctrial$B[i]
y <-euc(Reference,L,A,B)
Munsell[i]<- which.min(y)
}
out<-Reference[Munsell,]
write.csv(out, "Muns_Carbon32.csv")
check<-read.csv("Muns_Carbon32.csv")
y<-euc(LAB,1,2,3)
which.min
dist(x, mnsl_data, method = "euclidean", diag = FALSE, upper = FALSE, p = 2)
library(plyr)
yay <- join(mnsl_CIELAB, munsLAB.df)
write.table(yay, "cfix_LAB_92132.txt")