Added noise reduction module (#1105)

* Added Noise Removal Module

* Remove ChangePixel Function
This commit is contained in:
aashna27
2019-06-13 22:39:13 +05:30
committed by Jeffrey Warren
parent cfdb7e2606
commit 9eac21897a
6 changed files with 141 additions and 0 deletions

View File

@@ -31,6 +31,7 @@ module.exports = {
'invert': require('image-sequencer-invert'),
'ndvi': require('./modules/Ndvi'),
'ndvi-colormap': require('./modules/NdviColormap'),
'noise-reduction': require('./modules/NoiseReduction'),
'paint-bucket': require('./modules/PaintBucket'),
'overlay': require('./modules/Overlay'),
'replace-color': require('./modules/ReplaceColor'),

View File

@@ -0,0 +1,38 @@
module.exports = function NoiseReduction(options, UI){
var defaults = require('./../../util/getDefaults.js')(require('./info.json'));
var output;
function draw(input,callback,progressObj){
progressObj.stop(true);
progressObj.overrideFlag = true;
var step = this;
options.method = options.method || defaults.method;
function extraManipulation(pixels) {
pixels = require('./NoiseReduction.js')(pixels, options.method);
return pixels;
}
function output(image, datauri, mimetype){
// This output is accessible by Image Sequencer
step.output = { src: datauri, format: mimetype };
}
return require('../_nomodule/PixelManipulation.js')(input, {
output: output,
extraManipulation: extraManipulation,
format: input.format,
image: options.image,
callback: callback
});
}
return {
options: options,
draw: draw,
output: output,
UI: UI
};
};

View File

@@ -0,0 +1,81 @@
module.exports = function Noise(pixels, method) {
let neighbourX = [-1, -1, -1, 0, 0, 0, 1, 1, 1];
let neighbourY = [-1, 0, 1, -1, 0, 1, -1, 0, 1];
if(method == 'Median Filtering'){
for(let y = 0; y < pixels.shape[1]; y++){
for(let x = 0; x < pixels.shape[0]; x++){
let i = 0, k = 0, windowr = [],windowg = [], windowb = [];
while( k <= 8){
let newX = x + neighbourX[k], newY = y + neighbourY[k];
if( newX >= 0 && newX < pixels.shape[0])
{
if( newY >= 0 && newY < pixels.shape[1]){
windowr[i] = pixels.get((newX),(newY),0);
windowg[i] = pixels.get((newX),(newY),1);
windowb[i] = pixels.get((newX),(newY),2);
i++;
}
}
k++;
}
windowr.sort();
windowg.sort();
windowb.sort();
if(i%2 == 0)
{
let value = windowr[i/2] + windowr[(i/2)-1];
pixels.set(x,y,0,value);
value = windowg[i/2] + windowg[(i/2)-1];
pixels.set(x,y,1,value);
value = windowb[i/2] + windowb[(i/2)-1];
pixels.set(x,y,2,value);
}
else {
pixels.set(x, y, 0, windowr[Math.floor(i/2)]);
pixels.set(x, y, 1, windowg[Math.floor(i/2)]);
pixels.set(x, y, 2, windowb[Math.floor(i/2)]);
}
}
}
}
else if(method == 'Mean Filtering'){
for(let y = 0; y < pixels.shape[1]; y++){
for(let x = 0; x < pixels.shape[0]; x++){
let i = 0, k = 0, sumR=0, sumG = 0, sumB =0;
while( k <= 8){
let newX = x + neighbourX[k], newY = y + neighbourY[k];
if( newX >= 0 && newX < pixels.shape[0])
{
if( newY >= 0 && newY < pixels.shape[1]){
sumR += pixels.get(newX,newY,0);
sumG += pixels.get(newX,newY,1);
sumB += pixels.get(newX,newY,2);
i++;
}
}
k++;
}
pixels.set(x, y, 0, sumR/i);
pixels.set(x, y, 1, sumG/i);
pixels.set(x, y, 2, sumB/i);
}
}
}
return pixels;
};

View File

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

View File

@@ -0,0 +1,13 @@
{
"name": "Noise Reduction",
"description": "Reduces noise from Image",
"inputs": {
"method": {
"type": "select",
"desc": "Select the noise filtering method",
"default": "Median Filtering",
"values": ["Mean Filtering","Median Filtering"]
}
},
"docs-link":""
}

View File

@@ -0,0 +1,4 @@
const testModule = require('../templates/module-test'),
benchmark = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAklEQVR4AewaftIAAAApSURBVKXBAQEAAAiDMKR/5xuC7QYjkEgiiSSSSCKJJJJIIokkkkgiiR5YbQIegx78CAAAAABJRU5ErkJggg==';
testModule('noise-reduction', {method: 'Median Filtering'}, benchmark);