Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
xval-noise-models: Cross validation of "var ~ mean + mean^2" models testing a SNR optimization model versus the regular VVM model.
library(imgnoiser)
library(dplyr)
library(robustbase)
# Acquire the data
vvm.all <- vvm$new(has.RGGB.pattern = TRUE)
vvm.all$digest(
file.name.from = '_ODL0387s4',
file.name.to = '_ODL1671s6',
file.name.ext = '.pgm',
file.path = 'ISO100/crops',
min.raw = 4, # <= Raising this limit to avoid the funny red tail
max.raw = c(16379, 15774, 15774 ,16379)
)
# Get and save the list of all the sample file names
all.pics <- unique(as.character(vvm.all$var.df$pict))
write.csv(all.pics, 'all-pics.csv', row.names =FALSE)
# Split the data and save the sets sample file names
# into the "train-pics.csv" and "test-pics.csv" files
split.data <- function() {
var.df <- subset(data.frame(vvm.all$var.df), channel == 'Green Avg')
chunks <- kmeans(log(var.df$mean), 60, iter.max=100, nstart=30)
pict.cluster.lst <- split(as.character(var.df$pict), chunks$cluster)
pick.training.set <- function(v) {
choosen.rows <-
if (length(v) == 1)
1
else {
# How many are choosen for training?
nbr <- round(length(v) * 0.6)
if (nbr == length(v)) nbr <- nbr - 1
sample(length(v), nbr)
}
# result
v[choosen.rows];
}
training.pics <- sapply(pict.cluster.lst, pick.training.set)
training.pics <- unlist(training.pics)
write.csv(training.pics, 'train-pics.csv', row.names =FALSE)
test.pics <- var.df[!(var.df$pict %in% training.pics), 'pict']
write.csv(test.pics, 'test-pics.csv', row.names =FALSE)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.