Last active
August 29, 2015 14:14
-
-
Save oscardelama/773e45301580c7d9e6c3 to your computer and use it in GitHub Desktop.
rgb-noise: digest as RGB each set
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
# Convert selected raw images to a given destinations space | |
# without demosaicing | |
convert.to.rgb <- function(target.space, | |
use.camera.tc, | |
target.tc, | |
cam.coldata = imgnoiser::nikon.d7000.ISO100.colmap, | |
dest.scale = 255 | |
) { | |
library(imgnoiser) | |
# Red the selected samples names and save them as a vector | |
sel.pics <- read.csv('sel-pict.csv') | |
sel.pics <- as.vector(sel.pics$pict) | |
# Place holder where all the resulting data will be collected | |
vvm.rgb.all <- vvm$new(has.RGGB.pattern = TRUE) | |
# For each set | |
for (set.nbr in 1L:6L) { | |
set.id <- paste0('s', set.nbr) | |
# Select the samples belonging to the set | |
pict.set <- sel.pics[grepl(set.id, sel.pics, fixed = TRUE)] | |
# Digest the raw images in the set | |
vvm.set <- vvm$new(has.RGGB.pattern = TRUE) | |
vvm.set$digest( | |
file.name.from = pict.set, | |
file.path = 'H:/FUN/FOTOS/Noise Study/ipadWhite/ISO100/Selection/crops' | |
) | |
# Get the 45 and 80 percentile of average green mean | |
qvals <- quantile(vvm.set$wide.var.df$green.avg.mean, c(0.45, 0.80)) | |
# Select the samples with average green mean between the 45 and 80 percentile | |
raw.means <- subset(vvm.set$wide.var.df, | |
green.avg.mean > qvals[1] & green.avg.mean < qvals[2], | |
c(red.mean, green.r.mean, green.b.mean, blue.mean)) | |
if (nrow(raw.means) == 0) stop("No rows selected for white balance!") | |
# Compute the average RGB raw values in the selected samples | |
neutral.raw <- with(raw.means, | |
c(mean(red.mean), mean(c(green.r.mean, green.b.mean)), mean(blue.mean))) | |
# Create a colmap object and calibrate it with this neutral reference value | |
cm.set <- colmap$new(cam.coldata) | |
if (target.space == 'raw') { | |
no.conv.mtx <- diag(1,3,3) | |
raw.to.rgb.mtx <- cm.set$set.conv.matrix.from.raw(neutral.raw, no.conv.mtx) | |
} else { | |
# Get and print the conversion matrix from raw to RGB | |
raw.to.rgb.mtx <- cm.set$get.conv.matrix.from.raw(neutral.raw, target.space) | |
} | |
print(neutral.raw) | |
print(raw.to.rgb.mtx) | |
# Digest the set as rgb, white-balancing each image with the colmap object | |
vvm.set.rgb <- vvm$new(has.RGGB.pattern = TRUE) | |
# debug( vvm.set.rgb$digest.as.rgb) | |
vvm.set.rgb$digest.as.rgb( | |
file.name.from = pict.set, | |
file.path = 'H:/FUN/FOTOS/Noise Study/ipadWhite/ISO100/Selection/crops', | |
is.neutral = TRUE, | |
map.to.rgb = cm.set, | |
use.camera.tc = use.camera.tc, | |
target.tc = target.tc , | |
rgb.scale = dest.scale | |
) | |
# Append the result of this set to the whole collection | |
vvm.rgb.all$append.from(vvm.set.rgb) | |
} | |
# The result is the whole set of the good samples digested as RGB | |
vvm.rgb.all; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment