Created
August 6, 2014 20:52
-
-
Save jsreeram/39fba324be459fab0686 to your computer and use it in GitHub Desktop.
2D Convolve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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