Skip to content

Instantly share code, notes, and snippets.

@merryhime
Created July 22, 2016 09:24
Show Gist options
  • Save merryhime/7e41700a6b79df22b8b3cb66dde7d24e to your computer and use it in GitHub Desktop.
Save merryhime/7e41700a6b79df22b8b3cb66dde7d24e to your computer and use it in GitHub Desktop.
(1 0 ¯1 1 0 ¯1 1 0 ¯1)⌽"(1 0 ¯1)⊖"⊂M
Here we have a matrix M
Let's say it looks like this:
> M
0 0 0 0 0
0 0 0 0 0
0 1 1 1 0
0 0 0 0 0
0 0 0 0 0
First we wrap it up so it appears like a scalar
> ⊂M
+---------+
|0 0 0 0 0|
|0 0 0 0 0|
|0 1 1 1 0|
|0 0 0 0 0|
|0 0 0 0 0|
+---------+
then we do a vertical-rotate-each
> (1 0 ¯1)⊖"⊂M
+---------+---------+---------+
|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|
|0 1 1 1 0|0 0 0 0 0|0 0 0 0 0|
|0 0 0 0 0|0 1 1 1 0|0 0 0 0 0|
|0 0 0 0 0|0 0 0 0 0|0 1 1 1 0|
|0 0 0 0 0|0 0 0 0 0|0 0 0 0 0|
+---------+---------+---------+
Then we do a horizonal rotate each, so we get an array of 9 matrices.
We can then multiply each member of our convolution matrix to each of these matrices
C×"(1 0 ¯1 1 0 ¯1 1 0 ¯1)⌽"(1 0 ¯1)⊖"⊂M
and then summate
+/C×"(1 0 ¯1 1 0 ¯1 1 0 ¯1)⌽"(1 0 ¯1)⊖"⊂M
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment