Skip to content

Instantly share code, notes, and snippets.

@jsreeram
Created August 6, 2014 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsreeram/39fba324be459fab0686 to your computer and use it in GitHub Desktop.
Save jsreeram/39fba324be459fab0686 to your computer and use it in GitHub Desktop.
2D Convolve
function ParallelInvoke(iterationSpace, obj, fn) {
/*....*/
}
// 2D convolve. input, filter & output are 2D (nested) arrays.
function Test(input, filter, output) {
let filterHalfWidth = (filter.length/2)-1
let inputHeight = input.length;
let inputWidth = input[0].length;
Invoke([inputWidth, inputHeight], output,
function(m, n) {
let sum = 0;
for(let i = -1*filterHalfWidth; i < filterHalfWidth; i++) {
for(let j = -1*filterHalfWidth; j < filterHalfWidth; j++) {
let x = m+i, y = n+j;
x = (x < 0 || x > inputWidth) ? 0:x;
y = (y < 0 || y > inputHeight) ? 0:y;
sum += input[x][y] * filter[x+filterHalfWidth][y+filterHalfWidth];
}
}
output[m][n] = sum;
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment