Skip to content

Instantly share code, notes, and snippets.

@oscardelama
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscardelama/084b6c68a0c0cfd0349f to your computer and use it in GitHub Desktop.
Save oscardelama/084b6c68a0c0cfd0349f to your computer and use it in GitHub Desktop.
Compute the loss of SNR we converting a raw image to a RGB color space.
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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment