Closed wincowgerDEV closed 12 months ago
@G-EC is Gabriel's username
Wrote some more code today to support this.
library(OpenSpecy)
library(signal)
library(dplyr)
library(ggplot2)
data("raman_hdpe")
raman_hdpe$derivative <- sgolayfilt(raman_hdpe$intensity, p = 3, n = 15, m = 1)
ggplot(raman_hdpe) + geom_line(aes(x = wavenumber, y = make_rel(intensity))) + geom_line(aes(x = wavenumber, y = make_rel(abs(derivative))), color = "blue")
#where are peaks
raman_hdpe %>%
dplyr::top_n(1/derivative, n = 50)
hist(log10(make_rel(abs(raman_hdpe$derivative))))
im <- make_rel(abs(raman_hdpe$derivative))
#Max entropy
calculateMaxEntropy <- function(Image){
# if(max(Image)<=1 & min(Image)>=0){
# im = Image*255
# }
size = dim(im)
im = as.vector(im)
hn = hist(im,breaks=seq(0,1, by = 0.01),plot=FALSE)$counts
#hn = hn / (size[1]*size[2])
c = rep(0,101)
c[1] = hn[1]
for (l in 2:101){
c[l]=c[l-1]+hn[l]
}
#low and high entropy
hl = rep(0,101);
hh = rep(0,101);
for (t in 1:101){
#low entropy threshlod
cl = c[100]
if(cl>0){
for(i in 1:t){
if (hn[i] >=0) {
hl[t] = hl[t]- (hn[i]/cl)*log(hn[i]/cl)
}
}
}
#high entropy threshold
ch = 1 - c[t]
if(ch > 0){
for ( i in (t+1):101 ){
if(!is.na(hn[i])){
if ( hn[i]>0 ) {
hh[t] = hh[t] - (hn[i]/ch)*log(hn[i]/ch);
}
}
}
}
}
# Find histogram index with maximum entropy
h_max =hl[1]+hh[1]
threshold = 0;
for(t in 2:101) {
j = hl[t] + hh[t]
if(!is.na(j)){
if (j > h_max) {
h_max = j;
threshold = t
}
}
}
#threshold = threshold/255
return (threshold)
}
`
@G-EC we have this implemented now in the package! Thanks for the help.
Gabriel Erni Cassola and I have been talking about adding derivative transformations to Open Specy and adding derivative matching.
Some initial code Gabriel wrote:
And code for converting the spectral library to derivative version: