Add: white balance module (#1011)

* WIP

* added white balance and renamed temperature module

* import defaults

* white balance module test
This commit is contained in:
Vibhor Gupta
2019-04-15 17:51:39 +05:30
committed by Jeffrey Warren
parent c3e8c3fb74
commit e22eacf666
7 changed files with 131 additions and 3 deletions

View File

@@ -7,6 +7,7 @@ module.exports = {
'blend': require('./modules/Blend'),
'blur': require('./modules/Blur'),
'brightness': require('./modules/Brightness'),
'canvas-resize': require('./modules/CanvasResize'),
'channel': require('./modules/Channel'),
'colorbar': require('./modules/Colorbar'),
'color-temperature': require('./modules/ColorTemperature'),
@@ -39,5 +40,5 @@ module.exports = {
'text-overlay': require('./modules/TextOverlay'),
'threshold': require('./modules/Threshold'),
'tint': require('./modules/Tint'),
'canvas-resize': require('./modules/CanvasResize')
'white-balance': require('./modules/WhiteBalance')
}

View File

@@ -78,4 +78,4 @@ module.exports = function ColorTemperature(options, UI) {
UI: UI
}
}
}

View File

@@ -9,4 +9,4 @@
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#color-temperature"
}
}

View File

@@ -0,0 +1,58 @@
module.exports = function Balance(options, UI) {
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
options.red = options.red || defaults.red
options.green = options.green || defaults.green
options.blue = options.blue || defaults.blue
var output;
function draw(input, callback, progressObj) {
progressObj.stop(true);
progressObj.overrideFlag = true;
var step = this;
function extraManipulation(pixels) {
var i = 0
var red_factor = 255/options.red
var green_factor = 255/options.green
var blue_factor = 255/options.blue
while (i < pixels.data.length) {
pixels.data[i] = Math.min(255, pixels.data[i]*red_factor)
pixels.data[i+1] = Math.min(255, pixels.data[i+1]*green_factor)
pixels.data[i+2] = Math.min(255, pixels.data[i+2]*blue_factor)
i+=4
}
return pixels
}
function output(image, datauri, mimetype) {
step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
inBrowser: options.inBrowser,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
}
}

View File

@@ -0,0 +1,4 @@
module.exports = [
require('./Module'),
require('./info.json')
]

View File

@@ -0,0 +1,22 @@
{
"name": "White Balance",
"description": "Render neutral colours correctly based on the whitest pixel in the image.",
"inputs": {
"red": {
"type": "integer",
"desc": "Red component of the whitest pixel ",
"default": 255
},
"green": {
"type": "integer",
"desc": "Green component of the whitest pixel ",
"default": 255
},
"blue": {
"type": "integer",
"desc": "Blue component of the whitest pixel ",
"default": 255
}
},
"docs-link":"https://github.com/publiclab/image-sequencer/blob/main/docs/MODULES.md#white-balance"
}

View File

@@ -0,0 +1,43 @@
const test = require('tape')
const base64Img = require('base64-img')
const looksSame = require('looks-same')
require('../../../src/ImageSequencer.js');
var sequencer = ImageSequencer({ui: false})
var options = {red: 240, green: 240, blue: 240}
var target = 'test_outputs'
var image = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAABlBMVEX+AAD///+KQee0AAAAAWJLR0QB/wIt3gAAAAd0SU1FB+EGHRIVAvrm6EMAAAAMSURBVAjXY2AgDQAAADAAAceqhY4AAAAldEVYdGRhdGU6Y3JlYXRlADIwMTctMDYtMjlUMTg6MjE6MDIrMDI6MDDGD83DAAAAJXRFWHRkYXRlOm1vZGlmeQAyMDE3LTA2LTI5VDE4OjIxOjAyKzAyOjAwt1J1fwAAAABJRU5ErkJggg=='
var benchmark = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAApSURBVKXBAQEAAAiDMKR/5xuC7QYjkEgiiSSSSCKJJJJIIokkkkgiiR5YbQIegx78CAAAAABJRU5ErkJggg=='
// Test for loading module
test('Load white balance module', function(t){
sequencer.loadImages(image)
sequencer.addSteps('white-balance', options)
t.equal(sequencer.steps[1].options.name, 'white-balance', 'White Balance module loads correctly')
t.end()
})
// Test for checking options
test('Options are correct', function(t){
t.equal(sequencer.steps[1].options.red, 240, 'Red component is correct')
t.equal(sequencer.steps[1].options.green, 240, 'Green component is correct')
t.equal(sequencer.steps[1].options.blue, 240, 'Blue component is correct')
t.end()
})
// Test for correct output
test('White Balance module works correctly', function(t){
sequencer.run({ mode: 'test' }, function(out) {
var result = sequencer.steps[1].output.src
base64Img.imgSync(result, target, 'result')
base64Img.imgSync(benchmark, target, 'benchmark')
result = './test_outputs/result.png'
benchmark = './test_outputs/benchmark.png'
looksSame(result, benchmark, function(err, res) {
if (err) console.log(err)
t.equal(res.equal, true)
t.end()
})
})
})