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
execute.tests <- function(n) { | |
# A place-holder for the test results | |
result.df <- data.frame() | |
# Initial values for snr model optimization | |
param.init <- c(2, 0.4, 5e-06) | |
# Iterate n times | |
for (n in 1:n) { | |
split.data() | |
# Model each channel per iteration |
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
# Get the weighted errors `w.mean` and `w.var` | |
test.error.weighted.var <- function(sel.channel, coeffs) { | |
tests.pics <- read.csv('test-pics.csv', stringsAsFactors = FALSE, row.names=NULL) | |
tests.pics <- as.vector(tests.pics[,1]) | |
data.df <- subset(data.frame(vvm.all$var.df), | |
channel == sel.channel & | |
pict %in% tests.pics) | |
predicted.var <- (data.df$mean*coeffs[3] + coeffs[2])*data.df$mean + coeffs[1] | |
error.var <- mean((data.df$var - predicted.var)^2/predicted.var) |
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
# Compute the SNR. | |
# Returns "high" values when the model variance is negative to | |
# hint the optimizer to get out of there. | |
snr <- function(mean, var) { | |
negatives <- which(var < 0) | |
result <- 20*log10(mean/sqrt(abs(var))) | |
result[negatives] <- result[negatives]*8 | |
result; | |
} |
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
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', |
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
avg.loss.of.snr <- function(color.conv.matrix, white.bal.scales) { | |
sqr.conv.mtx <- color.conv.matrix^2 | |
wb.conv.mtx <- t(apply(sqr.conv.mtx, 1, function(x) x*white.bal.scales )) | |
mc <- apply(wb.conv.mtx, 1, sum) | |
loss <- mean(log10(mc)) - mean(log(white.bal.scales) ) | |
# Result | |
10*loss; | |
} | |
# Helper function to build the color matrix | |
matrix_3x3 <- function(x) matrix(x, nrow=3L, ncol=3L, byrow=TRUE); |
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
# Read the TIFF files | |
vvm.tif <- vvm$new(has.RGGB.pattern = TRUE) | |
vvm.tif$digest.from.rgb( | |
file.name.from = '_ODL0415', | |
file.name.to = '_ODL1668', | |
file.path = 'ISO100/Selection/LR-zero' | |
) | |
# VVM plot | |
vvm.tif$plot(tlab = "VVM: sRGB images from Lightroom", | |
slab = 'With zero settings', |
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
# Draw SNR quality reference limits for 18% gray | |
add.snr.ref.limits <- function(p) { | |
p + | |
geom_hline(aes(yintercept=20), colour='red', linetype = 6, alpha = 0.4) + | |
geom_hline(aes(yintercept=32), colour='cyan', linetype = 6, alpha = 0.8) + | |
geom_hline(aes(yintercept=38), colour='green', linetype = 6, alpha = 0.8) | |
} |
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
library(imgnoiser) | |
library(ggplot2) | |
# Y coordinate of sRGB primaries. From http://en.wikipedia.org/wiki/SRGB | |
weights.sRGB <- c(0.2126, 0.7152, 0.0722) | |
# D65 white point in XYZ. From ASTM E308-01 in http://www.brucelindbloom.com/ | |
D65.XYZ <- c(0.95047, 1.00000, 1.08883) | |
# With "D65 color matrix" in the camera color data, we can convert | |
# the D65 XYZ white point to the camera raw color space: | |
D65.raw <- nikon.d7000.ISO100.colmap$cam.matrices.2$color.matrix %*% D65.XYZ | |
#> [,1] |
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
vvm.rgb <- convert.to.rgb(target.space = 'sRGB', use.camera.tc = FALSE, target.tc = 'linear') | |
x11() | |
vvm.rgb$plot(tlab = "VVM Selected samples in linear sRGB", | |
slab = 'Without camera tone curve') | |
vvm.rgb$plot(x = log2(mean), y = 20*log10(mean/sqrt(var)), | |
tlab = "SNR Selected samples in linear sRGB", | |
slab = 'Without camera tone curve', | |
xlab = "Signal (stops)", xlim=c(-1.5,8), | |
ylab = "SNR (dB)") |
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
# Plot log-log of LR and our camera tone curves | |
ggplot(lin.rgb.and.tif) + | |
geom_point(aes(x = (mean)/255, y = tif.mean.cam/255, | |
group = channel, colour = channel), | |
size = 1.5) + | |
ggtitle('LR Camera tone curve\nFor Nikon D7000') + | |
xlab('linear sRGB gray (log10)') + ylab('LR camera TC sRGB gray (log10)') + | |
scale_x_log10() + | |
scale_y_log10() + | |
geom_line(aes(x=x, y=y), data=my.cam.tc, color='darkblue', linetype='dashed') |
NewerOlder