Tweaked AutoCalib Code. This is fun!
attempt_autocalibrate = function(min_required_intensity) { | |
//The following two are copied from end; before calling attempt_autocalib | |
flotoptions.grid.markings = [] | |
$W.plot = $.plot($("#graph"),$W.data,flotoptions); | |
var max_limit = 5 | |
//min_required_intensity = 20 | |
var max_green = -1000 // We need to find the maximum value of G first | |
var max_green_index = 0 // We need to find the location where G's value is maximum | |
var offset = 50 // The offset region where we wont search for the max R and B values | |
var blue_offset = 30 | |
$.each($W.spectrum.lines, function(index, line){ | |
if(line.wavelength == null){ | |
line.wavelength = index | |
scaled = false | |
} | |
if ((line.g > max_green) && (line.average > min_required_intensity)) { | |
max_green = line.g | |
max_green_index = index | |
} | |
}); | |
var max_red = -1000 | |
var max_blue = -1000 | |
var max_blue_index = 0 | |
var max_red_index = max_green_index + offset | |
$.each($W.spectrum.lines, function(index, line){ | |
if (index > max_green_index + offset) { | |
if((line.r > max_red) && (line.average > min_required_intensity)) { | |
max_red = line.r | |
max_red_index = index | |
} | |
} | |
}); | |
//Let the guess work begin. | |
estimated_blue_peak = max_green_index - 1.707 * (max_red_index - max_green_index) | |
$.each($W.spectrum.lines, function(index, line){ | |
if(index < estimated_blue_peak + blue_offset && index > estimated_blue_peak - blue_offset) { | |
if ((line.b > max_blue) && (line.average > min_required_intensity)) { | |
console.log("entered") | |
max_blue = line.b | |
max_blue_index = index | |
} | |
} | |
}); | |
console.log("Green peak:" + max_green_index) | |
console.log("Blue peak:" + max_blue_index) | |
console.log("Red peak:" + max_red_index) | |
gb_diff = max_green_index - max_blue_index | |
rg_diff = max_red_index - max_green_index | |
rb_diff = max_red_index - max_blue_index | |
console.log("GB diff: " + gb_diff) | |
console.log("RG Diff: " + rg_diff) | |
console.log("RB Diff: " + rb_diff) | |
diff_rat = (gb_diff/111) - (rg_diff/65) | |
gbrg = gb_diff/rg_diff | |
diff = gbrg - 1.707 | |
console.log("GB/RG ratio:" + gbrg) | |
console.log("Expected ratio: 1.707") | |
console.log("Diff in these ratios:" + diff) | |
console.log("Diff in GB/111 and RG/65:" + diff_rat) | |
percentage = diff*100/1.707 | |
console.log("percentage error in GB/RG ratio: " + percentage + " %") | |
console.log("Allowed percentage is: " + max_limit + " %") | |
if (percentage < max_limit && percentage > -1*max_limit){ | |
console.log("Expected to be a CFL?: " + true) | |
} | |
else console.log("Expected to be a CFL?: " + false) | |
// Give out the expected wavelengths | |
// Considering only Green and Blue points | |
step_size = (546.074 - 435.833)*1.00/(gb_diff) | |
//start_wavelength = 545 - step_size*max_green_index | |
start_wavelength = 435.833 - step_size*max_blue_index | |
wavelength_b = start_wavelength + step_size*max_blue_index | |
wavelength_r = start_wavelength + step_size*max_red_index | |
wavelength_g = start_wavelength + step_size*max_green_index | |
// Lets mark these on the plot | |
$W.markers = [] | |
// Adding blue | |
nm = wavelength_b | |
label = "Blue" | |
o = $W.plot.pointOffset({ x: nm, y: 90}) | |
if (!flotoptions.grid.markings) flotoptions.grid.markings = [] | |
flotoptions.grid.markings.push({ color: '#0000ff', lineWidth: 1, xaxis: { from: nm, to: nm } }) | |
$W.plot = $.plot($("#graph"),$W.data,flotoptions); | |
$W.markers.push([label,nm,o.left]) | |
// Adding red | |
nm = wavelength_r | |
label = "Red" | |
o = $W.plot.pointOffset({ x: nm, y: 90}) | |
if (!flotoptions.grid.markings) flotoptions.grid.markings = [] | |
flotoptions.grid.markings.push({ color: '#ff0000', lineWidth: 1, xaxis: { from: nm, to: nm } }) | |
$W.plot = $.plot($("#graph"),$W.data,flotoptions); | |
$W.markers.push([label,nm,o.left]) | |
// Adding green | |
nm = wavelength_g | |
label = "Green" | |
o = $W.plot.pointOffset({ x: nm, y: 90}) | |
if (!flotoptions.grid.markings) flotoptions.grid.markings = [] | |
flotoptions.grid.markings.push({ color: '#00ff00', lineWidth: 1, xaxis: { from: nm, to: nm } }) | |
$W.plot = $.plot($("#graph"),$W.data,flotoptions); | |
$W.markers.push([label,nm,o.left]) | |
//$W.show_rgb() | |
} | |
attempt_autocalibrate(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment