Clipping detection adapted from older Spectral Workbench code
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
setup: function() { | |
// code to run on startup | |
// need to highlight the clipping; this just checks if it's happening | |
// i = pixel position | |
overexposure_recurse = function(data,i,count,color,threshold) { | |
if (count > threshold) { | |
return [true,i] | |
} else { | |
if (data[i][color] >= 255) { | |
return overexposure_recurse(data,i+2,count+2,color,threshold) // checks every 2 px | |
} else return [false,i] | |
} | |
} | |
// start a search every 10 pixels for a plateau of <threshold> width | |
detect_clipping = function(data,threshold) { | |
var overexposed = {r: false, g: false, b: false} | |
var colors = ["r","g","b"] | |
// first, check if there's already an "Overexposed" dataset: | |
var overexposure_index | |
$.each($W.data,function(index,set) { | |
if (set['label'] == "Overexposed") { | |
overexposure_index = index | |
} else { | |
// if not, add a dataset for overexposure: | |
overexposure_index = $W.data.length | |
$W.data.push({data:[],label:"Overexposed"}) | |
} | |
}) | |
flotoptions.colors[overexposure_index] == "yellow" | |
// check each channel for plateaus at 100%: | |
$.each(colors,function(index,color) { | |
var i = 0; | |
while (i < data.length) { | |
var line = data[i] | |
var scan = overexposure_recurse(data,i,0,color,threshold) | |
// here's a good place to draw clipped areas | |
// in capture, we just added another row of data with points only on spots where there was overexposure | |
// but if we scan every 10px, we'll miss some. | |
if (data[i][color] >= 255) $W.data[overexposure_index].data.push([data[i]['wavelength'],100]) | |
if (scan[0]) { | |
overexposed[color] = true | |
i = data.length | |
} else i = scan[1]+10 // starts looking for new plateaus 10px ahead | |
} | |
}) | |
return overexposed | |
} | |
detect_clipping($W.spectrum['lines'],5) | |
$.plot($("#graph"),$W.data,flotoptions) | |
}, | |
draw: function() { | |
// code to run every frame | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment