Files
image-sequencer/src/modules/NoiseReduction/NoiseReduction.js
Harsh Khandeparkar 257113a948 Shorten UI code with new $step method (#710)
* update dist

Signed-off-by: tech4GT <varun.gupta1798@gmail.com>

dist update

Revert "dist update"

This reverts commit 9ee2a987e8f978961656ae8f71f6e6702bbbd30d.

* Merge remote-tracking branch 'upstream/main' into main

* add dist

* add new func

* update itermediate

* changes

* fix gitignore

* use scopeQuery

* add mapHtmlTypes test

* scopeQuery tests added

* try something

* change

* fix stepui test

* Remove double quotes

* update new code

* refactor to spec
2019-06-21 15:11:10 -04:00

81 lines
2.2 KiB
JavaScript

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;
};